The code for this recipe is available at https://github.com/dev-cafe/cmake-cookbook/tree/v1.0/chapter-05/recipe-03 and has a C++ example. The recipe is valid with CMake version 3.5 (and higher) and has been tested on GNU/Linux, macOS, and Windows.
Build targets for your projects might depend on the results of commands that can only be executed at build time, after the build system generation has been completed. CMake offers three options to execute custom commands at build time:
- Using add_custom_command to generate output files to be compiled within a target.
- Using add_custom_target to execute commands with no output.
- Using add_custom_command to execute commands with no output, before or after a target has been built.
These three options enforce specific semantics and are not interchangeable. The next three...