Reputation: 174
What I need is filtering the *.h and *.cpp files in some directory, then format it using some script, so I write the following codes:
add_custom_command(
DEPENDS ${GENERATED_STUFF}
COMMAND find "${OUTPUT_DIR}/include/SOME_PATH" -iname *.h -o -iname *.cpp | xargs /net/binlib/lib/clang/clang-format-3.9.0 -i
OUTPUT ?????
)
However, this command just modifies the existing files, so no new file outputs are generated. In this case, how can I define the output? Is there any other way to resolve this need? I only want this command to be re-executed only when file changes.
Upvotes: 3
Views: 5761
Reputation: 65928
You may create "timestamp" file. It will be used by build system only for extract timestamp and compare it with files under DEPENDS.
add_custom_command(
DEPENDS ${GENERATED_STUFF}
COMMAND find "${OUTPUT_DIR}/include/exchange_protocol" -iname *.h -o -iname *.cpp | xargs /net/binlib/lib/clang/clang-format-3.9.0 -i
COMMAND ${CMAKE_COMMAND} -E touch my_file.stamp
OUTPUT my_file.stamp
)
For make your add_custom_command
work, you need to use add_custom_target
which depends on given file.
Upvotes: 5