使用CMake使用SFML库构建项目

时间:2017-06-17 03:53:28

标签: cmake sfml

this question类似,我尝试使用CMake使用SFML构建项目。

我的CMakeLists.txt文件是:

cmake_minimum_required(VERSION 2.6)
project(pong)

# Specify C++11 flag for g++
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2")
endif()

# Add directory containing FindSFML.cmake to module path
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH})

# Add sources
file(GLOB SOURCES
    "${PROJECT_SOURCE_DIR}/*.cpp"
)

# Find SFML
set(SFML_ROOT "C:/Users/usr/Downloads/_ Downloads (new)_/SFML-2.4.2-linux-gcc-64-bit/SFML-2.4.2")
find_package( SFML COMPONENTS audio graphics window system REQUIRED )

if(SFML_FOUND)
        include_directories(${SFML_INCLUDE_DIR})
    target_link_libraries(pong ${SFML_LIBRARIES})
else()
        #set(SFML_ROOT "" CACHE PATH "SFML top-level directory")
        message("\n-> SFML directory not found. Set SFML_ROOT to SFML's top-level path (containing \"include\" and \"lib\" 

directories).")
        message("-> Make sure the SFML libraries with the same configuration (Release/Debug, Static/Dynamic) exist.\n")
endif()

add_executable(pong ${SOURCES})

当我尝试在Windows上使用MinGW-w64 + MSYS2构建它时,出现以下错误:

CMake Error at cmake/Modules/FindSFML.cmake:307 (message):
  Could NOT find SFML (missing: SFML_AUDIO_LIBRARY SFML_GRAPHICS_LIBRARY
  SFML_WINDOW_LIBRARY SFML_SYSTEM_LIBRARY)
Call Stack (most recent call first):
  CMakeLists.txt:19 (find_package)

我不知道为什么找不到图书馆。

请帮帮我。

0 个答案:

没有答案