Copying and modifying files
A relatively common task when building software is that some files must be copied to a specific location or modified before the build. In the Executing custom tasks at configuration time section, we saw an example where the Git revision was retrieved and passed to the compiler as a preprocessor definition. A much nicer way to do this would be to generate a header file containing the necessary information. While just echoing the code snippet and writing it into a file would be possible, it is dangerous as it may lead to platform-specific code. CMake's solution to this is the configure_file
command, which can copy files from one location to another and modify their content while doing so. The signature of configure_file
is as follows:
configure_file(<input> <output> NO_SOURCE_PERMISSIONS | USE_SOURCE_PERMISSIONS | &...