Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake: hierarchical project setup

Tags:

cmake

I have a project with the following structure:

proj:
-CMakeLists.txt    
-subdir0   
  -CMakeLists.txt    
  -app0.cpp
  -app1.cpp
-subdir1
  -CMakeLists.txt    
  -app2.cpp

And after build, I like to have:

proj:    
-CMakeLists.txt    
-subdir0   
  -CMakeLists.txt    
  -app0.cpp
  -app1.cpp
-subdir1
  -CMakeLists.txt    
  -app2.cpp
-build
  -subdir0   
    -app0.exec
    -app1.exec
  -subdir1
    -app2.exec

The CMake doc is quite difficult to read and all I need here is an example (e.g. an existing project) how to set this up...

thanks a lot!

like image 976
guinny Avatar asked Oct 20 '12 17:10

guinny


1 Answers

You want the following:

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)


Then in a command prompt simply do:

mkdir <root of proj>/build
cd <root of proj>/build
cmake ..
like image 82
Fraser Avatar answered Oct 05 '22 10:10

Fraser