Cmake: hierarchical project setup

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 assembly, I like:

 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 document is pretty hard to read, and all I need is an example (like an existing project) how to install this ...

Many thanks!

+6
source share
1 answer

You want the following:

projected / CMakeLists.txt:

 cmake_minimum_required(VERSION 2.8 FATAL_ERROR) project(MyTest) add_subdirectory(subdir0) add_subdirectory(subdir1) 


projected / subdir0 / CMakeLists.txt:

 add_executable(app0 app0.cpp) add_executable(app1 app1.cpp) 


projected / subdir1 / CMakeLists.txt:

 add_executable(app2 app2.cpp) 


Then at the command prompt, simply do:

 mkdir <root of proj>/build cd <root of proj>/build cmake .. 
+5
source

Source: https://habr.com/ru/post/928191/


All Articles