Skip to content

Commit 8b629c2

Browse files
committed
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 <marco.casaroli@gmail.com>
1 parent 458c8bf commit 8b629c2

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

src/common/CMakeLists.txt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@ execute_process(
1414

1515
if(GIT_DIR)
1616
message(STATUS "Detected git repository. Automatic commit ID tracking is enabled.")
17-
18-
# Generate commit ID header file in source dir if we are in a git repository
19-
add_custom_command(
20-
OUTPUT include/commit_id.h
21-
COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h"
22-
COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h"
23-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
24-
VERBATIM
25-
DEPENDS always_rebuild
26-
)
17+
if(OCRE_COMMIT_ID_IN_SRC_DIR)
18+
add_custom_command(
19+
OUTPUT commit_id.h
20+
COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > commit_id.h"
21+
COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> commit_id.h"
22+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
23+
VERBATIM
24+
DEPENDS always_rebuild
25+
)
26+
add_custom_target(ocre_commit_id DEPENDS commit_id.h)
27+
else()
28+
add_custom_command(
29+
OUTPUT commit_id.h
30+
COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h"
31+
COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/commit_id.h"
32+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
33+
VERBATIM
34+
DEPENDS always_rebuild
35+
)
36+
endif()
2737
endif()
2838

2939
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ocre)
@@ -50,7 +60,7 @@ target_sources(OcreCommon
5060
PRIVATE
5161
common.c
5262
include/build_info.h
53-
include/commit_id.h
63+
commit_id.h
5464
)
5565

5666
target_include_directories(OcreCommon

0 commit comments

Comments
 (0)