Content #
add_custom_target(Name [ALL] [command1 [args1...]]
[COMMAND command2 [args2...] ...]
[DEPENDS depend depend depend ... ]
[BYPRODUCTS [files...]]
[WORKING_DIRECTORY dir]
[COMMENT comment]
[JOB_POOL job_pool]
[VERBATIM] [USES_TERMINAL]
[COMMAND_EXPAND_LISTS]
[SOURCES src1 [src2...]])
They allow you to specify your own command line that will be executed without checking whether the produced output is up to date, for example: • Calculate the checksums of other binaries. • Run the code-sanitizer and collect the results. • Send a compilation report to the data processing pipeline.
One good use case for custom targets might be the need to remove specific files on every build – for example, to make sure that code-coverage reports don’t contain stale data. All we need to do is define a custom target like so:
add_custom_target(clean_stale_coverage_files
COMMAND find . -name "*.gcda" -type f -delete)
The preceding command will search for all files with a .gcda extension and remove them.
There is one catch though; unlike executable and library targets, custom targets won’t be built until they are added to a dependency graph.