1

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?

frans
  • 8,868
  • 11
  • 58
  • 132
  • 1
    That's not how you use CMake. I am glad, that it does not work, as it would lead to curious (elegant?) CMake project, nobody would understand. – usr1234567 Oct 17 '17 at 10:42
  • 1
    I admit this is abusing CMake principles. Maybe there is another way to accomplish the need to create variables (e.g. a timestamp) used in CMake commands or variables like `CPACK_PACKAGE_FILE_NAME`. I don't know any. – frans Oct 17 '17 at 12:30

0 Answers0