我有一个具有以下结构的项目:
proj:
-CMakeLists.txt
-subdir0
-CMakeLists.txt
-app0.cpp
-app1.cpp
-subdir1
-CMakeLists.txt
-app2.cpp
构建之后,我希望拥有:
proj:
-CMakeLists.txt
-subdir0
-CMakeLists.txt
-app0.cpp
-app1.cpp
-subdir1
-CMakeLists.txt
-app2.cpp
-build
-subdir0
-app0.exec
-app1.exec
-subdir1
-app2.exec
CMake文档很难阅读,我在这里只需要一个示例(例如现有项目)来设置它...
多谢!
最佳答案
您需要以下内容:
proj/CMakeLists.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(MyTest)
add_subdirectory(subdir0)
add_subdirectory(subdir1)
proj/subdir0/CMakeLists.txt:
add_executable(app0 app0.cpp)
add_executable(app1 app1.cpp)
proj/subdir1/CMakeLists.txt:
add_executable(app2 app2.cpp)
然后在命令提示符下简单地执行以下操作:
mkdir <root of proj>/build
cd <root of proj>/build
cmake ..
关于cmake:分层项目设置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12991180/