diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dca6aaaaf..2397c42eb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,6 +9,16 @@ file(GLOB sources_Fortran ${src_home}/*.F90) #list(REMOVE_ITEM sources_Fortran ${src_home}/fesom_partition_init.F90) file(GLOB sources_C ${src_home}/*.c) +# generate a custom file from fesom_version_info.F90 which includes the current git SHA +set(FESOM_ORIGINAL_VERSION_FILE ${src_home}/fesom_version_info.F90) +set(FESOM_GENERATED_VERSION_FILE ${CMAKE_CURRENT_BINARY_DIR}/fesom_version_info-generated.F90) +list(REMOVE_ITEM sources_Fortran ${FESOM_ORIGINAL_VERSION_FILE}) # we want to compile the generated file instead +list(APPEND sources_Fortran ${FESOM_GENERATED_VERSION_FILE}) +add_custom_command(OUTPUT ${FESOM_GENERATED_VERSION_FILE} 5303B6F4_E4F4_45B2_A6E5_8E2B9FB5CDC4 # the second arg to OUTPUT is a name for a file we never create to make sure this command will run on every re-build + COMMAND ${CMAKE_COMMAND} -DFESOM_ORIGINAL_VERSION_FILE=${FESOM_ORIGINAL_VERSION_FILE} -DFESOM_GENERATED_VERSION_FILE=${FESOM_GENERATED_VERSION_FILE} -P GitRepositoryInfo.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + COMMENT "determining ${PROJECT_NAME} git SHA ...") + #if(${FESOM_STANDALONE}) # list(REMOVE_ITEM sources_Fortran ${src_home}/cpl_driver.F90) #endif() diff --git a/src/GitRepositoryInfo.cmake b/src/GitRepositoryInfo.cmake new file mode 100644 index 000000000..e5eb37c26 --- /dev/null +++ b/src/GitRepositoryInfo.cmake @@ -0,0 +1,12 @@ +find_package(Git QUIET) +if(Git_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + OUTPUT_VARIABLE FESOM_GIT_SHA + OUTPUT_STRIP_TRAILING_WHITESPACE) +else() + set(FESOM_GIT_SHA "unknown") + message("git not found, setting FESOM_GIT_SHA to: ${FESOM_GIT_SHA}") +endif() + +configure_file(${FESOM_ORIGINAL_VERSION_FILE} ${FESOM_GENERATED_VERSION_FILE} @ONLY) diff --git a/src/fesom_version_info.F90 b/src/fesom_version_info.F90 new file mode 100644 index 000000000..5fe688b5a --- /dev/null +++ b/src/fesom_version_info.F90 @@ -0,0 +1,14 @@ +module fesom_version_info_module + private + public fesom_git_sha + +contains + + + pure function fesom_git_sha() result(x) + character(:), allocatable :: x + ! EO args + x = "@FESOM_GIT_SHA@" + end function + +end module diff --git a/src/fvom_main.F90 b/src/fvom_main.F90 index a02a8fe68..42050c90d 100755 --- a/src/fvom_main.F90 +++ b/src/fvom_main.F90 @@ -22,6 +22,7 @@ program main use io_mesh_info use diagnostics use mo_tidal +use fesom_version_info_module #if defined (__oasis) use cpl_driver #endif @@ -53,6 +54,7 @@ program main call par_init if(mype==0) then write(*,*) + print *,"FESOM2 git SHA: "//fesom_git_sha() print *, achar(27)//'[32m' //'____________________________________________________________'//achar(27)//'[0m' print *, achar(27)//'[7;32m'//' --> FESOM BUILDS UP MODEL CONFIGURATION '//achar(27)//'[0m' end if