[CMake] Custom target

Mark Stijnman mark.stijnman at gmail.com
Thu Jun 6 05:29:45 EDT 2013


On Wednesday 05 June 2013, Ian Liu Rodrigues wrote:
> Dear all,
>
> Is it possible to create a target for all sub-directories with the
> same name? For instance, I want to create a "benchmark" target so that
> every subdir implements a way of bench-marking its own program.
>
> I tried adding a "add_custom_target(benchmark ...)" in the
> CMakeLists.txt of each subdir, but cmake complains about duplicate
> target names.

In your top-level CMakeLists.txt, just do
add_custom_target(benchmark)

Then, in each sub-directory, do:

add_custom_target(${subproject}_benchmark)
add_dependencies(benchmark ${subproject}_benchmark)

Now building "benchmark" will build all the "${subproject}_benchmark"
targets too.

regards Mark


More information about the CMake mailing list