gpt4 book ai didi

cmake - 配置 CLion、Cmake 和 SFML 的问题

转载 作者:行者123 更新时间:2023-12-05 09:22:11 32 4
gpt4 key购买 nike

我目前正在尝试配置我的 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) 毫无意义。

关于cmake - 配置 CLion、Cmake 和 SFML 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28243397/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com