我不明白如何使用构建 SFML 项目CMakeLists.txt
file.
如果你有时间的话,请帮帮我。谢谢你!)
Details
我从官方网站下载了 SFML 库(https://www.sfml-dev.org/index.php),将其移至我的项目根目录(参见下面的屏幕截图),使用 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;
}
截图
项目根文件夹截图
SFML文件夹截图
main.cpp-源文件夹