How to make CMake custom target trigger only for some dependencies?

566 views Asked by At

I have a CMake custom target that depends on an input file and a program, like this:

add_custom_command(
    OUTPUT generate
    COMMAND install generate
)
add_custom_command(
    OUTPUT header.h
    DEPENDS generate header.txt
    COMMAND generate -i header.txt -o header.h
)

Because of how the build system works, the 'generate' application is not available when compiling and needs to be installed everytime with the first custom command.

The issue I have is that, since the application always needs to be installed, the custom command is always running, obviously. So what I want is for the output 'header.h' to only be generated when 'header.txt' changes. Basically, 'header.txt' changes would be the only trigger to this custom command. However, if this is triggered, then I also want to run the first custom command so that we can install the application.

If 'header.txt' did not change, then there is no need to install the application with the first custom command since it is not going to be used.

How can this be done in CMake?

0

There are 0 answers