我不明白如何使用CMakeLists.txt文件来构建SFML项目,
请问您有时间帮忙吗?谢谢!
详情: 我从官方网站https://www.sfml-dev.org/index.php下载了SFML库,并将其移到了我的项目根目录下(请参见下面的屏幕截图),编写了使用SFML的C++代码,然后输入了这个cmake命令:
但是在控制台输出中,我得到了这个:
这是使用SFML的主要C++文件(它在项目子文件夹中)。
.../test_proj/subdir_02/main.cpp:
详情: 我从官方网站https://www.sfml-dev.org/index.php下载了SFML库,并将其移到了我的项目根目录下(请参见下面的屏幕截图),编写了使用SFML的C++代码,然后输入了这个cmake命令:
.../test_proj> cmake -G "Ninja" .
但是在控制台输出中,我得到了这个:
CMake Warning at subdir_02/CMakeLists.txt:5 (find_package):
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 not find one.
Could not find a package configuration file provided by "SFML" 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.
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/tim/Documents/c-c++/test_proj
CMakeLists.txt:
add_executable(subdir_02 main.cpp)
set(SFML_STATIC_LIBRARIES TRUE)
find_package(SFML COMPONENTS window graphics system)
target_compile_features(subdir_02 PUBLIC cxx_std_17)
target_compile_definitions(subdir_02 PRIVATE SFML_STATIC)
target_link_libraries(subdir_02 ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
这是使用SFML的主要C++文件(它在项目子文件夹中)。
.../test_proj/subdir_02/main.cpp:
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow app(sf::VideoMode(800, 600, 32), "Hello World - SFML");
return 0;
}
FindSFML.cmake
文件或其他地方写什么 :) - Life Sweetener