From 8b629c2a4db487268704d4cdbb0c98c0249742eb Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Sun, 10 May 2026 23:37:21 +0200 Subject: [PATCH 1/2] build(common): commit_id in src dir When we want to make a tarball release, stripping the git metadata, we need to generate commit_id.h and include it in the source tree. Signed-off-by: Marco Casaroli --- src/common/CMakeLists.txt | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index a7690f1f..578084e8 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -14,16 +14,26 @@ execute_process( if(GIT_DIR) message(STATUS "Detected git repository. Automatic commit ID tracking is enabled.") - - # Generate commit ID header file in source dir if we are in a git repository - add_custom_command( - OUTPUT include/commit_id.h - COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h" - COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h" - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - VERBATIM - DEPENDS always_rebuild - ) + if(OCRE_COMMIT_ID_IN_SRC_DIR) + add_custom_command( + OUTPUT commit_id.h + COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > commit_id.h" + COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> commit_id.h" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + VERBATIM + DEPENDS always_rebuild + ) + add_custom_target(ocre_commit_id DEPENDS commit_id.h) + else() + add_custom_command( + OUTPUT commit_id.h + COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h" + COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + VERBATIM + DEPENDS always_rebuild + ) + endif() endif() file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ocre) @@ -50,7 +60,7 @@ target_sources(OcreCommon PRIVATE common.c include/build_info.h - include/commit_id.h + commit_id.h ) target_include_directories(OcreCommon From de8153036df43b6805b40eecd4cea4c00dc5c05e Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Sun, 10 May 2026 21:45:32 +0000 Subject: [PATCH 2/2] chore(gitignore) correct path to commit_id.h Signed-off-by: Marco Casaroli --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3d32a3e0..6f66f7cc 100644 --- a/.gitignore +++ b/.gitignore @@ -54,7 +54,7 @@ Thumbs.db # Generated by VS settings.json -src/common/include/ocre/commit_id.h +src/common/commit_id.h **/.DS_Store