Edit: my question targets the early configure stage where CMake input files are still being parsed and thus have to be present before include()
is being called. So the answer found here: Force CMake to generate configure_file target every build does not solve my problem since it generates files after include()
statements have been interpreted.
I have a CMakeLists.txt
that includes a file which is generated in the configure stage:
execute_process(COMMAND "my-generator -o generated.cmake")
include(generated.cmake)
Apart from the fact that this approach doesn't feel right (not to say elegant) I now need to re-generate that file before every build (my-generator
produces output that incorporates the current time).
My assumption is that I can't use add_custom_command()
or add_custom_target()
because the file would be generated at compile time but needed in the configure-step.
This very old post suggests to touch
the input file so I did this:
execute_process(
COMMAND "my-generator -o generated.cmake"
COMMAND cmake -E touch "${CMAKE_CURRENT_LIST_FILE}")
.. which does not produce errors but calling make
multiple times won't run the configure step more than once.
What do I do wrong? Is there a better approach?