Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group build targets in CMake project

Tags:

cmake

I just included doxygen generation in my project using the add_custom_target() command. Now I did not include ALL as I don't want this build be default.

Now I have the following scenario.

project/subproj1/doc project/subproj2/doc

In each subproject there is a CMakeLists.txt file with: add_custom_target(gen_doc_subproj1 ...) add_custom_target(gen_doc_subproj2 ...)

What I'd like to achieve is that after generating my make files I can type:

make doc and it will build all documentation targets.

Is there some construction in CMake such as: if_not_exist_target_group(doc) create_target_group(doc) endif add_to_target_group(gen_doc_subproj1, doc)

Any pointers would be appriciated.

like image 809
Jan Jaap Avatar asked May 12 '16 14:05

Jan Jaap


People also ask

How do I add a target in CMake?

Use the add_custom_command() command to generate a file with dependencies. By default nothing depends on the custom target. Use the add_dependencies() command to add dependencies to or from other targets.

What is a build target CMake?

Introduction. A CMake-based buildsystem is organized as a set of high-level logical targets. Each target corresponds to an executable or library, or is a custom target containing custom commands.

What does Add_subdirectory do in CMake?

Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.


1 Answers

If i understood you right, it is as simple as

if(NOT TARGET doc)
  add_custom_target(doc)
  add_dependencies(doc gen_doc_subproj1 gen_doc_subproj2 ...)
endif()
like image 88
arrowd Avatar answered Sep 23 '22 00:09

arrowd