From 5f9462caad014e4abfc762101c8d2e6b02bb1ae5 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 19 Dec 2019 12:44:55 -0500 Subject: Print version --- CMakeLists.txt | 12 +++++++++++- config.h.in | 1 + src/spm.c | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee2fded..a833b85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,18 @@ cmake_minimum_required(VERSION 3.15) project(spm C) include(CheckSymbolExists) +find_package(Git) set(CMAKE_C_STANDARD 99) - +execute_process( + COMMAND ${GIT_EXECUTABLE} describe --always --tags --dirty + OUTPUT_VARIABLE VERSION + ERROR_VARIABLE VERSION_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE +) +if(${VERSION_ERROR}) + message("Git required to build this software") + return(1) +endif(${VERSION_ERROR}) check_symbol_exists(strsep string.h HAVE_STRSEP) configure_file(${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_BINARY_DIR}/include/config.h) diff --git a/config.h.in b/config.h.in index cedd8a4..b9fd475 100644 --- a/config.h.in +++ b/config.h.in @@ -2,5 +2,6 @@ #define SPM_CONFIG_IN_H #cmakedefine HAVE_STRSEP 1 +#define SPM_VERSION "${VERSION}" #endif //SPM_CONFIG_IN_H diff --git a/src/spm.c b/src/spm.c index 60ab3b6..58619fe 100644 --- a/src/spm.c +++ b/src/spm.c @@ -57,7 +57,7 @@ int main(int argc, char *argv[]) { exit(0); } else if (strcmp(arg, "-V") == 0 || strcmp(arg, "--version") == 0) { - printf("want version\n"); + printf("%s\n", SPM_VERSION); exit(0); } else if (strcmp(arg, "-v") == 0 || strcmp(arg, "--verbose") == 0) { -- cgit