Catskul
Catskul

Reputation: 19460

Is it possible to create a cmake script that generates a build that handles unknown files generated at build time?

I have a system that produces generated code from a spec document which can change at any time. As such, the list of files being generated cannot be static, and must be able to be handled dynamically at build time.

From what I can tell the typical CMakeLists.txt is set up to define a rule for each file at cmake generation time.

Is there a way to get CMake to write generic rules so that the targets can be set at build time?

If not, what are the possible work-arounds?

Upvotes: 1

Views: 575

Answers (1)

arrowd
arrowd

Reputation: 34421

First, you can put your code generation process into CMakeLists.txt in a form of a target (add_custom_command), and then make your target depends on this command. This was code generation steps will be run every time you issue make.

Alternatively, here is a hack:

add_custom_target(cmake_regen ALL
    COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/CMakeFiles/Makefile.cmake)

And a less hackish variant, which should preserve already built targets:

add_custom_target(cmake_regen ALL
    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target rebuild_cache)

Adding such code into CMakeLists.txt forces CMake to regenerate makefiles on each run without running full configuration process.

Upvotes: 1

Related Questions