Skip to content

Commit

Permalink
feat(cmake): include git commit id in configuration summary
Browse files Browse the repository at this point in the history
  • Loading branch information
program-- authored and PhilMiller committed Aug 22, 2024
1 parent 2ffedf8 commit 1cb6e41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ list(APPEND CMAKE_MODULE_PATH "${NGEN_MOD_DIR}")
# (1) finds Git package
# (2) Sets ${NGEN_HAS_GIT_DIR} to ON/OFF if ${NGEN_ROOT_DIR}/.git exists
# (3) Function `git_update_submodule` which updates a given submodule
# (4) Sets ${NGEN_GIT_COMMIT} to the current commit hash if available
include(GitUpdateSubmodules)

# NGen CMake module for automating external subdirectory builds (i.e. testbmicpp)
Expand Down Expand Up @@ -406,7 +407,10 @@ ngen_multiline_message(
" C Compiler: ${CMAKE_C_COMPILER}"
" C Flags: ${CMAKE_C_FLAGS}"
" CXX Compiler: ${CMAKE_CXX_COMPILER}"
" CXX Flags: ${CMAKE_CXX_FLAGS}"
" CXX Flags: ${CMAKE_CXX_FLAGS}")
ngen_dependent_multiline_message(NGEN_HAS_GIT_DIR
" Git Commit ID: ${NGEN_GIT_COMMIT}")
ngen_multiline_message(
" Flags:"
" NGEN_WITH_MPI: ${NGEN_WITH_MPI}"
" NGEN_WITH_NETCDF: ${NGEN_WITH_NETCDF}"
Expand Down
7 changes: 7 additions & 0 deletions cmake/GitUpdateSubmodules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ find_package(Git QUIET)

if(EXISTS "${NGEN_ROOT_DIR}/.git")
set(NGEN_HAS_GIT_DIR ON)

execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
WORKING_DIRECTORY ${NGEN_ROOT_DIR}
OUTPUT_VARIABLE NGEN_GIT_COMMIT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else()
set(NGEN_HAS_GIT_DIR OFF)
endif()
Expand Down

0 comments on commit 1cb6e41

Please sign in to comment.