From 1c86fb7ec351b219f8220544285b427be34ee8d4 Mon Sep 17 00:00:00 2001 From: Martin Blicha Date: Thu, 18 May 2023 23:28:02 +0200 Subject: [PATCH] Options: Add option to print current version This solution is not ideal, it should be more sophisticated and distinguish between current builds and official releases. --- CMakeLists.txt | 2 ++ src/Options.cc | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fae4c3b..53bf0717 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,8 @@ set(GOLEM_VERSION_PATCH 1) set(GOLEM_VERSION ${GOLEM_VERSION_MAJOR}.${GOLEM_VERSION_MINOR}.${GOLEM_VERSION_PATCH}) project(Golem VERSION ${GOLEM_VERSION} LANGUAGES CXX) +add_definitions(-DGOLEM_VERSION="${GOLEM_VERSION}") + set(CMAKE_CXX_STANDARD 17) set(CMAKE_SOURCE_DIR "src") diff --git a/src/Options.cc b/src/Options.cc index a30e4bed..ffa80702 100644 --- a/src/Options.cc +++ b/src/Options.cc @@ -30,6 +30,7 @@ void printUsage() { "Usage: golem [options] [-i] file\n" "\n" "-h,--help Print this help message\n" + "--version Print version number of Golem\n" "-l,--logic SMT-LIB logic to use (required); possible values: QF_LRA, QF_LIA\n" "-e,--engine Select engine to use; supported engines:\n" " bmc - Bounded Model Checking (only transition systems)\n" @@ -62,10 +63,12 @@ Options CommandLineParser::parse(int argc, char ** argv) { int forcedCovering = 0; int verbose = 0; int tpaUseQE = 0; + int printVersion = 0; struct option long_options[] = { {"help", no_argument, nullptr, 'h'}, + {"version", no_argument, &printVersion, 1}, {Options::ENGINE.c_str(), required_argument, nullptr, 'e'}, {Options::LOGIC.c_str(), required_argument, nullptr, 'l'}, {Options::INPUT_FILE.c_str(), required_argument, nullptr, 'i'}, @@ -87,6 +90,10 @@ Options CommandLineParser::parse(int argc, char ** argv) { switch (c) { case 0: + if (long_options[option_index].flag == &printVersion) { + std::cout << "Golem " << GOLEM_VERSION << std::endl; + exit(0); + } if (long_options[option_index].flag == &computeWitness and optarg) { if (isDisableKeyword(optarg)) { computeWitness = 0; @@ -110,15 +117,12 @@ Options CommandLineParser::parse(int argc, char ** argv) { break; case 'e': res.addOption(Options::ENGINE, optarg); -// printf ("option -e with value `%s'\n", optarg); break; case 'l': res.addOption(Options::LOGIC, optarg); -// printf ("option -l with value `%s'\n", optarg); break; case 'i': res.addOption(Options::INPUT_FILE, optarg); -// printf ("option -i with value `%s'\n", optarg); break; case 'f': res.addOption(Options::ANALYSIS_FLOW, optarg);