Is there any way to do the equivalent of add_custom_command (run an external script when a certain file changes), but for something that should be run during CMake script execution itself? (That is, for dependency graph generation.)
We have our source code files split up into multiple sub-libraries, and there are configuration files which list which source file goes with which library. (The format of these configuration files are fixed by another tool we use.) Currently, we run a custom external script which parses those configuration files and writes new files, which are then loaded by the CMake build process to give the list of filenames to be passed to add_library(). This means that each time a source file is added/removed, we need to remember to re-run the prebuild command, before re-running CMake, and then re-launching the build command.
I know that CMake can recognize that it needs to re-run itself, so I'm hoping that we can get CMake to 1) recognize that the configuration files are changed 2) rerun the configfile parser 3) load the new file list 4) use the new file list to regenerate the dependency tree 5) finally launch the actual build/compilation process with the new files included. ... and all this from the standard build command, without having to manually run the external configfile parser or manually re-run the CMake command, and without needless execution when the configfile hasn't changed.
In searching, I did find this question, where using configure_file() is suggested, but that doesn't address how to invoke the external configfile parser script.
configure_file()
is the right choice to retrigger the configuration process. Andexecute_process()
is used to run commands during the configuration step. – Fostoria