mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-08-24 22:21:43 +02:00
add GIT_HASH and TREXIO_USER_NAME variables to CMake
This commit is contained in:
parent
4afd9cf2c1
commit
5db1de3d3c
@ -32,6 +32,22 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/.git/config")
|
||||
else()
|
||||
message(FATAL_ERROR "EMACS not found. It is required to produce TREXIO source code from org-mode files.")
|
||||
endif()
|
||||
# in case Git is not available, we default to "unknown"
|
||||
set(GIT_HASH "unknown")
|
||||
# find Git and if available set GIT_HASH variable
|
||||
find_package(Git QUIET)
|
||||
if(GIT_FOUND)
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} --no-pager show -s --pretty=format:%H -n 1
|
||||
OUTPUT_VARIABLE GIT_HASH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
ERROR_QUIET)
|
||||
endif()
|
||||
# get the user name from the ${USER} env variable
|
||||
set(TREXIO_USER_NAME $ENV{USER})
|
||||
# replace placeholders in the templace config.h.in file to produce config.h
|
||||
# config.h is needed to insert TREXIO_PACKAGE_VERSION and TREXIO_GIT_HASH into trexio.h
|
||||
configure_file(${CMAKE_SOURCE_DIR}/include/cmake_config.h.in
|
||||
${CMAKE_SOURCE_DIR}/include/config.h)
|
||||
endif()
|
||||
|
@ -3,3 +3,5 @@
|
||||
#define VERSION_MAJOR @PROJECT_VERSION_MAJOR@
|
||||
#define VERSION_MINOR @PROJECT_VERSION_MINOR@
|
||||
#define VERSION_PATCH @PROJECT_VERSION_PATCH@
|
||||
#define GIT_HASH "@GIT_HASH@"
|
||||
#define TREXIO_USER_NAME "@TREXIO_USER_NAME@"
|
||||
|
Loading…
Reference in New Issue
Block a user