11

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

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 文档很难阅读,我需要的只是一个示例(例如现有项目)如何设置它......

多谢!

4

1 回答 1

12

您需要以下内容:

项目/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 ..
于 2012-10-20T18:55:40.457 回答