Add dependency to ZERO_CHECK? [SOLVED]

For my project I need to create executables with different “branding” (e.g. exe file name, window title, etc.), some of which needs to be compiled in (i.e. not runtime editable).

Since the branding will be modified by non-programmers I set up a JSON file that gets passed to CMake as a command-line argument (-DBranding=“MyBrand.json”). In my CMakeLists.txt I read the JSON file and use its values to populate preprocessor definitions that then get used in C++ code.

The trouble is that any changes to the JSON do not get picked up by ZERO_CHECK, the “let me re-run CMake for you, because CMake files changed” target.

Adding the JSON file to the executable target doesn’t help, because changes to the JSON file need to trigger a CMake re-run to update the preprocessor definitions. Re-compiling the target when the JSON changes is useless, because CMake didn’t change the preprocessor definitions.

Is it possible to add a file dependency to ZERO_CHECK? Similarly to how it already checks whether CMakePresets.json was modified after its last run, I’d like it to check the timestamp of my JSON file …

The better solution is to use add_custom_command to read the JSON and write a header or something like that.

Failing that, you can add to CMAKE_CONFIGURE_DEPENDS to make CMake rerun when the file changes.

Thank you for the add_custom_command idea, that might be a better approach.

Regardless, CMAKE_CONFIGURE_DEPENDS is exactly what I was looking for! Much appreciated!