Skip to content

Commit

Permalink
Rework version-info rules to allow building from github downloaded zi…
Browse files Browse the repository at this point in the history
…p archives
  • Loading branch information
gjanssens committed Jun 4, 2024
1 parent 1b7f1e2 commit 1acc3db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,26 @@ if (GNC_VCS_INFO_RESULT EQUAL 0)
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.")
endif()
endif()

if (BUILDING_FROM_VCS)
set(VCS_INFO_BASE_DIR ${CMAKE_BINARY_DIR})
set(GENERATE_VCS_INFO = "Yes")
else()
set(VCS_INFO_BASE_DIR ${CMAKE_SOURCE_DIR})
find_path(test_vcs_info_file "gnc-vcs-info.h" PATHS ${CMAKE_SOURCE_DIR}/libgnucash/core-utils)
if (${test_vcs_info_file} STREQUAL "test_vcs_info_file-NOTFOUND")
set(VCS_INFO_BASE_DIR ${CMAKE_BINARY_DIR})
set(GENERATE_VCS_INFO = "Yes")
else()
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
# And this file is needed in several other build rules, so we define its
# location once here.
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 CACHE STRING "path to gnc-vcs-info.h file")


if (WIN32)
# Help Windows find the various dependencies. We assume here that the standard advice for building
Expand Down
29 changes: 29 additions & 0 deletions cmake/no-vcs2version-info.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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 (should point at a bash shell or compatible)
# - 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)
17 changes: 7 additions & 10 deletions libgnucash/core-utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,13 @@ set(localedir "${CMAKE_INSTALL_FULL_DATAROOTDIR}/locale")
configure_file(gncla-dir.h.in gncla-dir.h)


### Create gnc-vcs-info.h
# This can only be done when building from a vcs (git/svn/bzr/svk) working directory.
# This file is shipped in the distribution tarball, so no need to generate it in that case anyway.
### Build rules for gnc-vcs-info.h
# Uses information extracted from git if in an active working directory.
# If not in a working directory, but a gnc-vcs-info.h file is found in
# the source tree, use that one, and assume we're building from a distribution tarball.
# If that file is missing, create one ourselves but make it clear the version info is inacurate.
# Worst case, just create
# The meta-cmake gymnastics here come from https://cmake.org/pipermail/cmake/2010-July/038015.html
if (BUILDING_FROM_VCS)
set(VCS_INFO_BASE_DIR ${CMAKE_BINARY_DIR})
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)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
Expand All @@ -115,7 +112,7 @@ add_custom_target(gnc-vcs-info ALL
-D SHELL="${SHELL}"
-P ${CMAKE_SOURCE_DIR}/cmake/git2version-info.cmake
)
else()
else ()
add_custom_target(gnc-vcs-info DEPENDS ${VCS_INFO_FILE})
endif()
dist_add_generated (${BUILDING_FROM_VCS} gnc-vcs-info.h)
Expand Down

0 comments on commit 1acc3db

Please sign in to comment.