Skip to content

Commit a4d4762

Browse files
ferkiFedeDP
authored andcommitted
Fix version string formatting
Use git to retrieve the git commit hash only if the source directory looks like a git repository.
1 parent e256faa commit a4d4762

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

CMakeLists.txt

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ set(CLIGHT_DATADIR "${CMAKE_INSTALL_FULL_DATADIR}/clight"
1414
CACHE PATH "Path for data dir folder")
1515

1616
execute_process(
17-
COMMAND git log -1 --format=%h
17+
COMMAND sh -c "test -d .git && git log -1 --format=%h"
1818
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
1919
OUTPUT_VARIABLE GIT_HASH
2020
OUTPUT_STRIP_TRAILING_WHITESPACE
2121
)
22+
23+
if(GIT_HASH)
24+
set(VERSION "${PROJECT_VERSION}-${GIT_HASH}")
25+
else()
26+
set(VERSION "${PROJECT_VERSION}")
27+
endif()
2228

2329
# Create program target
2430
file(GLOB_RECURSE SOURCES src/*.c)
@@ -33,7 +39,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
3339
)
3440
target_compile_definitions(${PROJECT_NAME} PRIVATE
3541
-D_GNU_SOURCE
36-
-DVERSION="${PROJECT_VERSION}-${GIT_HASH}"
42+
-DVERSION="${VERSION}"
3743
-DCONFDIR="${CLIGHT_CONFDIR}"
3844
-DOLDCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}/default"
3945
-DDATADIR="${CLIGHT_DATADIR}"

0 commit comments

Comments
 (0)