配置 CLion、Cmake 和 SFML 的问题
Issues Configuring CLion, Cmake, and SFML
我目前正在尝试配置我的 Cmake 文件以包含 SFML 库。
我的CMakeLists.txt。如果这很重要,我正在使用 OS X Yosemite。
cmake_minimum_required(VERSION 2.8.4)
project(SFMLTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=lib++")
set(SOURCE_FILES main.cpp)
add_executable(SFMLTest ${SOURCE_FILES})
#Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2.2 REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${main.cpp} ${SFML_Libraries})
endif()
我目前收到的错误是
Error:By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has asked
CMake to find a package configuration file provided by "SFML", but CMake did notfind one.
Could not find a package configuration file provided by "SFML" (requested version 2.2)
with any of the following names:
SFMLConfig.cmake sfml-config.cmake
Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or
set "SFML_DIR"to a directory containing one of the above files.
If "SFML" provides a separate development package or SDK, be sure it has been installed.
我的 FindSFML.cmake 位于
/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules
你的问题是查找模块的完整路径是
/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules/FindSFML.cmake
但是您要将 ${CMAKE_SOURCE_DIR}/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules
添加到您的 CMAKE_MODULE_PATH
。 ${CMAKE_SOURCE_DIR}
是包含顶级 CMakeLists.txt
文件的目录的绝对路径。如果你知道你想要包含的模块文件的绝对路径,你绝对不应该在它前面加上源代码树路径。只需将行更改为:
set(CMAKE_MODULE_PATH "/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules" ${CMAKE_MODULE_PATH})
另请注意,由于您在 find_package()
的参数中指定了 REQUIRED
,如果找不到包,CMake 将终止并报错。因此 if(SFML_FOUND)
毫无意义。
这个解决方案是完美的:https://oxymeos.shost.ca/article.php?about=work_with_the_SFML_in_CLion。我推荐它!它对我有用
您在项目的根目录下创建了一个名为 "cmake_modules" 的文件夹,并将 "FindSFML.cmake" 文件(在 Windows 和 Mac OS X: "[Your_SFML Location]/cmake/Modules/FindSFML.cmake", 在 Linux: "[Your_SFML_location]/share/SFML/cmake/Modules/FindSFML.cmake ".
CMake 配置文件(CMakeLists.txt)然后以这种形式呈现:
cmake_minimum_required(VERSION 3.7)
project([your_project])
# Define the source and the executable
set(EXECUTABLE_NAME "[name_executable]")
add_executable(${EXECUTABLE_NAME} [project_files])
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()
我目前正在尝试配置我的 Cmake 文件以包含 SFML 库。 我的CMakeLists.txt。如果这很重要,我正在使用 OS X Yosemite。
cmake_minimum_required(VERSION 2.8.4)
project(SFMLTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=lib++")
set(SOURCE_FILES main.cpp)
add_executable(SFMLTest ${SOURCE_FILES})
#Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules" ${CMAKE_MODULE_PATH})
find_package(SFML 2.2 REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${main.cpp} ${SFML_Libraries})
endif()
我目前收到的错误是
Error:By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has asked
CMake to find a package configuration file provided by "SFML", but CMake did notfind one.
Could not find a package configuration file provided by "SFML" (requested version 2.2)
with any of the following names:
SFMLConfig.cmake sfml-config.cmake
Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or
set "SFML_DIR"to a directory containing one of the above files.
If "SFML" provides a separate development package or SDK, be sure it has been installed.
我的 FindSFML.cmake 位于
/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules
你的问题是查找模块的完整路径是
/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules/FindSFML.cmake
但是您要将 ${CMAKE_SOURCE_DIR}/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules
添加到您的 CMAKE_MODULE_PATH
。 ${CMAKE_SOURCE_DIR}
是包含顶级 CMakeLists.txt
文件的目录的绝对路径。如果你知道你想要包含的模块文件的绝对路径,你绝对不应该在它前面加上源代码树路径。只需将行更改为:
set(CMAKE_MODULE_PATH "/Users/Home/SFML-2.2-osx-clang-universal/cmake/Modules" ${CMAKE_MODULE_PATH})
另请注意,由于您在 find_package()
的参数中指定了 REQUIRED
,如果找不到包,CMake 将终止并报错。因此 if(SFML_FOUND)
毫无意义。
这个解决方案是完美的:https://oxymeos.shost.ca/article.php?about=work_with_the_SFML_in_CLion。我推荐它!它对我有用
您在项目的根目录下创建了一个名为 "cmake_modules" 的文件夹,并将 "FindSFML.cmake" 文件(在 Windows 和 Mac OS X: "[Your_SFML Location]/cmake/Modules/FindSFML.cmake", 在 Linux: "[Your_SFML_location]/share/SFML/cmake/Modules/FindSFML.cmake ".
CMake 配置文件(CMakeLists.txt)然后以这种形式呈现:
cmake_minimum_required(VERSION 3.7)
project([your_project])
# Define the source and the executable
set(EXECUTABLE_NAME "[name_executable]")
add_executable(${EXECUTABLE_NAME} [project_files])
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
find_package(SFML 2 REQUIRED system window graphics network audio)
if(SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${SFML_LIBRARIES})
endif()