Skip to content

Commit

Permalink
Fix version string formatting
Browse files Browse the repository at this point in the history
Use git to retrieve the git commit hash only if the source directory
looks like a git repository.
  • Loading branch information
ferki authored and FedeDP committed May 12, 2024
1 parent bc3b2e5 commit ffb5213
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ include(GNUInstallDirs)
find_package(PkgConfig)

execute_process(
COMMAND git log -1 --format=%h
COMMAND sh -c "test -d .git && git log -1 --format=%h"
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(GIT_HASH)
set(VERSION "${PROJECT_VERSION}-${GIT_HASH}")
else()
set(VERSION "${PROJECT_VERSION}")
endif()

# Create program target
file(GLOB SOURCES src/*.c src/utils/*.c src/modules/*.c src/modules/sensors/*.c src/modules/backlight_plugins/*.c)

Expand All @@ -26,7 +32,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
)
target_compile_definitions(${PROJECT_NAME} PRIVATE
-D_GNU_SOURCE
-DVERSION="${PROJECT_VERSION}-${GIT_HASH}"
-DVERSION="${VERSION}"
)
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)

Expand Down

0 comments on commit ffb5213

Please sign in to comment.