Implementing build time configure_file functionality
The current configure_file
functionality requires project reconfiguration if the source file changes, which can be very slow.
The current workaround I often do is to implement a small cmake script which calls configure_file
, and then inject that into the build system through add_custom_command
.
Example script:
foreach(I RANGE "${CMAKE_ARGC}")
if (CMAKE_ARGV${I} STREQUAL "--")
math(EXPR START "${I} + 1")
break()
endif()
endforeach()
foreach(I RANGE "${START}" "${CMAKE_ARGC}")
list(APPEND ARGS "${CMAKE_ARGV${I}}")
endforeach()
configure_file(${ARGS})
I suppose adding configure_file
as a builtin command line tool would already be of some help, but I wonder
if we can do even better, properly integrating this into the cmake language, and avoiding manual commands and target creation.