Explorar o código

Add option to use git describe to generate BUILD_TAG

Add an option to use git describe to generate the value for BUILD_TAG.
This should help differentiate internal/test versions more easily.
Default the option off for now, since it is not reliable - it will not
be regenerated if the git status changes after cmake is run.

However anyone wanting to generate a RPM/DEB that they
intend to share or load to a shared cluster may want to enable it.

We could move the generation of the build_config.h (or the part of it
that generates #define BUILD_TAG) into a custom target that is executed
on every make (but which only modifies the file if the contents is
different.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman %!s(int64=14) %!d(string=hai) anos
pai
achega
3c98abc461
Modificáronse 2 ficheiros con 18 adicións e 2 borrados
  1. 11 2
      CMakeLists.txt
  2. 7 0
      cmake_modules/commonSetup.cmake

+ 11 - 2
CMakeLists.txt

@@ -99,7 +99,7 @@ option(RUNTIME_USER "Set the runtime username")
 option(RUNTIME_GROUP "Set the runtime group")
 option(ENV_XML_FILE "Set the environment xml file name.")
 option(ENV_CONF_FILE "Set the environment conf file name.")
-option(LICENSE_FILE "Set the liscense file to use.")
+option(LICENSE_FILE "Set the license file to use.")
 
 if( NOT LICENSE_FILE )
     set(LICENSE_FILE "LICENSE.txt")
@@ -218,7 +218,16 @@ set(CPACK_SOURCE_IGNORE_FILES
 ## Run file configuration to set build tag along with install lines for generated
 ## config files.
 ###
-set( BUILD_TAG "${CPACK_RPM_PACKAGE_VERSION}_${CPACK_RPM_PACKAGE_RELEASE}-${stagever}")
+if (USE_GIT_DESCRIBE)
+    execute_process(COMMAND "${GIT_COMMAND}" describe --always --abbrev=4 --tags --dirty
+        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+        OUTPUT_VARIABLE BUILD_TAG
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE)
+    MESSAGE ( "${BUILD_TAG}" )
+else ()
+    set( BUILD_TAG "${CPACK_RPM_PACKAGE_VERSION}_${CPACK_RPM_PACKAGE_RELEASE}-${stagever}")
+endif ()
 configure_file(${HPCC_SOURCE_DIR}/build-config.h.cmake "build-config.h" )
 
 #set( CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON )

+ 7 - 0
cmake_modules/commonSetup.cmake

@@ -52,6 +52,7 @@ IF ("${COMMONSETUP_DONE}" STREQUAL "")
   set (USE_OPENSSL 1)      # option(USE_OPENSSL "Configure use of OpenSSL" ON)
   option(USE_ZLIB "Configure use of zlib" ON)
   option(USE_NATIVE_LIBRARIES "Search standard OS locations for thirdparty libraries" ON)
+  option(USE_GIT_DESCRIBE "Use git describe to generate BUILD_TAG" OFF)
 
   option(PORTALURL "Set url to hpccsystems portal download page")
 
@@ -103,6 +104,9 @@ IF ("${COMMONSETUP_DONE}" STREQUAL "")
     if ("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
       add_definitions(/ZI)
     endif ()
+    if ("${GIT_COMMAND}" STREQUAL "")
+        set ( GIT_COMMAND "git.cmd" )
+    endif ()
   else ()
     if (NOT CMAKE_USE_PTHREADS_INIT)
       message (FATAL_ERROR "pthreads support not detected")
@@ -116,6 +120,9 @@ IF ("${COMMONSETUP_DONE}" STREQUAL "")
     endif ()
     # All of these are defined in platform.h too, but need to be defned before any system header is included
     ADD_DEFINITIONS (-D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -D__USE_LARGEFILE64=1 -D__USE_FILE_OFFSET64=1)
+    if ("${GIT_COMMAND}" STREQUAL "")
+        set ( GIT_COMMAND "git" )
+    endif ()
   endif ()
 
   macro(HPCC_ADD_LIBRARY target)