![](/img/trans.png)
[英]CMake add_subdirectory given source which is not an existing directory
[英]CMake Error add_subdirectory given source "lib/sfml" which is not an existing directory
这是我第一次使用 CMake,所以请耐心等待。 我的知识非常有限。 我正在按照一个教程来重新创建我在下面链接的太空入侵者。
我使用 git-bash 设置我的存储库,现在我使用 CMake (cmake-gui) 为 Windows 设置我的构建。
回购教程链接: https://dooglz.github.io/set09121/repo_setup.html
构建教程链接: https://dooglz.github.io/set09121/build_setup.html
这是我关注的 CMake 指南: https://github.com/edinburgh-napier/aux_guides/blob/master/cmake_guide.Z437175BA4191210EE004E1D93Z49
据我了解,对于“源代码在哪里”,我使用 CMakeLists.txt 和 main.cpp 创建了一个名为“Space Invader”的文件夹。 对于“在哪里构建二进制文件”,我创建了一个名为“build.
当我按下配置时,我收到此错误消息。
Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
CMake Error at CMakeLists.txt:15 (add_subdirectory):
add_subdirectory given source "lib/sfml" which is not an existing
directory.
这是给定的CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
# Require modern C++
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(Games_Engineering)
#### Setup Directories ####
#Main output directory
SET(OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/")
# Ouput all DLLs from all libs into main build folder
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY})
#### Add External Dependencies ####
add_subdirectory("lib/sfml")
set(SFML_INCS "lib/sfml/include")
link_directories("${CMAKE_BINARY_DIR}/lib/sfml/lib")
#### Practical 1 ####
file(GLOB_RECURSE SOURCES practical_1/*.cpp practical_1/*.h)
add_executable(PRACTICAL_1 ${SOURCES})
target_include_directories(PRACTICAL_1 PRIVATE ${SFML_INCS})
target_link_libraries(PRACTICAL_1 sfml-graphics)
主文件
int main(){
sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
while (window.isOpen()){
sf::Event event;
while (window.pollEvent(event)){
if (event.type == sf::Event::Closed){
window.close();
}
}
window.clear();
window.draw(shape);
window.display();
}
return 0;
}
我还尝试使用 git-bash 创建 CMake。 本教程说使用以下命令:
mkdir projectname_build
cd projectname_build
cmake -G "Visual Studio 14 2015 Win64" ../projectname/
或者就我而言,最后一行(我猜这是正确的)
cmake -G "Visual Studio 16 2019" ../projectname/
但是当我尝试使用 git-bash 时,我得到了这个错误:
bash: cmake: command not found
我可以用 git-bash 或 CMake 为 Windows 制作 CMake,所以我对这些路线的任何解决方案持开放态度。 我也不想将代码更改为在尝试完成此项目时将来会遇到问题的地方,这就是为什么我链接教程以展示我已经完成的工作。
我一直在寻找很长时间才能找到解决方案,但我很迷茫。 请查看网站链接,请耐心等待我。 如果其中任何内容令人困惑或措辞错误,我深表歉意。 我只是一个试图扩展我的技能的学生。
它没有提到递归
没错,它只在“ 从头开始”中提到,包括:
通过运行获取/更新 SFML:
git submodule update --init --recursive
Even without recursive, the command git submodule add https://github.com/SFML/SFML.git lib/sfml
followed by git submodule update --init
should be enough for your lib/sfml
folder to be populated.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.