-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first version of info page * include hash of latest commit in info window * improved info window * git safe.directory --------- Co-authored-by: Jonas Otto <[email protected]>
- Loading branch information
Showing
7 changed files
with
245 additions
and
31 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
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,89 @@ | ||
# adapted from https://gitlab.com/jhamberg/cmake-examples/-/blob/master/cmake/CheckGit.cmake | ||
|
||
set(CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}) | ||
if (NOT DEFINED pre_configure_inc_dir) | ||
set(pre_configure_inc_dir ${CMAKE_SOURCE_DIR}/include) | ||
endif () | ||
|
||
if (NOT DEFINED pre_configure_dir) | ||
set(pre_configure_dir ${CMAKE_SOURCE_DIR}/src) | ||
endif () | ||
|
||
if (NOT DEFINED post_configure_dir) | ||
set(post_configure_dir ${CMAKE_BINARY_DIR}/generated) | ||
endif () | ||
|
||
set(pre_configure_file ${pre_configure_dir}/git_version.cpp.in) | ||
set(post_configure_file ${post_configure_dir}/git_version.cpp) | ||
|
||
function(CheckGitWrite git_hash) | ||
file(WRITE ${CMAKE_BINARY_DIR}/git-state.txt ${git_hash}) | ||
endfunction() | ||
|
||
function(CheckGitRead git_hash) | ||
if (EXISTS ${CMAKE_BINARY_DIR}/git-state.txt) | ||
file(STRINGS ${CMAKE_BINARY_DIR}/git-state.txt CONTENT) | ||
LIST(GET CONTENT 0 var) | ||
|
||
set(${git_hash} ${var} PARENT_SCOPE) | ||
endif () | ||
endfunction() | ||
|
||
function(CheckGitVersion) | ||
# 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 | ||
) | ||
|
||
CheckGitRead(GIT_HASH_CACHE) | ||
if (NOT EXISTS ${post_configure_dir}) | ||
file(MAKE_DIRECTORY ${post_configure_dir}) | ||
endif () | ||
|
||
if (NOT EXISTS ${post_configure_dir}/git_version.hpp) | ||
file(COPY ${pre_configure_inc_dir}/git_version.hpp DESTINATION ${post_configure_dir}) | ||
endif() | ||
|
||
if (NOT DEFINED GIT_HASH_CACHE) | ||
set(GIT_HASH_CACHE "INVALID") | ||
endif () | ||
|
||
# Only update the git_version.cpp if the hash has changed. This will | ||
# prevent us from rebuilding the project more than we need to. | ||
if (NOT ${GIT_HASH} STREQUAL ${GIT_HASH_CACHE} OR NOT EXISTS ${post_configure_file}) | ||
# Set che GIT_HASH_CACHE variable the next build won't have | ||
# to regenerate the source file. | ||
CheckGitWrite(${GIT_HASH}) | ||
|
||
configure_file(${pre_configure_file} ${post_configure_file} @ONLY) | ||
endif () | ||
|
||
endfunction() | ||
|
||
function(CheckGitSetup) | ||
|
||
add_custom_target(AlwaysCheckGit COMMAND ${CMAKE_COMMAND} | ||
-DRUN_CHECK_GIT_VERSION=1 | ||
-Dpre_configure_inc_dir=${pre_configure_inc_dir} | ||
-Dpre_configure_dir=${pre_configure_dir} | ||
-Dpost_configure_file=${post_configure_dir} | ||
-DGIT_HASH_CACHE=${GIT_HASH_CACHE} | ||
-P ${CURRENT_LIST_DIR}/CheckGit.cmake | ||
BYPRODUCTS ${post_configure_file} | ||
) | ||
|
||
add_library(git_version ${CMAKE_BINARY_DIR}/generated/git_version.cpp) | ||
target_include_directories(git_version PUBLIC ${CMAKE_BINARY_DIR}/generated) | ||
add_dependencies(git_version AlwaysCheckGit) | ||
|
||
CheckGitVersion() | ||
endfunction() | ||
|
||
# This is used to run this function from an external cmake process. | ||
if (RUN_CHECK_GIT_VERSION) | ||
CheckGitVersion() | ||
endif () | ||
|
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,15 @@ | ||
/** | ||
* @file git_version.hpp | ||
* @author Dominik Authaler | ||
* @date 12.08.2023 | ||
* | ||
* Utility file for including the hash of the latest commit within the executable. | ||
* Based on https://jonathanhamberg.com/post/cmake-embedding-git-hash/. | ||
*/ | ||
|
||
#ifndef RIG_RECONFIGURE_GIT_VERSION_HPP | ||
#define RIG_RECONFIGURE_GIT_VERSION_HPP | ||
|
||
extern const char *gitHash; | ||
|
||
#endif //RIG_RECONFIGURE_GIT_VERSION_HPP |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,15 @@ | ||
/** | ||
* @file git_version.cpp.in | ||
* @author Dominik Authaler | ||
* @date 12.08.2023 | ||
* | ||
* Utility file for including the hash of the latest commit within the executable. | ||
* Based on https://jonathanhamberg.com/post/cmake-embedding-git-hash/. | ||
* | ||
* Note that this file is preprocessed by cmake before being forwarded to the compiler (this allows replacing | ||
* the variable placeholder with the corresponding commit hash). | ||
*/ | ||
|
||
#include "git_version.hpp" | ||
|
||
const char *gitHash = "@GIT_HASH@"; |
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