Skip to content

Commit 377098f

Browse files
Get version string from git-describe, git-archive or CMake config
1 parent bc7debe commit 377098f

File tree

16 files changed

+69
-50
lines changed

16 files changed

+69
-50
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
debian/ export-ignore
22
.gitattributes export-ignore
3+
icinga-archive-version.cmake export-subst

.github/ISSUE_TEMPLATE/release.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ assignees: ''
99

1010
# Release Workflow
1111

12-
- [ ] Update `ICINGA2_VERSION`
12+
- [ ] Update `ICINGA2_VERSION` in main CMakeLists.txt
1313
- [ ] Update bundled Windows dependencies
1414
- [ ] Harden global TLS defaults (consult https://ssl-config.mozilla.org)
1515
- [ ] Update `CHANGELOG.md`

CMakeLists.txt

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
cmake_minimum_required(VERSION 3.17...3.17)
55
set(BOOST_MIN_VERSION "1.66.0")
66

7+
set(ICINGA2_VERSION "2.15.0")
8+
79
set(CMAKE_CXX_STANDARD 17)
810
set(CMAKE_CXX_STANDARD_REQUIRED ON)
911
set(CMAKE_CXX_EXTENSIONS OFF)
@@ -54,6 +56,11 @@ set(ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe")
5456
set(ICINGA2_UNITY_BUILD ON CACHE BOOL "Whether to perform a unity build")
5557
set(ICINGA2_LTO_BUILD OFF CACHE BOOL "Whether to use LTO")
5658

59+
option(ICINGA2_INCLUDE_PACKAGE_INFO "Include package version in 'icinga2 --version'" OFF)
60+
set(ICINGA2_PACKAGE_VERSION ${ICINGA2_VERSION} CACHE STRING "Version used when packaging Icinga 2")
61+
set(ICINGA2_PACKAGE_REVISION "1" CACHE STRING "Revision used when packaging Icinga 2")
62+
set(ICINGA2_PACKAGE_VENDOR "Icinga GmbH" CACHE STRING "Vendor string used when packaging Icinga 2")
63+
5764
set(ICINGA2_CONFIGDIR "${CMAKE_INSTALL_SYSCONFDIR}/icinga2" CACHE FILEPATH "Main config directory, e.g. /etc/icinga2")
5865
set(ICINGA2_CACHEDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/cache/icinga2" CACHE FILEPATH "Directory for cache files, e.g. /var/cache/icinga2")
5966
set(ICINGA2_DATADIR "${CMAKE_INSTALL_LOCALSTATEDIR}/lib/icinga2" CACHE FILEPATH "Data directory for the daemon, e.g. /var/lib/icinga2")
@@ -97,35 +104,20 @@ file(READ "${CMAKE_CURRENT_SOURCE_DIR}/COPYING" ICINGA2_LICENSE_GPL)
97104
set(ICINGA2_LICENSE "${ICINGA2_LICENSE_GPL}\n\n---\n\n${ICINGA2_LICENSE_ADDITIONS}")
98105
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" ${ICINGA2_LICENSE})
99106

100-
file(STRINGS ICINGA2_VERSION SPEC_VERSION REGEX "^Version:")
101-
string(LENGTH "${SPEC_VERSION}" SPEC_VERSION_LENGTH)
102-
math(EXPR SPEC_VERSION_LENGTH "${SPEC_VERSION_LENGTH} - 9")
103-
string(SUBSTRING ${SPEC_VERSION} 9 ${SPEC_VERSION_LENGTH} SPEC_VERSION)
104-
105-
configure_file(icinga-spec-version.h.cmake icinga-spec-version.h)
106-
107107
include(GetGitRevisionDescription)
108-
git_describe(GIT_VERSION --tags)
109-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/icinga-version.h.force)
110-
configure_file(icinga-version.h.force ${CMAKE_CURRENT_BINARY_DIR}/icinga-version.h COPYONLY)
111-
else()
112-
if(NOT ICINGA2_GIT_VERSION_INFO OR GIT_VERSION MATCHES "-NOTFOUND$")
113-
file(STRINGS ICINGA2_VERSION SPEC_REVISION REGEX "^Revision: ")
114-
string(LENGTH "${SPEC_REVISION}" SPEC_REVISION_LENGTH)
115-
math(EXPR SPEC_REVISION_LENGTH "${SPEC_REVISION_LENGTH} - 10")
116-
string(SUBSTRING ${SPEC_REVISION} 10 ${SPEC_REVISION_LENGTH} SPEC_REVISION)
117-
118-
set(GIT_VERSION "r${SPEC_VERSION}-${SPEC_REVISION}")
119-
set(ICINGA2_VERSION "${SPEC_VERSION}")
120-
else()
121-
# use GIT version as ICINGA2_VERSION
122-
string(REGEX REPLACE "^[rv]" "" ICINGA2_VERSION "${GIT_VERSION}")
108+
git_describe(ICINGA2_VERSION)
109+
if(NOT ICINGA2_GIT_VERSION_INFO OR ICINGA2_VERSION MATCHES "-NOTFOUND$")
110+
include(icinga-archive-version.cmake)
111+
if(ICINGA2_VERSION MATCHES "^\\$.*")
112+
set(ICINGA2_VERSION "v${ICINGA2_PACKAGE_VERSION}-${ICINGA2_PACKAGE_REVISION}")
123113
endif()
124-
configure_file(icinga-version.h.cmake icinga-version.h)
125114
endif()
126115

116+
# We need a version string that doesn't contain the leading 'v' for the icinga.rc file
117+
string(REGEX REPLACE "^[rv]" "" ICINGA2_RC_VERSION "${ICINGA2_VERSION}")
118+
127119
# NuGet on Windows requires a semantic versioning, example: 2.10.4.123 (only 4 element, only numeric)
128-
string(REGEX REPLACE "-([0-9]+).*$" ".\\1" ICINGA2_VERSION_SAFE "${ICINGA2_VERSION}")
120+
string(REGEX REPLACE "-([0-9]+).*$" ".\\1" ICINGA2_VERSION_SAFE "${ICINGA2_RC_VERSION}")
129121
string(REGEX REPLACE "-[^\\.]*(.*)$" "\\1" ICINGA2_VERSION_SAFE "${ICINGA2_VERSION_SAFE}")
130122
string(REGEX REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+)[\\.]?[0-9]*" "\\1" CHOCO_VERSION_SHORT "${ICINGA2_VERSION_SAFE}")
131123

@@ -496,7 +488,7 @@ if(BUILD_TESTING)
496488
endif()
497489

498490
set(CPACK_PACKAGE_NAME "Icinga 2")
499-
set(CPACK_PACKAGE_VENDOR "Icinga GmbH")
491+
set(CPACK_PACKAGE_VENDOR ${ICINGA2_PACKAGE_VENDOR})
500492
set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION_SAFE})
501493
set(CPACK_PACKAGE_INSTALL_DIRECTORY "ICINGA2")
502494
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")

