Generate a C file with git revision string
Former-commit-id: b70cf214ee64d245cbb6b2337b1a4d4e922429c9
This commit is contained in:
parent
88350eea0a
commit
8e8de07760
|
@ -1,7 +1,11 @@
|
||||||
cmake_minimum_required(VERSION 3.0.2)
|
cmake_minimum_required(VERSION 3.0.2)
|
||||||
include(CMakeAddFortranSubdirectory)
|
include(CMakeAddFortranSubdirectory)
|
||||||
|
include(version.cmake)
|
||||||
|
|
||||||
project (QPMS)
|
project (QPMS)
|
||||||
|
|
||||||
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
|
|
||||||
macro(use_c99)
|
macro(use_c99)
|
||||||
if (CMAKE_VERSION VERSION_LESS "3.1")
|
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
|
||||||
|
@ -24,4 +28,4 @@ cmake_add_fortran_subdirectory (amos
|
||||||
LIBRARIES amos
|
LIBRARIES amos
|
||||||
NO_EXTERNAL_INSTALL)
|
NO_EXTERNAL_INSTALL)
|
||||||
add_subdirectory (qpms)
|
add_subdirectory (qpms)
|
||||||
|
#add_subdirectory (apps/transop-ewald)
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
# based on https://www.mattkeeter.com/blog/2018-01-06-versioning/
|
||||||
|
|
||||||
|
execute_process(COMMAND git describe --tags --dirty --always
|
||||||
|
OUTPUT_VARIABLE GIT_REV
|
||||||
|
ERROR_QUIET)
|
||||||
|
|
||||||
|
# Check whether we got any revision (which isn't
|
||||||
|
# always the case, e.g. when someone downloaded a zip
|
||||||
|
# file from Github instead of a checkout)
|
||||||
|
if ("${GIT_REV}" STREQUAL "")
|
||||||
|
set(GIT_REV "N/A")
|
||||||
|
set(GIT_BRANCH "N/A")
|
||||||
|
else()
|
||||||
|
execute_process(
|
||||||
|
COMMAND git rev-parse --abbrev-ref HEAD
|
||||||
|
OUTPUT_VARIABLE GIT_BRANCH)
|
||||||
|
|
||||||
|
string(STRIP "${GIT_REV}" GIT_REV)
|
||||||
|
string(STRIP "${GIT_BRANCH}" GIT_BRANCH)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(VERSION "const char* GIT_REV=\"${GIT_REV}\";
|
||||||
|
const char* GIT_BRANCH=\"${GIT_BRANCH}\";")
|
||||||
|
|
||||||
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp)
|
||||||
|
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp VERSION_)
|
||||||
|
else()
|
||||||
|
set(VERSION_ "")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (NOT "${VERSION}" STREQUAL "${VERSION_}")
|
||||||
|
file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp "${VERSION}")
|
||||||
|
endif()
|
||||||
|
|
Loading…
Reference in New Issue