Extract a few cmake commands to dedicated files rather than generating them on the fly

This simplifies a number of escape sequences.

The generated file to configure the man page was split up a bit further:
- code that extracted the GNC_VCS_REV_Y_M from gnc-vcs-info.h was spun out
  into its own function that now sets all parameters in gnc-vcs-info.h
  as environment variables.
- this function is now invoked by configure-manpage.cmake to extract
  the date to insert into the manpage.
- the manpage in addition now shows the full date rather than only
  yyyy-mm. This is how man itself does it as well.
This commit is contained in:
Geert Janssens
2019-08-24 15:33:24 +02:00
parent 0e9e3c107d
commit c4a21bc9d4
7 changed files with 68 additions and 34 deletions

View File

@@ -8,4 +8,7 @@ if (APPLE)
endif(APPLE)
set_dist_list(cmake_DIST CMakeLists.txt README_CMAKE.txt cmake_uninstall.cmake.in)
set_dist_list(cmake_DIST CMakeLists.txt README_CMAKE.txt cmake_uninstall.cmake.in
configure-manpage.cmake git2version-info.cmake
version-info2env.cmake
)

View File

@@ -0,0 +1,17 @@
# Command to configure the gnucash man page
# These commands are store in a separate cmake file as they have to be
# rerun depending on build conditions, not depending on cmake conditions
# (such as did the version string change or not)
#
# The following environment variables are used and should be properly set
# by the calling code:
# - SRC_DIR (top level source code directory)
# - SRC (full path to gnc-vcs-info.h.in)
# - DST (full path to destination for gnc-vcs-info.h)
# - VCS_INFO_FILE (full path to gnc-vcs-info.h - can be in source tree (release builds) or build tree (git builds))
include (${SRC_DIR}/cmake/version-info2env.cmake)
versioninfo2env (${VCS_INFO_FILE})
configure_file(${SRC} ${DST} )
file(COPY gnucash.1
DESTINATION ${DATADIR_BUILD}/gnucash)

View File

@@ -0,0 +1,28 @@
# Create the gnc-vcs-info.h file starting from git.
# It currently sets four parameters
# - GNC_VCS_REV
# - GNC_VCS_REV_DATE
# - GNC_VCS_REV_YEAR
# - GNC_VCS_REV_Y_M
# The following environment variables are used and should be properly set
# by the calling code:
# - SHELL (should point at a bash shell or compatible)
# - SRC_DIR (top level source code directory)
# - SRC (full path to gnc-vcs-info.h.in)
# - DST (full path to destination for gnc-vcs-info.h)
execute_process(
COMMAND ${SHELL} "${SRC_DIR}/util/gnc-vcs-info" -r "${SRC_DIR}"
OUTPUT_VARIABLE GNC_VCS_REV
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${SHELL} "${SRC_DIR}/util/gnc-vcs-info" -d "${SRC_DIR}"
OUTPUT_VARIABLE GNC_VCS_REV_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(SUBSTRING ${GNC_VCS_REV_DATE} 0 4 GNC_VCS_REV_YEAR)
string(SUBSTRING ${GNC_VCS_REV_DATE} 0 7 GNC_VCS_REV_Y_M)
configure_file(${SRC} ${DST} @ONLY)

View File

@@ -0,0 +1,13 @@
# Extract the parameters set in _VCS_INFO_FILE and export them as environment variables
# _VCS_INFO_FILE should be the full path to gnc-vcs-info.h
function (versioninfo2env _VCS_INFO_FILE)
file(STRINGS ${_VCS_INFO_FILE} lines REGEX "#define")
foreach(line ${lines})
string(REGEX REPLACE "^.* (.*) \"(.*)\"" "\\1;\\2" _param_val ${line})
list(GET _param_val 0 _param)
list(GET _param_val 1 _val)
set(${_param} ${_val} PARENT_SCOPE)
endforeach()
endfunction()