ICINGA2_VERSION

Lines changed: 0 additions & 2 deletions
This file was deleted.

config.h.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
#define ICINGA_BUILD_COMPILER_NAME "${ICINGA2_BUILD_COMPILER_NAME}"
2929
#define ICINGA_BUILD_COMPILER_VERSION "${ICINGA2_BUILD_COMPILER_VERSION}"
3030

31+
#define ICINGA_VERSION "${ICINGA2_VERSION}"
32+
#define ICINGA_RC_VERSION "${ICINGA2_RC_VERSION}"
33+
#cmakedefine01 ICINGA2_INCLUDE_PACKAGE_INFO
34+
#define ICINGA_PACKAGE_VERSION "${ICINGA2_PACKAGE_VERSION}"
35+
#define ICINGA_PACKAGE_REVISION "${ICINGA2_PACKAGE_REVISION}"
36+
#define ICINGA_PACKAGE_VENDOR "${ICINGA2_PACKAGE_VENDOR}"
37+
3138
// Deprecated options?
3239
#define ICINGA_PKGDATADIR "${ICINGA2_FULL_PKGDATADIR}"
3340
#define ICINGA_PREFIX "${CMAKE_INSTALL_PREFIX}"

doc/21-development.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,12 +2391,11 @@ for implementation details.
23912391

23922392
#### Version detection
23932393

2394-
CMake determines the Icinga 2 version number using `git describe` if the
2395-
source directory is contained in a Git repository. Otherwise the version number
2396-
is extracted from the `ICINGA2_VERSION` file. This behavior can be
2397-
overridden by creating a file called `icinga-version.h.force` in the source
2398-
directory. Alternatively the `-DICINGA2_GIT_VERSION_INFO=OFF` option for CMake
2399-
can be used to disable the usage of `git describe`.
2394+
CMake determines the Icinga 2 version number using `git describe` if the source directory is contained
2395+
in a Git repository or if the source directory has been extracted from an archive built with `git-archive`.
2396+
Otherwise the version number is specified in the `ICINGA2_VERSION` variable in the main `CMakeLists.txt`
2397+
file. The `-DICINGA2_GIT_VERSION_INFO=OFF` option for CMake can be used to disable the usage of
2398+
`git describe`.
24002399

24012400

24022401
### Building RPMs <a id="development-package-builds-rpms"></a>

icinga-app/icinga.rc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <windows.h>
2-
#include "icinga-version.h"
2+
#include "config.h"
33

44
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
55

@@ -18,12 +18,12 @@ BEGIN
1818
BEGIN
1919
VALUE "CompanyName", "Icinga GmbH"
2020
VALUE "FileDescription", "Icinga 2"
21-
VALUE "FileVersion", ICINGA2_VERSION
21+
VALUE "FileVersion", ICINGA_RC_VERSION
2222
VALUE "InternalName", "icinga2.exe"
2323
VALUE "LegalCopyright", "� Icinga GmbH"
2424
VALUE "OriginalFilename", "icinga2.exe"
2525
VALUE "ProductName", "Icinga 2"
26-
VALUE "ProductVersion", ICINGA2_VERSION
26+
VALUE "ProductVersion", ICINGA_RC_VERSION
2727
END
2828
END
2929

icinga-archive-version.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
set(ICINGA2_VERSION "$Format:%(describe)$")

icinga-spec-version.h.cmake

Lines changed: 0 additions & 1 deletion
This file was deleted.

icinga-version.h.cmake

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)