0

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_FILES})

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?

einpoklum
  • 118,144
  • 57
  • 340
  • 684
scooterman
  • 1,336
  • 2
  • 17
  • 36

2 Answers2

0

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.
RobertJMaynard
  • 2,183
  • 14
  • 13
0

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.

Chin Huang
  • 12,912
  • 4
  • 46
  • 47