From: vsr Date: Sat, 2 Oct 2021 12:18:15 +0000 (+0300) Subject: bos #26458 Versioning of sources via git commit id (sha1) X-Git-Tag: V9_8_0a1~4^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=183b7a6491f8b0ced79e3ceedb998df62a363294;p=tools%2Fconfiguration.git bos #26458 Versioning of sources via git commit id (sha1) --- diff --git a/cmake/SalomeMacros.cmake b/cmake/SalomeMacros.cmake index e67a6d9..805d05b 100644 --- a/cmake/SalomeMacros.cmake +++ b/cmake/SalomeMacros.cmake @@ -1142,3 +1142,80 @@ MACRO(SALOME_DO_VAR_SUBSTITUTION env variable value) SET(${env} "${${env}} export ${_item}=${_val}:\${${_item}}\n") ENDIF() ENDMACRO(SALOME_DO_VAR_SUBSTITUTION) + +######################################################################### +# SALOME_SETUP_VERSION() +# +# USAGE: SALOME_SETUP_VERSION(version [DEVELOPMENT]) +# +# ARGUMENTS: +# version [in] Version decriptor (string). +# +# OPTIONS: +# DEVELOPMENT Forces setting development flag. +# +# The macro sets the following variables: +# - PROJECTNAME_MAJOR_VERSION - major version number +# - PROJECTNAME_MINOR_VERSION - minor version number +# - PROJECTNAME_PATCH_VERSION - release version number +# - PROJECTNAME_VERSION - full qualified version +# - PROJECTNAME_VERSION_DEV - development flag (0 value for released version) +# - PROJECTNAME_XVERSION - hexadecimal representation of version +# - PROJECTNAME_GIT_SHA1 - git commit's sha1 +# +FUNCTION(SALOME_SETUP_VERSION version) + # parse arguments + PARSE_ARGUMENTS(SALOME_SETUP_VERSION "" "DEVELOPMENT" ${ARGN}) + # project name in upper case (if not set in master CMakeLists.txt) + STRING(TOUPPER ${PROJECT_NAME} _pkg_uc) + # parse version component + STRING(REGEX MATCHALL "[^.]" _components "${version}") + LIST(LENGTH _components _length) + IF(${_length} GREATER 0) + LIST(GET _components 0 _major) + LIST(REMOVE_AT _components 0) + ELSE() + SET(_major 0) + ENDIF() + LIST(LENGTH _components _length) + IF(${_length} GREATER 0) + LIST(GET _components 0 _minor) + LIST(REMOVE_AT _components 0) + ELSE() + SET(_minor 0) + ENDIF() + LIST(LENGTH _components _length) + IF(${_length} GREATER 0) + LIST(GET _components 0 _patch) + LIST(REMOVE_AT _components 0) + ELSE() + SET(_patch 0) + ENDIF() + # set project version: 'major', 'minor' and 'patch' components + SET(${_pkg_uc}_MAJOR_VERSION ${_major} PARENT_SCOPE) + SET(${_pkg_uc}_MINOR_VERSION ${_minor} PARENT_SCOPE) + SET(${_pkg_uc}_PATCH_VERSION ${_patch} PARENT_SCOPE) + SET(${_pkg_uc}_VERSION ${_major}.${_minor}.${_patch} PARENT_SCOPE) + # set 'development' flag + IF(SALOME_SETUP_VERSION_DEVELOPMENT) + SET(${_pkg_uc}_VERSION_DEV 1 PARENT_SCOPE) + ELSE() + SET(${_pkg_uc}_VERSION_DEV 0 PARENT_SCOPE) + ENDIF() + # set hexa representation of version + SALOME_TOHEXA(${_major} _major_h) + SALOME_TOHEXA(${_minor} _minor_h) + SALOME_TOHEXA(${_patch} _patch_h) + SET(${_pkg_uc}_XVERSION "0x${_major_h}${_minor_h}${_patch_h}" PARENT_SCOPE) + # detect git sha1 + EXECUTE_PROCESS(COMMAND git describe --dirty --tags --match=V* --always + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE _git_version + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + IF(_git_version) + SET(${_pkg_uc}_GIT_SHA1 "${_git_version}" PARENT_SCOPE) + ELSE(_) + SET(${_pkg_uc}_GIT_SHA1 "unknown" PARENT_SCOPE) + ENDIF() +ENDFUNCTION()