Adds commit hash to the version.
[apps/app-templates.git] / cmake / cmake.d / 02-variables.cmake
index 0fc55a3..dc1c313 100644 (file)
@@ -67,6 +67,13 @@ execute_process(COMMAND git describe --abbrev=0
        OUTPUT_STRIP_TRAILING_WHITESPACE
 )
 
+# Get the git commit hash to append to the version
+execute_process(COMMAND git rev-parse --short HEAD
+       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+       OUTPUT_VARIABLE COMMIT_HASH
+       OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+
 # Detect unstaged or untracked changes
 execute_process(COMMAND git status --short
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
@@ -84,7 +91,9 @@ endif()
 # attributes then add the dirty flag if git repo not sync'ed
 project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES ${PROJECT_LANGUAGES})
 if(NOT ${DIRTY_FLAG})
-set(PROJECT_VERSION "${PROJECT_VERSION}-dirty")
+       set(PROJECT_VERSION "${PROJECT_VERSION}-${COMMIT_HASH}-dirty")
+else()
+       set(PROJECT_VERSION "${PROJECT_VERSION}-${COMMIT_HASH}")
 endif()
 
 set(AFB_TOKEN   ""      CACHE PATH "Default AFB_TOKEN")
@@ -176,7 +185,7 @@ set(BINDIR bin CACHE PATH "User executables")
 set(ETCDIR etc CACHE PATH "Read only system configuration data")
 set(LIBDIR lib CACHE PATH "System library directory")
 set(HTTPDIR htdocs CACHE PATH "HTML5 data directory")
-set(DATADIR data CACHE PATH "External data resources files")
+set(DATADIR var CACHE PATH "External data resources files")
 
 # Normally CMake uses the build tree for the RPATH when building executables
 # etc on systems that use RPATH. When the software is installed the executables