소스 검색

Merge pull request #1015 from richardkchapman/gitdescribe

Use git describe to generate/check tags
Reviewed-by: Gavin Halliday <ghalliday@hpccsystems.com>
Gavin Halliday 13 년 전
부모
커밋
a36dee9fc3
2개의 변경된 파일36개의 추가작업 그리고 1개의 파일을 삭제
  1. 28 1
      CMakeLists.txt
  2. 8 0
      cmake_modules/commonSetup.cmake

+ 28 - 1
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")
@@ -219,6 +219,33 @@ set(CPACK_SOURCE_IGNORE_FILES
 ## config files.
 ###
 set( BUILD_TAG "${CPACK_RPM_PACKAGE_VERSION}_${CPACK_RPM_PACKAGE_RELEASE}-${stagever}")
+if (USE_GIT_DESCRIBE OR CHECK_GIT_TAG)
+    execute_process(COMMAND "${GIT_COMMAND}" describe --exact --tags --dirty
+        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+        OUTPUT_VARIABLE GIT_BUILD_TAG
+        ERROR_QUIET
+        OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if (CHECK_GIT_TAG)
+        if(NOT "${GIT_BUILD_TAG}" STREQUAL "${BUILD_TAG}")
+            message(FATAL_ERROR "Git tag ${GIT_BUILD_TAG} does not match source version ${BUILD_TAG}" )
+        endif()
+    else()
+        if ("${GIT_BUILD_TAG}" STREQUAL "")
+            execute_process(COMMAND "${GIT_COMMAND}" describe --always --tags --all --abbrev=6 --dirty --long
+                WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+                OUTPUT_VARIABLE GIT_BUILD_TAG
+                ERROR_QUIET
+                OUTPUT_STRIP_TRAILING_WHITESPACE)
+        endif()
+    endif()
+    message ("-- Git tag is '${GIT_BUILD_TAG}'")
+    if(NOT "${GIT_BUILD_TAG}" STREQUAL "${BUILD_TAG}")
+        if(NOT "${GIT_BUILD_TAG}" STREQUAL "") # probably means being built from a tarball...
+            set( BUILD_TAG "${BUILD_TAG}[${GIT_BUILD_TAG}]")
+        endif()
+    endif()
+endif()
+message ("-- Build tag is '${BUILD_TAG}'")
 configure_file(${HPCC_SOURCE_DIR}/build-config.h.cmake "build-config.h" )
 
 #set( CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON )

+ 8 - 0
cmake_modules/commonSetup.cmake

@@ -52,6 +52,8 @@ 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" ON)
+  option(CHECK_GIT_TAG "Require git tag to match the generated build tag" OFF)
 
   option(PORTALURL "Set url to hpccsystems portal download page")
 
@@ -103,6 +105,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 +121,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)