-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom build step for generating version header
Generate a version header including git revision and dirty flag; print version upon runtime startup. Co-authored-by: Fabian Knorr <fabian.knorr@dps.uibk.ac.at>
- Loading branch information
Showing
6 changed files
with
79 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Split version string into components | ||
string(REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" _ ${CELERITY_VERSION}) | ||
set(CELERITY_VERSION_MAJOR ${CMAKE_MATCH_1}) | ||
set(CELERITY_VERSION_MINOR ${CMAKE_MATCH_2}) | ||
set(CELERITY_VERSION_PATCH ${CMAKE_MATCH_3}) | ||
|
||
message(VERBOSE "Celerity version is ${CELERITY_VERSION_MAJOR}.${CELERITY_VERSION_MINOR}.${CELERITY_VERSION_PATCH}") | ||
|
||
# Attempt to obtain git revision / dirty status | ||
set(CELERITY_VERSION_GIT_REVISION "unknown") | ||
set(CELERITY_VERSION_GIT_IS_DIRTY 0) | ||
|
||
find_package(Git QUIET) | ||
if(GIT_FOUND) | ||
execute_process( | ||
COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD | ||
WORKING_DIRECTORY "${CELERITY_SOURCE_DIR}" | ||
RESULT_VARIABLE EXIT_CODE | ||
OUTPUT_VARIABLE GIT_REVISION | ||
ERROR_QUIET | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
if(EXIT_CODE EQUAL 0) | ||
set(CELERITY_VERSION_GIT_REVISION ${GIT_REVISION}) | ||
execute_process( | ||
COMMAND "${GIT_EXECUTABLE}" diff --quiet HEAD | ||
WORKING_DIRECTORY "${CELERITY_SOURCE_DIR}" | ||
RESULT_VARIABLE CELERITY_VERSION_GIT_IS_DIRTY | ||
ERROR_QUIET | ||
) | ||
endif() | ||
endif() | ||
|
||
# Simply write resulting header (which is git-ignored) into include directory. | ||
# This way we don't need to do any additional work | ||
# for setting up include paths, during installation etc. | ||
configure_file("${CMAKE_CURRENT_LIST_DIR}/version.h.in" | ||
"${CELERITY_SOURCE_DIR}/include/version.h" | ||
@ONLY | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
// clang-format off | ||
#define CELERITY_VERSION_MAJOR @CELERITY_VERSION_MAJOR@ | ||
#define CELERITY_VERSION_MINOR @CELERITY_VERSION_MINOR@ | ||
#define CELERITY_VERSION_PATCH @CELERITY_VERSION_PATCH@ | ||
|
||
#define CELERITY_VERSION_GIT_REVISION "@CELERITY_VERSION_GIT_REVISION@" | ||
#define CELERITY_VERSION_GIT_IS_DIRTY @CELERITY_VERSION_GIT_IS_DIRTY@ | ||
// clang-format on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters