Rework version-info rules to allow building from github downloaded zip archives

This commit is contained in:
Geert Janssens 2024-06-04 09:27:14 +02:00
parent 3f8b97bb2e
commit bd6e79b4d6
5 changed files with 71 additions and 32 deletions

View File

@ -154,14 +154,23 @@ if (GNC_VCS_INFO_RESULT EQUAL 0)
if (NOT GIT_FOUND) if (NOT GIT_FOUND)
message(SEND_ERROR "Looks like we're building from version control, but can't find git executable. Please install git or set GIT_EXECUTABLE.") message(SEND_ERROR "Looks like we're building from version control, but can't find git executable. Please install git or set GIT_EXECUTABLE.")
endif() endif()
endif()
# Determine whether or not we have to generate a gnc-vcs-info.h file
# Distribution tarballs have this file in the source tree
# Git checkouts or zipfiles downloaded straight from github won't have it
# and require us to build it.
if (BUILDING_FROM_VCS OR NOT EXISTS "${CMAKE_SOURCE_DIR}/libgnucash/core-utilsgnc-vcs-info.h")
set(VCS_INFO_BASE_DIR ${CMAKE_BINARY_DIR}) set(VCS_INFO_BASE_DIR ${CMAKE_BINARY_DIR})
set(GENERATE_VCS_INFO "Yes")
else() else()
set(VCS_INFO_BASE_DIR ${CMAKE_SOURCE_DIR}) set(VCS_INFO_BASE_DIR ${CMAKE_SOURCE_DIR})
set(GENERATE_VCS_INFO "No")
endif() endif()
# The location of gnc-vcs-info.h depends on whether we build from VCS or not # As the file's path is needed by several other build rules, we already define
# And this file is needed in several other build rules, so we define its # that here. The actual build rules (if needed) are in libgnucash/core-utils.
# location once here. set(VCS_INFO_FILE ${VCS_INFO_BASE_DIR}/libgnucash/core-utils/gnc-vcs-info.h CACHE STRING "path to gnc-vcs-info.h file")
set(VCS_INFO_FILE ${VCS_INFO_BASE_DIR}/libgnucash/core-utils/gnc-vcs-info.h)
if (WIN32) if (WIN32)
# Help Windows find the various dependencies. We assume here that the standard advice for building # Help Windows find the various dependencies. We assume here that the standard advice for building

View File

@ -8,7 +8,15 @@ if (APPLE)
endif() endif()
set_dist_list(cmake_DIST CMakeLists.txt README_CMAKE.txt cmake_uninstall.cmake.in set_dist_list(cmake_DIST
configure-appdata.cmake configure-gnucash-desktop.cmake configure-manpage.cmake CMakeLists.txt
configure-totd.cmake git2version-info.cmake version-info2env.cmake README_CMAKE.txt
cmake_uninstall.cmake.in
configure-appdata.cmake
configure-gnucash-desktop.cmake
configure-manpage.cmake
configure-totd.cmake
git2version-info.cmake
no-vcs2version-info.cmake
version-info2env.cmake
) )

View File

@ -0,0 +1,19 @@
# Create the gnc-vcs-info.h file starting from a source directory that's
# - not a git working directory
# - not extracted from a distribution tarball
# 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:
# - PROJECT_VERSION
# - SRC (full path to gnc-vcs-info.h.in)
# - DST (full path to destination for gnc-vcs-info.h)
set (GNC_VCS_REV "${PROJECT_VERSION}-unknown-commit")
string (TIMESTAMP GNC_VCS_REV_DATE "%Y-%m-%d")
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

@ -175,7 +175,7 @@ install(TARGETS gnc-gnome
# No headers to install # No headers to install
set (GNC_APPDATA_IN ${CMAKE_CURRENT_BINARY_DIR}/gnucash.appdata.xml.in) set (GNC_APPDATA_IN ${CMAKE_CURRENT_BINARY_DIR}/gnucash.appdata.xml.in)
if (NOT BUILDING_FROM_VCS) if (NOT GENERATE_VCS_INFO)
# We're building from a dist tarball. # We're building from a dist tarball.
# As a convenience to packagers we have included a pretranslated # As a convenience to packagers we have included a pretranslated
# intermediate appdata file in the dist tarball. # intermediate appdata file in the dist tarball.
@ -255,7 +255,7 @@ set_local_dist(gnome_DIST_local
CMakeLists.txt gnome.i gnucash.appdata.xml.in.in gnucash.desktop.in.in CMakeLists.txt gnome.i gnucash.appdata.xml.in.in gnucash.desktop.in.in
gnucash.releases.xml ${gnc_gnome_noinst_HEADERS} ${gnc_gnome_SOURCES} ${gnome_SCHEME}) gnucash.releases.xml ${gnc_gnome_noinst_HEADERS} ${gnc_gnome_SOURCES} ${gnome_SCHEME})
dist_add_generated(${BUILDING_FROM_VCS} gnucash.appdata.xml.in) dist_add_generated(${GENERATE_VCS_INFO} gnucash.appdata.xml.in)
add_dependencies(gnucash-appdata dist-gnucash-gnome-gnucash-appdata-xml-in) add_dependencies(gnucash-appdata dist-gnucash-gnome-gnucash-appdata-xml-in)
set(gnome_DIST ${gnome_DIST_local} ${test_gnome_DIST} PARENT_SCOPE) set(gnome_DIST ${gnome_DIST_local} ${test_gnome_DIST} PARENT_SCOPE)

