Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cmake Custom target that runs only once

I need to somehow generate .fidl files based on .cpp and .hpp files. The problem is that if I try to use add_custom_target it runs every time. For add_custom_command I need specify output files, but I do not want to do it. I'd like to do something like this:

add_custom_command(gen_fidl
                   DEPENDS "*.fidl"
                   COMMAND <My Commands>)

But in this case I need specify a rule for .fidl files

How would I be able to do something like this?

like image 701
Denis Kotov Avatar asked Dec 05 '25 09:12

Denis Kotov


1 Answers

I've found the following solution:

add_custom_command(
        OUTPUT fidl_generated_successfully
        DEPENDS ./cmake-build-debug/*.fidl
        COMMAND touch fidl_generated_successfully
        COMMAND <COMMAND TO DO>)

add_custom_target(
        fidl_gen
        DEPENDS fidl_generated_successfully)

add_dependencies(${PROJECT_NAME} fidl_gen)

But the issue there is the generation on the file (fidl_generated_successfully). Are there anywhere better solution without creating useless file fidl_generated_successfully

like image 90
Denis Kotov Avatar answered Dec 06 '25 22:12

Denis Kotov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!