From 2d6bdbc1b1d6992249e843964240c490e1609eb1 Mon Sep 17 00:00:00 2001 From: James Larrowe Date: Thu, 23 Jul 2020 10:47:01 -0400 Subject: [PATCH] Use versioning consistent with the Makefile in CMake This uses git to determine the dirty version and uses a fallback if that's not available. --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 014253dd..abc77bae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,10 +59,18 @@ else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic") endif() +# Use versioning consistent with Makefile +# the git revision is used but uses the fallback in an archive + +execute_process(COMMAND git describe --tags --dirty --always + OUTPUT_VARIABLE GIT_REV + ERROR_QUIET) +string(STRIP "${GIT_REV}" GIT_REV) + if(CMAKE_VERSION VERSION_LESS 3.12) - add_definitions(-DBUILD_VERSION_STRING="${PROJECT_VERSION}") + add_definitions(-DBUILD_VERSION_STRING="${GIT_REV}") else() - add_compile_definitions(BUILD_VERSION_STRING="${PROJECT_VERSION}") + add_compile_definitions(BUILD_VERSION_STRING="${GIT_REV}") endif() set(CMAKE_C_STANDARD 11)