Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cmake:分层项目设置_Cmake - Fatal编程技术网

cmake:分层项目设置

cmake:分层项目设置,cmake,Cmake,我有一个具有以下结构的项目: 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

我有一个具有以下结构的项目:

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)
add_executable(app0 app0.cpp)
add_executable(app1 app1.cpp)
add_executable(app2 app2.cpp)

proj/subdir0/CMakeLists.txt:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(MyTest)
add_subdirectory(subdir0)
add_subdirectory(subdir1)
add_executable(app0 app0.cpp)
add_executable(app1 app1.cpp)
add_executable(app2 app2.cpp)

proj/subdir1/CMakeLists.txt:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(MyTest)
add_subdirectory(subdir0)
add_subdirectory(subdir1)
add_executable(app0 app0.cpp)
add_executable(app1 app1.cpp)
add_executable(app2 app2.cpp)

然后在命令提示下,只需执行以下操作:

mkdir <root of proj>/build
cd <root of proj>/build
cmake ..
mkdir/build
cd/build
克马克。。