Custom Cmake target that only runs once

I need to generate files somehow .fidl

based on files .cpp

and .hpp

. The problem is, if I try to use it add_custom_target

, it runs every time. For add_custom_command

I need to specify the output files, but I don't want to. I would like to do something like this:

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

      

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

files

How can I do something like this?

+3


source to share


2 answers


I 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 problem is in the file generation ( fidl_generated_successfully ). Is there a better solution somewhere without creating a useless fidl_generated_successfully

+1


source


The general answer is this: If you don't know what files are generated, you should use a "fake" file approach, such as Denis Kotov suggested. Otherwise, something like this is better:



# definition of fidl_list
add_custom_command( OUTPUT ${fidl_list}
    DEPENDS ${input_files_or_folders_for_generation}
    COMMAND <command_to_do> )

add_custom_target(fidl_gen DEPENDS ${fidl_list})

      

0


source







All Articles