mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
parent
0e9e3c107d
commit
c4a21bc9d4
@ -8,4 +8,7 @@ if (APPLE)
|
|||||||
endif(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
|
||||||
|
)
|
||||||
|
17
cmake/configure-manpage.cmake
Normal file
17
cmake/configure-manpage.cmake
Normal 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)
|
28
cmake/git2version-info.cmake
Normal file
28
cmake/git2version-info.cmake
Normal 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)
|
13
cmake/version-info2env.cmake
Normal file
13
cmake/version-info2env.cmake
Normal 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()
|
@ -62,18 +62,6 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
set(VCS_INFO_FILE ${VCS_INFO_BASE_DIR}/libgnucash/core-utils/gnc-vcs-info.h)
|
set(VCS_INFO_FILE ${VCS_INFO_BASE_DIR}/libgnucash/core-utils/gnc-vcs-info.h)
|
||||||
|
|
||||||
# The copious use of backslashes below is to escape escape sequences that
|
|
||||||
# have to end up in the file being written...
|
|
||||||
# eg \\\" will become \", \\\\1 will become \\1 (which cmake will then interpret as \1)
|
|
||||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/manpage.cmake
|
|
||||||
"file(STRINGS \${VCS_INFO_FILE} ym_line REGEX \"GNC_VCS_REV_Y_M\")
|
|
||||||
string(REGEX REPLACE \"^.* \\\"(.*)\\\"\" \"\\\\1\" DATE \${ym_line})
|
|
||||||
configure_file(\${SRC} \${DST} )
|
|
||||||
file(COPY gnucash.1
|
|
||||||
DESTINATION \${DATADIR_BUILD}/gnucash)
|
|
||||||
")
|
|
||||||
|
|
||||||
|
|
||||||
add_custom_command(OUTPUT gnucash.1
|
add_custom_command(OUTPUT gnucash.1
|
||||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gnucash.1.in gnc-vcs-info
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gnucash.1.in gnc-vcs-info
|
||||||
COMMAND ${CMAKE_COMMAND} -D SRC=${CMAKE_CURRENT_SOURCE_DIR}/gnucash.1.in
|
COMMAND ${CMAKE_COMMAND} -D SRC=${CMAKE_CURRENT_SOURCE_DIR}/gnucash.1.in
|
||||||
@ -81,7 +69,8 @@ add_custom_command(OUTPUT gnucash.1
|
|||||||
-D VERSION=${VERSION}
|
-D VERSION=${VERSION}
|
||||||
-D VCS_INFO_FILE=${VCS_INFO_FILE}
|
-D VCS_INFO_FILE=${VCS_INFO_FILE}
|
||||||
-D DATADIR_BUILD=${DATADIR_BUILD}
|
-D DATADIR_BUILD=${DATADIR_BUILD}
|
||||||
-P ${CMAKE_CURRENT_BINARY_DIR}/manpage.cmake
|
-D SRC_DIR=${CMAKE_SOURCE_DIR}
|
||||||
|
-P ${CMAKE_SOURCE_DIR}/cmake/configure-manpage.cmake
|
||||||
)
|
)
|
||||||
add_custom_target(gnucash-manpage DEPENDS gnucash.1)
|
add_custom_target(gnucash-manpage DEPENDS gnucash.1)
|
||||||
dist_add_generated (${BUILDING_FROM_VCS} gnucash.1)
|
dist_add_generated (${BUILDING_FROM_VCS} gnucash.1)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
.\" Process this file with
|
.\" Process this file with
|
||||||
.\" groff -man -Tascii foo.1
|
.\" groff -man -Tascii foo.1
|
||||||
.\"
|
.\"
|
||||||
.TH GNUCASH 1 "@DATE@" "Version @VERSION@" "GnuCash Manual Pages"
|
.TH GNUCASH 1 "@GNC_VCS_REV_DATE@" "Version @VERSION@" "GnuCash Manual Pages"
|
||||||
.SH NAME
|
.SH NAME
|
||||||
gnucash \- personal finance manager
|
gnucash \- personal finance manager
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
|
@ -54,29 +54,13 @@ file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
|
|||||||
#define GNC_VCS_REV_Y_M \"@GNC_VCS_REV_Y_M@\"
|
#define GNC_VCS_REV_Y_M \"@GNC_VCS_REV_Y_M@\"
|
||||||
")
|
")
|
||||||
|
|
||||||
set(SCM_REV_COMMAND "${CMAKE_SOURCE_DIR}/util/gnc-vcs-info -r")
|
|
||||||
set(SCM_REV_DATE_COMMAND "${CMAKE_SOURCE_DIR}/util/gnc-vcs-info -d")
|
|
||||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/version.cmake
|
|
||||||
"execute_process(
|
|
||||||
COMMAND ${SHELL} ${SCM_REV_COMMAND} ${CMAKE_SOURCE_DIR}
|
|
||||||
OUTPUT_VARIABLE GNC_VCS_REV
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
||||||
)
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${SHELL} ${SCM_REV_DATE_COMMAND} ${CMAKE_SOURCE_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)
|
|
||||||
")
|
|
||||||
|
|
||||||
add_custom_target(gnc-vcs-info ALL
|
add_custom_target(gnc-vcs-info ALL
|
||||||
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
|
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
|
||||||
COMMAND ${CMAKE_COMMAND} -D SRC=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
|
COMMAND ${CMAKE_COMMAND} -D SRC=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
|
||||||
-D DST=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
|
-D DST=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
|
||||||
-P ${CMAKE_CURRENT_BINARY_DIR}/version.cmake
|
-D SRC_DIR=${CMAKE_SOURCE_DIR}
|
||||||
|
-D SHELL="${SHELL}"
|
||||||
|
-P ${CMAKE_SOURCE_DIR}/cmake/git2version-info.cmake
|
||||||
)
|
)
|
||||||
else(BUILDING_FROM_VCS)
|
else(BUILDING_FROM_VCS)
|
||||||
add_custom_target(gnc-vcs-info DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gnc-vcs-info.h)
|
add_custom_target(gnc-vcs-info DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/gnc-vcs-info.h)
|
||||||
|
Loading…
Reference in New Issue
Block a user