build: infer VERSION from Git history
authorJo-Philipp Wich <jo@mein.io>
Fri, 17 Feb 2017 17:22:02 +0000 (18:22 +0100)
committerJo-Philipp Wich <jo@mein.io>
Fri, 17 Feb 2017 17:22:02 +0000 (18:22 +0100)
Pass short hash and commit date as VERSION string.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
CMakeLists.txt

index d7730c6c7a2ab2ecd1bf6d030e00b056c68979b9..34a0a6f996d609eb0bc51e11e9196dcfe4fa6612 100644 (file)
@@ -16,6 +16,15 @@ IF(NOT BUILD_CPU)
        SET(BUILD_CPU "${CMAKE_SYSTEM_PROCESSOR}")
 ENDIF()
 
+EXECUTE_PROCESS(COMMAND git log -1 "--format=%h (%ci)"
+       OUTPUT_VARIABLE GIT_VERSION
+       OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
+IF(NOT GIT_VERSION)
+       SET(GIT_VERSION "unknown")
+ENDIF()
+
 ADD_DEFINITIONS(-Os -Wall --std=gnu99 -g3 -Wmissing-declarations
        -DDATADIR="/usr/share"
        -DOPKGETCDIR="/etc"
@@ -23,6 +32,7 @@ ADD_DEFINITIONS(-Os -Wall --std=gnu99 -g3 -Wmissing-declarations
        -DOPKGLIBDIR="/usr/lib"
        -DHOST_CPU_STR="${HOST_CPU}"
        -DBUILD_CPU=${BUILD_CPU}
+       -DVERSION="${GIT_VERSION}"
 )
 
 ADD_SUBDIRECTORY(libbb)