Update build/resources/backend_versions.json during cmake#1114
Update build/resources/backend_versions.json during cmake#1114
Conversation
|
This seems not to work as I intended on some versions of cmake. Marking as a draft for now. |
Move resource copying from CMake configuration phase to build phase with proper file dependency tracking using CONFIGURE_DEPENDS and DEPENDS. This ensures that changes to src/cpp/resources files are detected and copied to the build directory on each build. Fixes #1104
9efd2fc to
843f9fd
Compare
I've fixed the issue, it was an incorrect use of the |
There was a problem hiding this comment.
Pull request overview
Moves copying of C++ runtime resource files out of the CMake configure step and into the build step, so resource changes (e.g., backend_versions.json) are picked up by cmake --build without requiring reconfiguration (Fixes #1104).
Changes:
- Adds a
copy_resourcesbuild target driven by a globbed resource file list (CONFIGURE_DEPENDS) to trigger rebuild-time copying. - Copies
src/cpp/resources/into${CMAKE_BINARY_DIR}/resourcesvia a custom command with dependency tracking. - Ensures the main executable depends on the resource-copying target.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| OUTPUT ${CMAKE_BINARY_DIR}/resources/.resource_timestamp | ||
| COMMAND ${CMAKE_COMMAND} -E copy_directory | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/resources | ||
| ${CMAKE_BINARY_DIR}/resources | ||
| COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/resources/.resource_timestamp | ||
| DEPENDS ${RESOURCE_FILES} | ||
| COMMENT "Copying resources to build directory" | ||
| ) | ||
|
|
||
| add_custom_target(copy_resources ALL | ||
| DEPENDS ${CMAKE_BINARY_DIR}/resources/.resource_timestamp |
There was a problem hiding this comment.
The stamp file output is placed inside the resources directory (${CMAKE_BINARY_DIR}/resources/.resource_timestamp). Since the build later copies/installs the entire resources directory, this dotfile will end up in the runtime output and in packaged installs. Consider moving the stamp outside the resources tree (e.g., ${CMAKE_CURRENT_BINARY_DIR}/resources.stamp) or explicitly excluding it from the subsequent copy/install steps.
| OUTPUT ${CMAKE_BINARY_DIR}/resources/.resource_timestamp | |
| COMMAND ${CMAKE_COMMAND} -E copy_directory | |
| ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/resources | |
| ${CMAKE_BINARY_DIR}/resources | |
| COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/resources/.resource_timestamp | |
| DEPENDS ${RESOURCE_FILES} | |
| COMMENT "Copying resources to build directory" | |
| ) | |
| add_custom_target(copy_resources ALL | |
| DEPENDS ${CMAKE_BINARY_DIR}/resources/.resource_timestamp | |
| OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/resources.stamp | |
| COMMAND ${CMAKE_COMMAND} -E copy_directory | |
| ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/resources | |
| ${CMAKE_BINARY_DIR}/resources | |
| COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/resources.stamp | |
| DEPENDS ${RESOURCE_FILES} | |
| COMMENT "Copying resources to build directory" | |
| ) | |
| add_custom_target(copy_resources ALL | |
| DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/resources.stamp |
| add_custom_command( | ||
| OUTPUT ${CMAKE_BINARY_DIR}/resources/.resource_timestamp | ||
| COMMAND ${CMAKE_COMMAND} -E copy_directory | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/resources | ||
| ${CMAKE_BINARY_DIR}/resources | ||
| COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/resources/.resource_timestamp | ||
| DEPENDS ${RESOURCE_FILES} |
There was a problem hiding this comment.
The custom command writes ${CMAKE_BINARY_DIR}/resources/.resource_timestamp, but the resources directory may not exist on a clean build. Since the next step touches a file inside that directory, add an explicit directory creation step (e.g., ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/resources) before copy/touch to avoid build failures on fresh build trees.
|
|
||
| # Copy resources to the runtime directoriy after build | ||
| # Collect resource files for dependency tracking | ||
| file(GLOB_RECURSE RESOURCE_FILES |
There was a problem hiding this comment.
file(GLOB_RECURSE ...) will include directories by default. Adding LIST_DIRECTORIES false would keep RESOURCE_FILES limited to actual files, avoiding spurious dependencies/rebuild triggers from directory timestamp changes.
| file(GLOB_RECURSE RESOURCE_FILES | |
| file(GLOB_RECURSE RESOURCE_FILES | |
| LIST_DIRECTORIES false |
Move resource copying from CMake configuration phase to build phase with proper file dependency tracking using CONFIGURE_DEPENDS and DEPENDS. This ensures that changes to src/cpp/resources files are detected and copied to the build directory on each build.
Fixes #1104