[CMake] Dinamically generated dependencies

Damián Nohales damiannohales at gmail.com
Tue Sep 9 10:36:33 EDT 2014


Hi,

I am trying to generate file that depends on a set of files that can
change throughout different make invocations.

To understand it better, let's show you the code:

-----------
cmake_minimum_required(VERSION 2.8)

project(demo-one C)

add_custom_command(
    OUTPUT
        "${CMAKE_BINARY_DIR}/generated.c"
    COMMAND
        generate -o "${CMAKE_BINARY_DIR}/generated.c"
    DEPENDS
        "$(shell generate-dependencies-list)"
    COMMENT
        "Generating generated.c"
)

add_executable(main main.c "${CMAKE_BINARY_DIR}/generated.c")
-----------

So, I want to generate the file generated.c with the "generate"
command and this files needs to be regenerated when the files
specified by "generated-dependencies-list" command changes. As you may
notice, "generated-dependencies-list" can generate different set of
files throughout different make invocations, so is not feasible to get
the result of "generated-dependencies-list" at configure time to then
pass the result to add_custom_command.

Actually the above code somewhat works, but it looks like a hack that
will only work for Makefile backend, also the make rule doesn't look
as what I'm expecting, after all, it's a hack:

generated.c: ../$(shell\ generate-dependencies-list)

Has CMake any feature to achieve this?

Basically, I want this rule or something to get the same result:

generated.c: $(shell generate-dependencies-list)


More information about the CMake mailing list