开发者

add_custom_command on xml files

开发者 https://www.devze.com 2023-01-25 03:42 出处:网络
our system uses some xml files to generate some code. So I\'ve created a custom command to scan and parse these files, and generate stuff as accorded.This is what I did:

our system uses some xml files to generate some code. So I've created a custom command to scan and parse these files, and generate stuff as accorded. This is what I did:

file(GLOB BEAN_XML_FILES "../../*.xml")

add_custom_command(TARGET communication PRE_BUILD
                   COMMAND python
                   ARGS bean_maker.py --input-directory ${SOURCE_DIR}/docs/beans --output-directory ${SOURCE_DIR}/beans
                   WORKING_DIRECTORY ${SOURCE_DIR}/tools/bean_maker
                   COMMENT "Running bean maker..."
                   DEPENDS ${BEAN_XML_FILE开发者_高级运维S})

The problem is that add_custom_command only runs when I run cmake, even when I modified some xml inside the folder.

How could I do this to run when changes are made to the files?


Use the add_custom_command signature for adding a custom command to produce output files.

add_custom_command(OUTPUT ${GENERATED_SOURCE_FILES}
                   COMMAND command1 [ARGS] [args1...]
                   DEPENDS ${BEAN_XML_FILES})

At build time, the command will execute if the generated files are older than the files they depend on.


The issue is that your custom command only runs when the target needs to be compiled. You need to make CMake thing that the target needs to be recompiled each time you modify one of those xml files.

Here are two options:

  1. Set a decadency that always is changing ( system time, incrementing variable )
  2. Create a second custom command that writes out the latest modified time of all the xml files to a file in your build directory. Depend on that file and you should only see your target recompile after an xml file is changed.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号