Writing custom commands
Using custom targets has one drawback – as soon as you add them to the ALL
target or start depending on them for other targets, they will be built every single time (you may still enable them in an if
block to limit that). Sometimes, this is what you want, but there are cases when custom behavior is necessary to produce files that shouldn't be recreated without reason:
- Generating a source code file that another target depends on
- Translating another language into C++
- Executing a custom action immediately before or after another target was built
There are two signatures for a custom command. The first one is an extended version of add_custom_target()
:
add_custom_command(OUTPUT output1 [output2 ...] COMMAND command1 [ARGS] [args1...] ...