Cmake build: Move interpretation of configure.ac to own function

Created function determineversionandbuildtype() in development/cmake/modules/LyXMacros.cmake
This commit is contained in:
Kornel Benko 2020-07-12 16:27:45 +02:00
parent 1c956cdc16
commit 26fa3b3d9d
2 changed files with 87 additions and 57 deletions

View File

@ -102,6 +102,21 @@ endif()
include(LyXMacros)
include(LyXDestinations)
# Try to get some informations from configure.ac
include(LyXPaths)
determineversionandbuildtype("${TOP_SRC_DIR}/configure.ac" _package_list _version_list _envlist LYX_DATE LYX_BUILD_TYPE)
list(GET _package_list 0 PACKAGE_BASE)
list(GET _package_list 1 PACKAGE_VERSION)
list(GET _package_list 2 PACKAGE_BUGREPORT)
list(GET _envlist 0 LYX_DIR_VER)
list(GET _envlist 1 LYX_USERDIR_VER)
list(GET _version_list 0 LYX_VERSION)
list(GET _version_list 1 LYX_MAJOR_VERSION)
list(GET _version_list 2 LYX_MINOR_VERSION)
list(GET _version_list 3 LYX_RELEASE_LEVEL)
list(GET _version_list 4 LYX_RELEASE_PATCH)
# Usage LYX_OPTION
# 1. parameter: option name without prefix 'LYX_'
# 2. parameter: description
@ -186,6 +201,12 @@ if(help OR HELP)
RETURN()
endif()
if ("${LYX_SUFFIX_VALUE}" MATCHES "")
set(LYX_INSTALL_SUFFIX "${LYX_MAJOR_VERSION}.${LYX_MINOR_VERSION}")
else()
set(LYX_INSTALL_SUFFIX "${LYX_SUFFIX_VALUE}")
endif()
# Check option dependencies
if (LYX_ENABLE_VALGRIND_TESTS)
find_program(VALGRIND_EXECUTABLE "valgrind")
@ -335,10 +356,6 @@ else()
endif()
endif()
# Try to get some informations from configure.ac
include(LyXPaths)
file(STRINGS "${TOP_SRC_DIR}/configure.ac" _config_lines)
if(WIN32)
@ -362,59 +379,6 @@ if(LYX_3RDPARTY_BUILD)
set(LYX_EXTERNAL_MYTHES OFF CACHE STRING "Build 3rdparty mytheslib" FORCE)
endif()
macro(setstripped _varname)
if(${ARGC} GREATER 1)
string(STRIP "${ARGV1}" _v)
if (_v MATCHES "^\\[\(.+\)\\]$")
set(_v ${CMAKE_MATCH_1})
endif()
if(USE_POSIX_PACKAGING)
string(TOLOWER ${_v} ${_varname})
else()
set(${_varname} ${_v})
endif()
else()
set(${_varname})
endif()
endmacro(setstripped)
foreach(_c_l ${_config_lines} )
if(_c_l MATCHES "^AC_INIT\\(\([^,]+\),\([^,]+\), *\\[\([^,]+\)\\] *,\(.*\)")
# Not using CMAKE_MATCH_ directly is needed, because
# its value is now changed inside macro setstripped
set(_PB ${CMAKE_MATCH_1})
set(_PV ${CMAKE_MATCH_2})
set(_PBU ${CMAKE_MATCH_3})
setstripped(PACKAGE_BASE ${_PB})
setstripped(PACKAGE_VERSION ${_PV})
setstripped(PACKAGE_BUGREPORT ${_PBU})
if(PACKAGE_VERSION MATCHES "^\([0-9]+\)\\.\([0-9]+\)\(\\.\([0-9]+\)\(\\.\([0-9]+\)\)?\)?.*$")
set(LYX_MAJOR_VERSION ${CMAKE_MATCH_1})
set(LYX_MINOR_VERSION ${CMAKE_MATCH_2})
set(LYX_RELEASE_LEVEL ${CMAKE_MATCH_4})
set(LYX_RELEASE_PATCH ${CMAKE_MATCH_6})
set(LYX_DIR_VER "LYX_DIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
set(LYX_USERDIR_VER "LYX_USERDIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
if (NOT LYX_RELEASE_LEVEL)
set(LYX_RELEASE_LEVEL 0)
endif()
if (NOT LYX_RELEASE_PATCH)
set(LYX_RELEASE_PATCH 0)
endif()
set(LYX_VERSION "${LYX_MAJOR_VERSION}.${LYX_MINOR_VERSION}")
if ("${LYX_SUFFIX_VALUE}" MATCHES "")
set(LYX_INSTALL_SUFFIX "${LYX_MAJOR_VERSION}.${LYX_MINOR_VERSION}")
else()
set(LYX_INSTALL_SUFFIX "${LYX_SUFFIX_VALUE}")
endif()
endif()
endif()
if(_c_l MATCHES "^AC_SUBST\\( *LYX_DATE *, *\\[\\\"(.*)\\\"\\].*")
set(LYX_DATE "${CMAKE_MATCH_1}")
endif()
endforeach(_c_l)
unset(_config_lines)
FIND_PROGRAM(LYX_GITVERSION git)
#message(STATUS "gitversion = ${LYX_GITVERSION}")
set(LYX_REVISION_VERSION ${LYX_RELEASE_LEVEL})

View File

@ -401,3 +401,69 @@ function(find_python_module module)
endif()
find_package_handle_standard_args(LYX_PY_${module} DEFAULT_MSG LYX_PY_${module_upper})
endfunction(find_python_module)
macro(setstripped _varname)
if(${ARGC} GREATER 1)
string(STRIP "${ARGV1}" _v)
if (_v MATCHES "^\\[\(.+\)\\]$")
set(_v ${CMAKE_MATCH_1})
endif()
if(USE_POSIX_PACKAGING)
string(TOLOWER ${_v} ${_varname})
else()
set(${_varname} ${_v})
endif()
else()
set(${_varname})
endif()
endmacro(setstripped)
# Determine the version and build-type
function(determineversionandbuildtype configfile package version dirs date buildtype)
file(STRINGS "${configfile}" _config_lines)
foreach(_c_l ${_config_lines} )
if(_c_l MATCHES "^AC_INIT\\(\([^,]+\),\([^,]+\), *\\[\([^,]+\)\\] *,\(.*\)")
# Not using CMAKE_MATCH_ directly is needed, because
# its value is now changed inside macro setstripped
set(_PB ${CMAKE_MATCH_1})
set(_PV ${CMAKE_MATCH_2})
set(_PBU ${CMAKE_MATCH_3})
setstripped(PACKAGE_BASE ${_PB})
setstripped(PACKAGE_VERSION ${_PV})
setstripped(PACKAGE_BUGREPORT ${_PBU})
set(${package} ${PACKAGE_BASE} ${PACKAGE_VERSION} ${PACKAGE_BUGREPORT} PARENT_SCOPE)
if(PACKAGE_VERSION MATCHES "^\([0-9]+\)\\.\([0-9]+\)\(\\.\([0-9]+\)\(\\.\([0-9]+\)\)?\)?\([a-z]*\).*$")
set(LYX_MAJOR_VERSION ${CMAKE_MATCH_1})
set(LYX_MINOR_VERSION ${CMAKE_MATCH_2})
set(LYX_RELEASE_LEVEL ${CMAKE_MATCH_4})
set(LYX_RELEASE_PATCH ${CMAKE_MATCH_6})
set(LYX_BUILD_TYPE ${CMAKE_MATCH_7})
set(LYX_DIR_VER "LYX_DIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
set(LYX_USERDIR_VER "LYX_USERDIR_${CMAKE_MATCH_1}${CMAKE_MATCH_2}x")
if (NOT LYX_RELEASE_LEVEL)
set(LYX_RELEASE_LEVEL 0)
endif()
if (NOT LYX_RELEASE_PATCH)
set(LYX_RELEASE_PATCH 0)
endif()
set(LYX_VERSION "${LYX_MAJOR_VERSION}.${LYX_MINOR_VERSION}")
endif()
endif()
if(_c_l MATCHES "^AC_SUBST\\( *LYX_DATE *, *\\[\\\"(.*)\\\"\\].*")
set(LYX_DATE "${CMAKE_MATCH_1}")
endif()
endforeach(_c_l)
set(${version} ${LYX_VERSION} ${LYX_MAJOR_VERSION} ${LYX_MINOR_VERSION} ${LYX_RELEASE_LEVEL} ${LYX_RELEASE_PATCH} PARENT_SCOPE)
set(${dirs} ${LYX_DIR_VER} ${LYX_USERDIR_VER} PARENT_SCOPE)
set(${date} ${LYX_DATE} PARENT_SCOPE)
if(LYX_BUILD_TYPE MATCHES "^\(dev\)$")
set(${buildtype} "development" PARENT_SCOPE)
elseif(LYX_BUILD_TYPE MATCHES "^\(alpha|beta|rc|pre\)$")
set(${buildtype} "prerelease" PARENT_SCOPE)
elseif(LYX_BUILD_TYPE MATCHES "^$")
set(${buildtype} "release" PARENT_SCOPE)
else()
set(${buildtype} "unknown" PARENT_SCOPE)
message(FATAL_ERROR "\"${configfile}\": Unable to determine build-type from suffix \"${LYX_BUILD_TYPE}\" in AC_INIT macro")
endif()
endfunction(determineversionandbuildtype)