From 1cb6e413258d7f382447ff73e832101271d7f0b4 Mon Sep 17 00:00:00 2001 From: program-- Date: Thu, 22 Aug 2024 07:32:10 -0700 Subject: [PATCH] feat(cmake): include git commit id in configuration summary --- CMakeLists.txt | 6 +++++- cmake/GitUpdateSubmodules.cmake | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 22a3af6b41..f4756bdfd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}" diff --git a/cmake/GitUpdateSubmodules.cmake b/cmake/GitUpdateSubmodules.cmake index 366f325116..140d045499 100644 --- a/cmake/GitUpdateSubmodules.cmake +++ b/cmake/GitUpdateSubmodules.cmake @@ -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()