Compilation groups with cmake

I have a project in which compilation creates several executables. I use cmake to create a Makefile. Then when I say make , they are all compiled. I know that I can use make target1 to compile the desired target. But I would like to split all my goals into groups and be able to use, say make group_A to compile a subset of the goals. How to achieve this?

The project is written in C ++ and developed for Linux and OSX.

+5
source share
1 answer

Take a look at add_custom_target and add_dependencies in the CMake documentation. You can add a group as a custom goal with the goals you want to create as a dependency for the group.

http://www.cmake.org/cmake/help/v3.2/command/add_custom_target.html http://www.cmake.org/cmake/help/v3.2/command/add_dependencies.html

EDIT (after @ms comment)

You can do

 add_custom_target(<group-name> DEPENDS <target1> <target2> ...) 

Here is a small example.

hello1.cpp

 #include <stdio.h> int main() { printf("Hello World 1\n"); return 0; } 

hello2.cpp

 #include <stdio.h> int main() { printf("Hello World 2\n"); return 0; } 

hello3.cpp

 #include <stdio.h> int main() { printf("Hello World 3\n"); return 0; } 

CMakeLists.txt

 cmake_minimum_required(VERSION 2.6 FATAL_ERROR) project(groups_demo) add_executable(hello1 hello1.cpp) add_executable(hello2 hello2.cpp) add_executable(hello3 hello3.cpp) add_custom_target(hello12 DEPENDS hello1 hello2) add_custom_target(hello23 DEPENDS hello3 hello2) add_custom_target(hello13 DEPENDS hello1 hello3) 

Now you can use make hello12 to build hello1 and hello2

+5
source

All Articles