Changeset - 8d17eb8be5a4
[Not reviewed]
default
0 1 0
Hasan Yavuz Ă–ZDERYA - 9 years ago 2017-05-05 08:01:22
hy@ozderya.net
fix get version for the case that there is a mercurial repo but no tag

in such case hg returns "null" tag
1 file changed with 7 insertions and 3 deletions:
0 comments (0 inline, 0 general)
cmake/modules/GetVersion.cmake
Show inline comments
 
@@ -6,71 +6,75 @@
 
# serialplot is free software: you can redistribute it and/or modify
 
# it under the terms of the GNU General Public License as published by
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# serialplot is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
#
 

	
 
# try to get latest version from mercurial
 
find_program(HG hg)
 

	
 
if (HG)
 
  # get latest tag
 
  execute_process(COMMAND ${HG} parents --template {latesttag}
 
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 
    RESULT_VARIABLE HG_RESULT
 
    OUTPUT_VARIABLE HG_LATEST_TAG
 
    OUTPUT_STRIP_TRAILING_WHITESPACE)
 
  if(NOT HG_RESULT EQUAL 0)
 
  if(HG_RESULT EQUAL 0)
 
    if (NOT HG_LATEST_TAG MATCHES "v[0-9.]+")
 
      unset(HG_LATEST_TAG)
 
    endif()
 
  else()
 
    unset(HG_LATEST_TAG)
 
  endif(NOT HG_RESULT EQUAL 0)
 
  endif()
 

	
 
  # get revision
 
  execute_process(COMMAND ${HG} id -i
 
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
 
    RESULT_VARIABLE HG_RESULT
 
    OUTPUT_VARIABLE HG_REVISION
 
    OUTPUT_STRIP_TRAILING_WHITESPACE)
 
  if(NOT HG_RESULT EQUAL 0)
 
    unset(HG_REVISION)
 
  endif(NOT HG_RESULT EQUAL 0)
 
endif (HG)
 

	
 
# Try to get version from .hg_archival file
 
if (NOT HG_LATEST_TAG)
 
  set(HG_ARCHIVAL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/.hg_archival.txt)
 
  if (EXISTS ${HG_ARCHIVAL_FILE})
 
    # get latest tag
 
    file(STRINGS ${HG_ARCHIVAL_FILE} HG_ARCHIVAL_LATEST_TAG REGEX "^latesttag:.+")
 
    string(REGEX REPLACE "latesttag:[ \t]*(.+)" "\\1" HG_LATEST_TAG ${HG_ARCHIVAL_LATEST_TAG})
 

	
 
    # get latest revision
 
    file(STRINGS ${HG_ARCHIVAL_FILE} HG_ARCHIVAL_REV REGEX "^node:.+")
 
    string(REGEX REPLACE "node:[ \t]*([a-fA-F0-9]+)" "\\1" HG_ARCHIVAL_REV ${HG_ARCHIVAL_REV})
 
    string(SUBSTRING ${HG_ARCHIVAL_REV} 0 12 HG_REVISION)
 
  endif()
 
endif ()
 

	
 
# extract version information from tag (remove 'v' prefix)
 
if (NOT ${HG_LATEST_TAG} STREQUAL "")
 
if (HG_LATEST_TAG)
 
  string(REPLACE "v" "" HG_VERSION ${HG_LATEST_TAG})
 
  message("Version from mercurial: ${HG_VERSION} (${HG_REVISION})")
 

	
 
  # replace version string
 
  set(VERSION_STRING ${HG_VERSION})
 
  set(VERSION_REVISION ${HG_REVISION})
 
else ()
 
  message("Failed to find version information from mercurial.")
 
endif ()
 

	
 
# parse version numbers
 
string(REPLACE "." ";" VERSION_LIST ${VERSION_STRING})
 
list(GET VERSION_LIST 0 VERSION_MAJOR)
 
list(GET VERSION_LIST 1 VERSION_MINOR)
 
list(GET VERSION_LIST 2 VERSION_PATCH)
0 comments (0 inline, 0 general)