From 486b45c6807b2b766dd274b7017e95c1a39ed4ab Mon Sep 17 00:00:00 2001 From: Tobias Reisinger Date: Wed, 17 Jun 2020 01:52:06 +0200 Subject: [PATCH] fix: versioning --- CMakeLists.txt | 13 +++++++------ src/helpers/parse_cli.c | 10 +++++++++- version.h.in | 2 ++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f50273a..7082966 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project(core - VERSION 0.1.0 + VERSION 0.1.1 LANGUAGES C) add_executable(core src/main.c) @@ -10,7 +10,6 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wpedantic -Werror -Wall -Wextra set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g -fprofile-arcs -ftest-coverage") add_definitions("-DMG_ENABLE_EXTRA_ERRORS_DESC") -add_definitions("-DEMGAUWA_CORE_VERSION=${CMAKE_PROJECT_VERSION}") aux_source_directory(src/ SRC_DIR) aux_source_directory(src/models MODELS_SRC) @@ -21,10 +20,12 @@ aux_source_directory(src/endpoints ENDPOINTS_SRC) add_dependencies(core migrations) configure_file("core.ini" "core.ini" COPYONLY) +configure_file("version.h.in" "version.h" @ONLY) + target_sources(core PRIVATE ${SRC_DIR} ${HANDLERS_SRC} ${HELPERS_SRC} ${MODELS_SRC} ${ENDPOINTS_SRC}) target_include_directories(core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_include_directories(core PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/vendor) +target_include_directories(core PRIVATE ${CMAKE_BINARY_DIR}) add_custom_target(migrations COMMAND ./compile_migrations.sh @@ -34,17 +35,17 @@ add_custom_target(migrations add_custom_target(run COMMAND ./core start DEPENDS core - WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_custom_target(debug COMMAND valgrind ./core start DEPENDS core - WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_custom_target(debug-full COMMAND valgrind --leak-check=full --show-leak-kinds=all ./core start DEPENDS core - WORKING_DIRECTORY ${CMAKE_PROJECT_DIR} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) add_custom_target(docs COMMAND doxygen diff --git a/src/helpers/parse_cli.c b/src/helpers/parse_cli.c index 10f9aa7..f708ed9 100644 --- a/src/helpers/parse_cli.c +++ b/src/helpers/parse_cli.c @@ -6,6 +6,7 @@ #include #include #include +#include static const char *const usage[] = { "core [options] [[--] args]", @@ -16,12 +17,13 @@ static const char *const usage[] = { void helper_parse_cli(int argc, const char **argv, config_t *config) { + int version = 0; struct argparse_option options[] = { OPT_HELP(), OPT_GROUP("Basic options"), OPT_STRING('c', "config", &config->file, "path to config file", NULL, 0, OPT_NONEG), - + OPT_BOOLEAN('v', "version", &version, "print version", NULL, 0, OPT_NONEG), OPT_END(), }; @@ -34,6 +36,12 @@ helper_parse_cli(int argc, const char **argv, config_t *config) ); argc = argparse_parse(&argparse, argc, argv); + if(version) + { + printf("%s\n", EMGAUWA_CORE_VERSION); + exit(0); + } + if(argc == 1) { config->run_type = RUN_TYPE_INVALID; diff --git a/version.h.in b/version.h.in new file mode 100644 index 0000000..cc2afe8 --- /dev/null +++ b/version.h.in @@ -0,0 +1,2 @@ +#define EMGAUWA_CORE_VERSION "@CMAKE_PROJECT_VERSION@" +