Skip to content

Commit bd6e79b

Browse files
committed
Rework version-info rules to allow building from github downloaded zip archives
1 parent 3f8b97b commit bd6e79b

File tree

5 files changed

+73
-34
lines changed

5 files changed

+73
-34
lines changed

CMakeLists.txt

+13-4
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,23 @@ if (GNC_VCS_INFO_RESULT EQUAL 0)
154154
if (NOT GIT_FOUND)
155155
message(SEND_ERROR "Looks like we're building from version control, but can't find git executable. Please install git or set GIT_EXECUTABLE.")
156156
endif()
157+
endif()
158+
159+
# Determine whether or not we have to generate a gnc-vcs-info.h file
160+
# Distribution tarballs have this file in the source tree
161+
# Git checkouts or zipfiles downloaded straight from github won't have it
162+
# and require us to build it.
163+
if (BUILDING_FROM_VCS OR NOT EXISTS "${CMAKE_SOURCE_DIR}/libgnucash/core-utilsgnc-vcs-info.h")
157164
set(VCS_INFO_BASE_DIR ${CMAKE_BINARY_DIR})
165+
set(GENERATE_VCS_INFO "Yes")
158166
else()
159167
set(VCS_INFO_BASE_DIR ${CMAKE_SOURCE_DIR})
168+
set(GENERATE_VCS_INFO "No")
160169
endif()
161-
# The location of gnc-vcs-info.h depends on whether we build from VCS or not
162-
# And this file is needed in several other build rules, so we define its
163-
# location once here.
164-
set(VCS_INFO_FILE ${VCS_INFO_BASE_DIR}/libgnucash/core-utils/gnc-vcs-info.h)
170+
# As the file's path is needed by several other build rules, we already define
171+
# that here. The actual build rules (if needed) are in libgnucash/core-utils.
172+
set(VCS_INFO_FILE ${VCS_INFO_BASE_DIR}/libgnucash/core-utils/gnc-vcs-info.h CACHE STRING "path to gnc-vcs-info.h file")
173+
165174

166175
if (WIN32)
167176
# Help Windows find the various dependencies. We assume here that the standard advice for building

cmake/CMakeLists.txt

+11-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ if (APPLE)
88
endif()
99

1010

