Copying and modifying files
A relatively common task when building software is that some files must be copied to a specific location before the build. Most file operations can be done using the file()
command at configuration time. For instance, copying files is done by invoking the following:
file(COPY_FILE old_file new_file)
There are several file operations available, such as file(REMOVE)
and file(REMOVE_RECURSE)
to delete files or directory trees, file(RENAME)
to move files, and file(CHMOD)
to change permissions on systems that support it. The full documentation of the file
command is available here: https://cmake.org/cmake/help/latest/command/file.html.
But what if we want to copy and modify a file at the same time? 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...