From 8e8de07760dcf7ffde87c16acea6e9f41af9fc5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Mon, 17 Jun 2019 17:22:33 +0300 Subject: [PATCH] Generate a C file with git revision string Former-commit-id: b70cf214ee64d245cbb6b2337b1a4d4e922429c9 --- CMakeLists.txt | 6 +++++- version.cmake | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 version.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 22cc8e1..73c85d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,11 @@ cmake_minimum_required(VERSION 3.0.2) include(CMakeAddFortranSubdirectory) +include(version.cmake) + project (QPMS) +set(CMAKE_BUILD_TYPE Debug) + macro(use_c99) if (CMAKE_VERSION VERSION_LESS "3.1") if (CMAKE_C_COMPILER_ID STREQUAL "GNU") @@ -24,4 +28,4 @@ cmake_add_fortran_subdirectory (amos LIBRARIES amos NO_EXTERNAL_INSTALL) add_subdirectory (qpms) - +#add_subdirectory (apps/transop-ewald) diff --git a/version.cmake b/version.cmake new file mode 100644 index 0000000..df2bc14 --- /dev/null +++ b/version.cmake @@ -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() +