11-
set_dist_list(cmake_DIST CMakeLists.txt README_CMAKE.txt cmake_uninstall.cmake.in
12-
configure-appdata.cmake configure-gnucash-desktop.cmake configure-manpage.cmake
13-
configure-totd.cmake git2version-info.cmake version-info2env.cmake
11+
set_dist_list(cmake_DIST
12+
CMakeLists.txt
13+
README_CMAKE.txt
14+
cmake_uninstall.cmake.in
15+
configure-appdata.cmake
16+
configure-gnucash-desktop.cmake
17+
configure-manpage.cmake
18+
configure-totd.cmake
19+
git2version-info.cmake
20+
no-vcs2version-info.cmake
21+
version-info2env.cmake
1422
)

cmake/no-vcs2version-info.cmake

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Create the gnc-vcs-info.h file starting from a source directory that's
2+
# - not a git working directory
3+
# - not extracted from a distribution tarball
4+
# It currently sets four parameters
5+
# - GNC_VCS_REV
6+
# - GNC_VCS_REV_DATE
7+
# - GNC_VCS_REV_YEAR
8+
# - GNC_VCS_REV_Y_M
9+
# The following environment variables are used and should be properly set
10+
# by the calling code:
11+
# - PROJECT_VERSION
12+
# - SRC (full path to gnc-vcs-info.h.in)
13+
# - DST (full path to destination for gnc-vcs-info.h)
14+
15+
set (GNC_VCS_REV "${PROJECT_VERSION}-unknown-commit")
16+
string (TIMESTAMP GNC_VCS_REV_DATE "%Y-%m-%d")
17+
string(SUBSTRING ${GNC_VCS_REV_DATE} 0 4 GNC_VCS_REV_YEAR)
18+
string(SUBSTRING ${GNC_VCS_REV_DATE} 0 7 GNC_VCS_REV_Y_M)
19+
configure_file(${SRC} ${DST} @ONLY)

gnucash/gnome/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ install(TARGETS gnc-gnome
175175
# No headers to install
176176

177177
set (GNC_APPDATA_IN ${CMAKE_CURRENT_BINARY_DIR}/gnucash.appdata.xml.in)
178-
if (NOT BUILDING_FROM_VCS)
178+
if (NOT GENERATE_VCS_INFO)
179179
# We're building from a dist tarball.
180180
# As a convenience to packagers we have included a pretranslated
181181
# intermediate appdata file in the dist tarball.
@@ -255,7 +255,7 @@ set_local_dist(gnome_DIST_local
255255
CMakeLists.txt gnome.i gnucash.appdata.xml.in.in gnucash.desktop.in.in
256256
gnucash.releases.xml ${gnc_gnome_noinst_HEADERS} ${gnc_gnome_SOURCES} ${gnome_SCHEME})
257257

258-
dist_add_generated(${BUILDING_FROM_VCS} gnucash.appdata.xml.in)
258+
dist_add_generated(${GENERATE_VCS_INFO} gnucash.appdata.xml.in)
259259
add_dependencies(gnucash-appdata dist-gnucash-gnome-gnucash-appdata-xml-in)
260260

261261
set(gnome_DIST ${gnome_DIST_local} ${test_gnome_DIST} PARENT_SCOPE)

libgnucash/core-utils/CMakeLists.txt

+28-25
Original file line numberDiff line numberDiff line change
@@ -87,38 +87,41 @@ set(localedir "${CMAKE_INSTALL_FULL_DATAROOTDIR}/locale")
8787
configure_file(gncla-dir.h.in gncla-dir.h)
8888

8989

90-
### Create gnc-vcs-info.h
91-
# This can only be done when building from a vcs (git/svn/bzr/svk) working directory.
92-
# This file is shipped in the distribution tarball, so no need to generate it in that case anyway.
93-
# The meta-cmake gymnastics here come from https://cmake.org/pipermail/cmake/2010-July/038015.html
94-
if (BUILDING_FROM_VCS)
95-
set(VCS_INFO_BASE_DIR ${CMAKE_BINARY_DIR})
96-
else()
97-
set(VCS_INFO_BASE_DIR ${CMAKE_SOURCE_DIR})
98-
endif()
99-
set(VCS_INFO_FILE ${VCS_INFO_BASE_DIR}/libgnucash/core-utils/gnc-vcs-info.h CACHE STRING "path to gnc-vcs-info.h file")
100-
101-
if (BUILDING_FROM_VCS)
102-
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
90+
### Build rules for gnc-vcs-info.h
91+
# When building from a distribution tarball simply use the one
92+
# found in the source tree.
93+
# When building from a git working directory extract the neede information from git.
94+
# Otherwise work from the PROJECT_VERSION variable and today's date, but annotate
95+
# the version info to indicate it's inaccurate.
96+
97+
if (GENERATE_VCS_INFO)
98+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
10399
"/* Autogenerated. Do not change. */
104100
#define GNC_VCS_REV \"@GNC_VCS_REV@\"
105101
#define GNC_VCS_REV_DATE \"@GNC_VCS_REV_DATE@\"
106102
#define GNC_VCS_REV_YEAR \"@GNC_VCS_REV_YEAR@\"
107-
#define GNC_VCS_REV_Y_M \"@GNC_VCS_REV_Y_M@\"
108-
")
109-
110-
add_custom_target(gnc-vcs-info ALL
111-
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
112-
COMMAND ${CMAKE_COMMAND} -D SRC=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
113-
-D DST=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
114-
-D SRC_DIR=${CMAKE_SOURCE_DIR}
115-
-D SHELL="${SHELL}"
116-
-P ${CMAKE_SOURCE_DIR}/cmake/git2version-info.cmake
117-
)
103+
#define GNC_VCS_REV_Y_M \"@GNC_VCS_REV_Y_M@\"")
104+
105+
if (BUILDING_FROM_VCS)
106+
add_custom_target(gnc-vcs-info ALL
107+
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
108+
COMMAND ${CMAKE_COMMAND} -D SRC=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
109+
-D DST=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
110+
-D SRC_DIR=${CMAKE_SOURCE_DIR}
111+
-D SHELL="${SHELL}"
112+
-P ${CMAKE_SOURCE_DIR}/cmake/git2version-info.cmake)
113+
else()
114+
add_custom_target(gnc-vcs-info ALL
115+
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
116+
COMMAND ${CMAKE_COMMAND} -D SRC=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h.in
117+
-D DST=${CMAKE_CURRENT_BINARY_DIR}/gnc-vcs-info.h
118+
-D PROJECT_VERSION=${PROJECT_VERSION}
119+
-P ${CMAKE_SOURCE_DIR}/cmake/no-vcs2version-info.cmake)
120+
endif()
118121
else()
119122
add_custom_target(gnc-vcs-info DEPENDS ${VCS_INFO_FILE})
120123
endif()
121-
dist_add_generated (${BUILDING_FROM_VCS} gnc-vcs-info.h)
124+
dist_add_generated (${GENERATE_VCS_INFO} gnc-vcs-info.h)
122125

123126
# Dist files
124127
set_local_dist(core_utils_DIST_local

0 commit comments

Comments
 (0)