From 7ac969f2bc3d41838c5c6a17ec1cda800a912081 Mon Sep 17 00:00:00 2001 From: Enrico Seiler Date: Sun, 22 Aug 2021 20:27:51 +0200 Subject: [PATCH] [INFRA] Propagate cmake project version to argument parser --- CMakeLists.txt | 35 +++++++++++++++++++++++++++++++-- src/CMakeLists.txt | 2 ++ src/argument_parsing/shared.cpp | 4 ++-- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 704346f2..424528c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,42 @@ cmake_minimum_required (VERSION 3.8) -## CUSTOMISE - # Define the application name and version. project (raptor VERSION 2.0.0) +# Fallback to these values if there is no git or no git repository +set (RAPTOR_COMMIT_DATE "2021-08-20--no-git" + CACHE STRING + "Set to provide a commit date if git is not available or the source directory is not a git repository.") +set (RAPTOR_COMMIT_HASH "74f815358db47037e93a56b826a9df3692e55680--no-git" + CACHE STRING + "Set to provide a commit hash if git is not available or the source directory is not a git repository.") + +# Extract git commit hash and date +find_package (Git QUIET) + +if (GIT_FOUND) + execute_process (COMMAND "${GIT_EXECUTABLE}" -C "${CMAKE_SOURCE_DIR}" rev-parse + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE is_no_git_repository + ERROR_QUIET) + + if (NOT is_no_git_repository) + execute_process (COMMAND "${GIT_EXECUTABLE}" describe --always --abbrev=40 --dirty + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE RAPTOR_COMMIT_HASH + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process (COMMAND + "${GIT_EXECUTABLE}" log -1 --format=%ad --date=short + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE RAPTOR_COMMIT_DATE + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + endif () +endif () + ## BUILD # Make Release default build type diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0111f267..05716a0f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,6 +32,8 @@ target_link_libraries ("${PROJECT_NAME}_upgrade_lib" PUBLIC "${PROJECT_NAME}_int # Raptor argument parsing add_library ("${PROJECT_NAME}_argument_parsing_shared_lib" STATIC argument_parsing/shared.cpp) +target_compile_definitions ("${PROJECT_NAME}_argument_parsing_shared_lib" PUBLIC "-DRAPTOR_VERSION=\"${CMAKE_PROJECT_VERSION} (${RAPTOR_COMMIT_HASH})\"") +target_compile_definitions ("${PROJECT_NAME}_argument_parsing_shared_lib" PUBLIC "-DRAPTOR_DATE=\"${RAPTOR_COMMIT_DATE}\"") target_link_libraries ("${PROJECT_NAME}_argument_parsing_shared_lib" PUBLIC "${PROJECT_NAME}_interface") add_library ("${PROJECT_NAME}_argument_parsing_build_lib" STATIC argument_parsing/build.cpp) diff --git a/src/argument_parsing/shared.cpp b/src/argument_parsing/shared.cpp index bf933a0b..b982f040 100644 --- a/src/argument_parsing/shared.cpp +++ b/src/argument_parsing/shared.cpp @@ -18,7 +18,7 @@ void init_shared_meta(seqan3::argument_parser & parser) "nucleotide sequences; Enrico Seiler, Svenja Mehringer, Mitra Darvish, Etienne Turc, " "and Knut Reinert; iScience 2021 24 (7): 102782. doi: " "https://doi.org/10.1016/j.isci.2021.102782"; - parser.info.date = "20-08-2021"; + parser.info.date = RAPTOR_DATE; parser.info.email = "enrico.seiler@fu-berlin.de"; parser.info.long_copyright = R"(BSD 3-Clause License @@ -52,7 +52,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.)"; parser.info.short_copyright = "BSD 3-Clause License"; parser.info.short_description = "A fast and space-efficient pre-filter for querying very large collections of nucleotide sequences."; parser.info.url = "https://github.com/seqan/raptor"; - parser.info.version = "2.0.0"; + parser.info.version = RAPTOR_VERSION; } void try_parsing(seqan3::argument_parser & parser)