-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from flightaware/BCK-5541
Embed git hash/branch info in cpptcl libs
- Loading branch information
Showing
3 changed files
with
77 additions
and
2 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,51 @@ | ||
function (load_git_properties prefix output_dir) | ||
|
||
# Load the current working branch | ||
execute_process( | ||
COMMAND git symbolic-ref -q --short HEAD | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} | ||
OUTPUT_VARIABLE GIT_BRANCH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
if (GIT_BRANCH STREQUAL "") | ||
execute_process( | ||
COMMAND git describe --tags --exact-match | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} | ||
OUTPUT_VARIABLE GIT_BRANCH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
endif () | ||
|
||
# Get the latest abbreviated commit hash of the working branch | ||
execute_process( | ||
COMMAND git log -1 --format=%h | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} | ||
OUTPUT_VARIABLE GIT_HASH | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
|
||
if ("${GIT_BRANCH}" STREQUAL "") | ||
set(GIT_BRANCH "N/A") | ||
endif () | ||
|
||
if ("${GIT_HASH}" STREQUAL "") | ||
set(GIT_HASH "N/A") | ||
endif () | ||
|
||
string(TOUPPER "${prefix}" var_prefix) | ||
string(CONCAT VERSION_DATA "const char* ${var_prefix}_GIT_HASH = \"${GIT_HASH}\";\n" | ||
"const char* ${var_prefix}_GIT_BRANCH = \"${GIT_BRANCH}\";\n" | ||
) | ||
|
||
if (EXISTS ${output_dir}/${prefix}_version.cpp) | ||
file(READ ${output_dir}/${prefix}_version.cpp VERSION_DATA_) | ||
else () | ||
set(VERSION_DATA_ "") | ||
endif () | ||
|
||
if (NOT "${VERSION_DATA}" STREQUAL "${VERSION_DATA_}") | ||
file(WRITE ${output_dir}/${prefix}_version.cpp "${VERSION_DATA}") | ||
endif () | ||
|
||
endfunction () |
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,19 @@ | ||
#ifndef CPPTCL_VERSION_H | ||
#define CPPTCL_VERSION_H | ||
|
||
// Variables are autogenerated and compiled | ||
// into the library by cmake | ||
extern "C" { | ||
extern const char* CPPTCL_GIT_HASH; | ||
extern const char* CPPTCL_GIT_BRANCH; | ||
} | ||
|
||
const char* cpptcl_git_hash() { | ||
return CPPTCL_GIT_HASH; | ||
} | ||
|
||
const char* cpptcl_git_branch() { | ||
return CPPTCL_GIT_BRANCH; | ||
} | ||
|
||
#endif //CPPTCL_VERSION_H |