View File

@ -87,38 +87,41 @@ set(localedir "${CMAKE_INSTALL_FULL_DATAROOTDIR}/locale")
configure_file(gncla-dir.h.in gncla-dir.h) configure_file(gncla-dir.h.in gncla-dir.h)
### Create gnc-vcs-info.h ### Build rules for gnc-vcs-info.h
# This can only be done when building from a vcs (git/svn/bzr/svk) working directory. # When building from a distribution tarball simply use the one
# This file is shipped in the distribution tarball, so no need to generate it in that case anyway. # found in the source tree.
# The meta-cmake gymnastics here come from https://cmake.org/pipermail/cmake/2010-July/038015.html # When building from a git working directory extract the neede information from git.
if (BUILDING_FROM_VCS) # Otherwise work from the PROJECT_VERSION variable and today's date, but annotate
set(VCS_INFO_BASE_DIR ${CMAKE_BINARY_DIR}) # the version info to indicate it's inaccurate.
else()
set(VCS_INFO_BASE_DIR ${CMAKE_SOURCE_DIR})
endif()
set(VCS_INFO_FILE ${VCS_INFO_BASE_DIR}/libgnucash/core-utils/gnc-vcs-info.h CACHE STRING "path to gnc-vcs-info.h file")
if (BUILDING_FROM_VCS) if (GENERATE_VCS_INFO)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
"/* Autogenerated. Do not change. */ "/* Autogenerated. Do not change. */
#define GNC_VCS_REV \"@GNC_VCS_REV@\" #define GNC_VCS_REV \"@GNC_VCS_REV@\"
#define GNC_VCS_REV_DATE \"@GNC_VCS_REV_DATE@\" #define GNC_VCS_REV_DATE \"@GNC_VCS_REV_DATE@\"
#define GNC_VCS_REV_YEAR \"@GNC_VCS_REV_YEAR@\" #define GNC_VCS_REV_YEAR \"@GNC_VCS_REV_YEAR@\"
#define GNC_VCS_REV_Y_M \"@GNC_VCS_REV_Y_M@\" #define GNC_VCS_REV_Y_M \"@GNC_VCS_REV_Y_M@\"")
")
add_custom_target(gnc-vcs-info ALL if (BUILDING_FROM_VCS)
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h add_custom_target(gnc-vcs-info ALL
COMMAND ${CMAKE_COMMAND} -D SRC=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
-D DST=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h COMMAND ${CMAKE_COMMAND} -D SRC=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
-D SRC_DIR=${CMAKE_SOURCE_DIR} -D DST=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
-D SHELL="${SHELL}" -D SRC_DIR=${CMAKE_SOURCE_DIR}
-P ${CMAKE_SOURCE_DIR}/cmake/git2version-info.cmake -D SHELL="${SHELL}"
) -P ${CMAKE_SOURCE_DIR}/cmake/git2version-info.cmake)
else()
add_custom_target(gnc-vcs-info ALL
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
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 PROJECT_VERSION=${PROJECT_VERSION}
-P ${CMAKE_SOURCE_DIR}/cmake/no-vcs2version-info.cmake)
endif()
else() else()
add_custom_target(gnc-vcs-info DEPENDS ${VCS_INFO_FILE}) add_custom_target(gnc-vcs-info DEPENDS ${VCS_INFO_FILE})
endif() endif()
dist_add_generated (${BUILDING_FROM_VCS} gnc-vcs-info.h) dist_add_generated (${GENERATE_VCS_INFO} gnc-vcs-info.h)
# Dist files # Dist files
set_local_dist(core_utils_DIST_local set_local_dist(core_utils_DIST_local