Skip to content

Update build/resources/backend_versions.json during cmake#1114

Open
superm1 wants to merge 1 commit intomainfrom
superm1/backend-resources
Open

Update build/resources/backend_versions.json during cmake#1114
superm1 wants to merge 1 commit intomainfrom
superm1/backend-resources

Conversation

@superm1
Copy link
Collaborator

@superm1 superm1 commented Feb 13, 2026

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

@superm1 superm1 marked this pull request as draft February 13, 2026 12:45
@superm1
Copy link
Collaborator Author

superm1 commented Feb 13, 2026

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
@superm1 superm1 force-pushed the superm1/backend-resources branch from 9efd2fc to 843f9fd Compare February 18, 2026 22:31
@superm1 superm1 requested review from Copilot and jeremyfowers and removed request for jeremyfowers February 18, 2026 22:31
@superm1 superm1 marked this pull request as ready for review February 18, 2026 22:31
@superm1
Copy link
Collaborator Author

superm1 commented Feb 18, 2026

This seems not to work as I intended on some versions of cmake. Marking as a draft for now.

I've fixed the issue, it was an incorrect use of the DEPENDS keyword.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_resources build target driven by a globbed resource file list (CONFIGURE_DEPENDS) to trigger rebuild-time copying.
  • Copies src/cpp/resources/ into ${CMAKE_BINARY_DIR}/resources via 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.

Comment on lines +704 to +714
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
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +703 to +709
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}
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

# Copy resources to the runtime directoriy after build
# Collect resource files for dependency tracking
file(GLOB_RECURSE RESOURCE_FILES
Copy link

Copilot AI Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
file(GLOB_RECURSE RESOURCE_FILES
file(GLOB_RECURSE RESOURCE_FILES
LIST_DIRECTORIES false

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmake --build --preset default does not update build/resource/backend_version.json

1 participant

Comments