A bit of context first - I'm working on converting a CMake build system to an internal build system. For this I iterate BUILDSYSTEM_TARGETS
and use get_property
to get all the properties I need and everything works fine, except some files are missing from the build. After checking the CMakeLists.txt files from the original build system I realized configure_file
is used in many and quite random places.
I assume CMake is storing configure_file
calls internally. If this is the case, is it possible to access this?
You could redefine configure_file
as a function (or macro) at the beginning of the project's CMakeLists.txt
. That way allows you to run arbitrary code every time the function is invoked in the project.
Inside redefining function you could implement the logic which you need. For call original function in the redefining one, use underscore-prefixed name (_configure_file
):
function(configure_file input output)
# ...
# Do something with the 'output' file. E.g. add it to the global list.
# ...
# After custom processing call original function with all parameters.
_configure_file(${input} ${output} ${ARGN})
endfunction()
Note, that generally redefining CMake functions is discouraged (at least, the underscored version of a function is an undocumented feature). But for debugging purposes it looks reasonable. Moreover, debugging was the primary reason to introduce such underscored functions: https://gitlab.kitware.com/cmake/cmake/-/issues/23482