[CMake] Configuration time "custom command"

Israel Israeli embedded.team103 at gmail.com
Tue Apr 9 08:30:49 EDT 2019


Hello,
We are using a large project that comes with it's own build and
configuration system.
We have multiple issues with this external build system and we want to move
the building of this project to cmake (as well as our code that depends on
it).

All the problems are related to the `build` step and we want to replace it
with a simple `add_library` with all sources.
The problem starts due to the fact that the project's configuration process
is complicated and ever-changing, and we do not want to maintain a copy of
it inside cmake.

Instead, we want to call `execute_process` to get cmake variables needed
from the external configuration system and have a simple cmake build steps
on top of it.

The thing is we want proper detection of when to rerun the configure step
and we want something similar to `add-custom_target`'s DEPENDS variable,
only at configure time.
Is this possible by any means? I know of `CMAKE_CONFIGURE_DEPENDS`, but the
fact that it is global is problematic and here's why:
There are multiple cmake variables that come from this configuration system
- from the language standard version to the list of target sources.
Change in what creates one of them should NOT trigger the configuration
system for another variable as this could cause a full rebuild of the
project which is undesirable due to long compilation times.

Basically, what I'm asking is* - Is there a way to describe "custom
commands", with proper dependency management that run at configure time?*

Example (pseudo cmake):

add_custom_configure_command(GetLinkerScript COMMAND
some_external_program1.exe OUTPUT_VARIABLE LINKER_SCRIPT DEPENDS
version_file.json)
add_custom_configure_command(GetSourcesList COMMAND
some_external_program2.exe OUTPUT_VARIABLE SOURCES DEPENDS config_file.json)

add_library(MyLib)
target_sources(MyLib PUBLIC ${SOURCES})
#Add custom target for the linker script that if it changes the lib needs
to be re-linked
add_custom_target(LinkerScript ...)

Is there a way to achieve this behavior (namely if I change the linker
script, then generating the list of sources won't happen - and not a
rebuild)?
Note this is just an example, in reality I have 10 different cmake
variables with different purposes that are outputted from the external
configuration system - but the dependencies are quite clear.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190409/6acce1dc/attachment.html>


More information about the CMake mailing list