Commit 14424394 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[CHANGE] - VERSION file systax changed a little bit. Added keyword hg which is...

[CHANGE] - VERSION file systax changed a little bit. Added keyword hg which is replaced by revision number. This is needed for packaging
parent 0d449bcf
# OW Version File. This file specifies the version. The line VERSION=X.Y.Z is
# used and parsed. If you do not want a version, comment it out.
# used and parsed. This file has to be here everytime. The VERSION needs to be
# set properly or CMake will fail.
#
# SYNTAX: The version string always is X.Y.Z with an optional postfix of "+hg".
# If this postfix is set, CMake will replace it with the Mercurial
# Revision. This is useful for packaging in most cases.
#
# IMPORTANT: If you modify the file, cmake re-creates the version header. But
# it is not able to set all library version. Please re-run cmake if
# you change something here.
#
# NOTE: do not add a space after #. The current CMake script will fail.
#VERSION=1.3.0
VERSION=1.2.0+hg
......@@ -179,14 +179,9 @@ INCLUDE_DIRECTORIES( ${OW_VERSION_HEADER_DIRECTORY} )
SETUP_VERSION_HEADER( ${OW_VERSION_HEADER} )
# Set the OW version string. This can be used by others for setting target versions during compilation.
GET_VERSION_STRING( dummy OW_VERSION "1.0.0 " )
IF( NOT DEFINED OW_VERSION )
# CMake does not like unset variables for target properties.
SET( OW_VERSION "1.0.0" )
ENDIF()
GET_VERSION_STRING( OW_VERSION OW_API_VERSION )
# We need a SOVERSION too. This somehow describes the API compatibility. We use the major number here.
SPLIT_VERSION_STRING( ${OW_VERSION} OW_VERSION_MAJOR OW_VERSION_MINOR OW_VERSION_PATCH )
SPLIT_VERSION_STRING( ${OW_API_VERSION} OW_VERSION_MAJOR OW_VERSION_MINOR OW_VERSION_PATCH )
SET( OW_SOVERSION ${OW_VERSION_MAJOR} )
# ---------------------------------------------------------------------------------------------------------------------------------------------------
......
......@@ -421,9 +421,9 @@ ENDFUNCTION( SETUP_DEV_INSTALL )
# empty, the contents of it get combined with the mercurial results if mercurial is installed. If not, only the file content will be used. If
# both methods fail, a default string is used.
# _version the returned version string
# _file_version returns only the version loaded from the version file. This is useful to set CMake version info for release compilation
# _api_version returns only the API-version loaded from the version file. This is useful to set CMake version info for release compilation
# _default a default string you specify if all version check methods fail
FUNCTION( GET_VERSION_STRING _version _file_version _default )
FUNCTION( GET_VERSION_STRING _version _api_version )
# Undef the OW_VERSION variable
UNSET( OW_VERSION_HG )
UNSET( OW_VERSION_FILE )
......@@ -434,7 +434,7 @@ FUNCTION( GET_VERSION_STRING _version _file_version _default )
# Read the version file
FILE( READ ${OW_VERSION_FILENAME} OW_VERSION_FILE_CONTENT )
# The first regex will mathc
STRING(REGEX REPLACE ".*[^#]VERSION=([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" OW_VERSION_FILE ${OW_VERSION_FILE_CONTENT} )
STRING( REGEX REPLACE ".*[^#]VERSION=([0-9]+\\.[0-9]+\\.[0-9]+(\\+hg)?).*" "\\1" OW_VERSION_FILE ${OW_VERSION_FILE_CONTENT} )
STRING( COMPARE EQUAL ${OW_VERSION_FILE} ${OW_VERSION_FILE_CONTENT} OW_VERSION_FILE_INVALID )
IF( OW_VERSION_FILE_INVALID )
UNSET( OW_VERSION_FILE )
......@@ -445,31 +445,33 @@ FUNCTION( GET_VERSION_STRING _version _file_version _default )
IF( OW_VERSION_FILE STREQUAL "" )
UNSET( OW_VERSION_FILE )
ENDIF()
# set the return parameter too
SET( ${_file_version} ${OW_VERSION_FILE} PARENT_SCOPE )
ENDIF()
# if the version file could not be parsed, print error
IF( NOT OW_VERSION_FILE )
MESSAGE( FATAL_ERROR "Could not parse \"${PROJECT_SOURCE_DIR}/../VERSION\"." )
ENDIF()
# Use hg to query version information.
# -> the nice thing is: if hg is not available, no compilation errors anymore
# NOTE: it is run insde the project source directory
EXECUTE_PROCESS( COMMAND hg parents --template "{rev}:{node|short} {branches} {tags}" OUTPUT_VARIABLE OW_VERSION_HG RESULT_VARIABLE hgParentsRetVar
EXECUTE_PROCESS( COMMAND hg parents --template "{rev}" OUTPUT_VARIABLE OW_VERSION_HG RESULT_VARIABLE hgParentsRetVar
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
IF( NOT ${hgParentsRetVar} STREQUAL 0 )
UNSET( OW_VERSION_HG )
ENDIF()
# Use the version strings and set them as #define
IF( DEFINED OW_VERSION_HG AND DEFINED OW_VERSION_FILE )
SET( ${_version} "${OW_VERSION_FILE} - ${OW_VERSION_HG}" PARENT_SCOPE )
ELSEIF( DEFINED OW_VERSION_FILE )
SET( ${_version} "${OW_VERSION_FILE}" PARENT_SCOPE )
ELSEIF( DEFINED OW_VERSION_HG )
SET( ${_version} "${OW_VERSION_HG}" PARENT_SCOPE )
# be more nice if we do not find mercruial version. The simply strip the +hg tag.
STRING( REGEX REPLACE "\\+hg" "" OW_VERSION ${OW_VERSION_FILE} )
ELSE()
SET( ${_version} ${_default} PARENT_SCOPE )
# if we have the mercurial info -> complement the version string
STRING( REGEX REPLACE "hg" "hg${OW_VERSION_HG}" OW_VERSION ${OW_VERSION_FILE} )
ENDIF()
SET( ${_version} ${OW_VERSION} PARENT_SCOPE )
# we need to separate the API version too. This basically is the same as the release version, but without the HG statement
STRING( REGEX REPLACE "([0-9]+\\.[0-9]+\\.[0-9]).*" "\\1" OW_API_VERSION ${OW_VERSION} )
SET( ${_api_version} ${OW_API_VERSION} PARENT_SCOPE )
ENDFUNCTION( GET_VERSION_STRING )
# This functions adds a custom target for generating the specified version header. This is very useful if you want to include build-time version
......
......@@ -28,5 +28,5 @@
# know.)
INCLUDE( BuildUtils.cmake )
GET_VERSION_STRING( OW_VERSION OW_FILE_VERSION "0.0.0" )
GET_VERSION_STRING( OW_VERSION OW_API_VERSION )
FILE( WRITE ${HEADER_FILENAME} "// generated by CMake. Do not modify.\n#define W_VERSION \"${OW_VERSION}\"\n" )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment