Skip to content

Commit ee5d78a

Browse files
committed
try auto generate android version
1 parent a7afc1d commit ee5d78a

File tree

4 files changed

+137
-17
lines changed

4 files changed

+137
-17
lines changed

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ if (UNIX AND NOT EMSCRIPTEN AND NOT ANDROID)
5656
if it's not installed, you'll get errors, that openmp or other stuff is not installed (hard to track down)" OFF)
5757
endif()
5858

59+
60+
include(cmake/alp_add_git_repository.cmake)
61+
include(cmake/Version.cmake)
62+
5963
########################################### setup #################################################
6064
set(CMAKE_CXX_STANDARD 20)
6165
set(CMAKE_AUTOMOC ON)
@@ -82,7 +86,6 @@ endif()
8286
find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL Network Quick QuickControls2 LinguistTools)
8387
qt_standard_project_setup(REQUIRES 6.8)
8488

85-
include(cmake/alp_add_git_repository.cmake)
8689
alp_add_git_repository(renderer_static_data URL https://github.com/AlpineMapsOrg/renderer_static_data.git COMMITISH v23.11 DO_NOT_ADD_SUBPROJECT)
8790
alp_add_git_repository(alpineapp_fonts URL https://github.com/AlpineMapsOrg/fonts.git COMMITISH v24.02 DO_NOT_ADD_SUBPROJECT)
8891
alp_add_git_repository(doc URL https://github.com/AlpineMapsOrg/documentation.git COMMITISH origin/main DO_NOT_ADD_SUBPROJECT DESTINATION_PATH doc)

app/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,16 @@ qt_add_translations(alpineapp TS_FILES
117117
i18n/en.ts
118118
)
119119

120+
alp_get_version(
121+
GIT_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
122+
VERSION_VAR "ALP_VERSION"
123+
VERSION_INT_VAR "ALP_VERSION_INTEGER"
124+
)
120125

121126
set_target_properties(alpineapp PROPERTIES
122127
QT_ANDROID_PACKAGE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/android
128+
QT_ANDROID_VERSION_NAME ${ALP_VERSION}
129+
QT_ANDROID_VERSION_CODE ${ALP_VERSION_INTEGER}
123130
)
124131
target_link_libraries(alpineapp PUBLIC gl_engine Qt::Quick Qt::QuickControls2)
125132

cmake/Version.cmake

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#############################################################################
2+
# Alpine Terrain Renderer
3+
# Copyright (C) 2023 Adam Celarek <family name at cg tuwien ac at>
4+
#
5+
# This program is free software: you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation, either version 3 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
#############################################################################
18+
19+
function(alp_get_version)
20+
# Usage:
21+
# alp_get_version(
22+
# GIT_DIR <path to git repo>
23+
# VERSION_VAR <name of var to hold the version string>
24+
# VERSION_INT_VAR <name of var to hold the commit count, optional>
25+
# )
26+
27+
cmake_parse_arguments(ALP "" "GIT_DIR;VERSION_VAR;VERSION_INT_VAR" "" ${ARGN})
28+
29+
if (NOT ALP_GIT_DIR)
30+
message(FATAL_ERROR "alp_get_version() requires GIT_DIR to be specified")
31+
endif()
32+
33+
if (NOT ALP_VERSION_VAR)
34+
message(FATAL_ERROR "alp_get_version() requires ALP_VERSION_VAR to be specified")
35+
endif()
36+
37+
find_package(Git 2.22 REQUIRED)
38+
39+
#--- Retrieve the version string (e.g. "v1.2.3-dirty") ---
40+
execute_process(
41+
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=-d --abbrev=1
42+
WORKING_DIRECTORY ${ALP_GIT_DIR}
43+
OUTPUT_STRIP_TRAILING_WHITESPACE
44+
OUTPUT_VARIABLE _local_version
45+
)
46+
47+
if (_local_version STREQUAL "")
48+
message(WARNING "Retrieving version string from git failed; using 'vUnknown'")
49+
set(_local_version "vUnknown")
50+
else()
51+
string(REPLACE "-g" "." _local_version ${_local_version})
52+
string(REPLACE "-" "." _local_version ${_local_version})
53+
endif()
54+
set(${ALP_VERSION_VAR} "${_local_version}" PARENT_SCOPE)
55+
56+
#--- Retrieve number of commits (rev-list HEAD --count) ---
57+
if (ALP_VERSION_INT_VAR)
58+
execute_process(
59+
COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
60+
WORKING_DIRECTORY ${ALP_GIT_DIR}
61+
OUTPUT_STRIP_TRAILING_WHITESPACE
62+
OUTPUT_VARIABLE _local_version_integer
63+
)
64+
65+
if (_local_version_integer STREQUAL "")
66+
message(WARNING "Retrieving number of commits from git failed; using '0'")
67+
set(_local_version_integer "0")
68+
endif()
69+
70+
set(${ALP_VERSION_INT_VAR} "${_local_version_integer}" PARENT_SCOPE)
71+
endif()
72+
endfunction()
73+
74+
75+
function(alp_generate_version_file)
76+
# Usage:
77+
# alp_generate_version_file(
78+
# GIT_DIR <path to git repo>
79+
# VERSION_TEMPLATE <path to .in template file>
80+
# VERSION_DESTINATION <destination file path to generate>
81+
# )
82+
83+
cmake_parse_arguments(ALP ""
84+
"GIT_DIR;VERSION_TEMPLATE;VERSION_DESTINATION"
85+
""
86+
${ARGN}
87+
)
88+
89+
if (NOT ALP_GIT_DIR)
90+
message(FATAL_ERROR "alp_generate_version_file() requires GIT_DIR")
91+
endif()
92+
if (NOT ALP_VERSION_TEMPLATE)
93+
message(FATAL_ERROR "alp_generate_version_file() requires VERSION_TEMPLATE")
94+
endif()
95+
if (NOT ALP_VERSION_DESTINATION)
96+
message(FATAL_ERROR "alp_generate_version_file() requires VERSION_DESTINATION")
97+
endif()
98+
99+
# Retrieve version info
100+
alp_get_version(
101+
GIT_DIR "${ALP_GIT_DIR}"
102+
VERSION_VAR "_version"
103+
)
104+
105+
# Because ALP_VERSION_VAR is a *name of a variable*, we use indirect expansion:
106+
set(ALP_VERSION "${_version}")
107+
108+
# Use configure_file() to generate your output
109+
configure_file(
110+
"${ALP_VERSION_TEMPLATE}"
111+
"${ALP_VERSION_DESTINATION}"
112+
@ONLY
113+
)
114+
endfunction()
115+

cmake/alp_generate_version_file.cmake

+11-16
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,17 @@
1616
# You should have received a copy of the GNU General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
#############################################################################
19-
20-
find_package(Git 2.22 REQUIRED)
2119

22-
get_filename_component(ALP_VERSION_TEMPLATE_DIR ${ALP_VERSION_TEMPLATE} DIRECTORY)
2320

24-
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty=-d --abbrev=1
25-
WORKING_DIRECTORY ${ALP_VERSION_TEMPLATE_DIR}
26-
OUTPUT_STRIP_TRAILING_WHITESPACE
27-
OUTPUT_VARIABLE ALP_VERSION)
28-
29-
if (ALP_VERSION STREQUAL "")
30-
message(WARNING "Retrieving version string from git was not successfull. Setting it to 'vUnknown'")
31-
set(ALP_VERSION "vUnknown")
32-
else()
33-
string(REPLACE "-g" "." ALP_VERSION ${ALP_VERSION})
34-
string(REPLACE "-" "." ALP_VERSION ${ALP_VERSION})
35-
endif()
21+
get_filename_component(CURRENT_SCRIPT_DIR "${CMAKE_CURRENT_LIST_FILE}" DIRECTORY)
22+
23+
include(${CURRENT_SCRIPT_DIR}/Version.cmake)
24+
25+
26+
get_filename_component(ALP_VERSION_TEMPLATE_DIR ${ALP_VERSION_TEMPLATE} DIRECTORY)
3627

37-
configure_file(${ALP_VERSION_TEMPLATE} ${ALP_VERSION_DESTINATION} @ONLY)
28+
alp_generate_version_file(
29+
GIT_DIR "${ALP_VERSION_TEMPLATE_DIR}"
30+
VERSION_TEMPLATE "${ALP_VERSION_TEMPLATE}"
31+
VERSION_DESTINATION "${ALP_VERSION_DESTINATION}"
32+
)

0 commit comments

Comments
 (0)