From f7951df4a17a5c7e831dd20d43049137b5761e85 Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Sat, 13 Oct 2012 00:59:37 +0100 Subject: [PATCH] Added --version option --- CMakeLists.txt | 6 +++++- config.h.in | 3 +++ main.cpp | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6459353..b6252fe9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,8 @@ find_package(Boost 1.46 COMPONENTS unit_test_framework REQUIRED) #= Config Header #------------------------------------------------------------------------------- +set(PV_TITLE PulseView) + set(PV_VERSION_MAJOR 0) set(PV_VERSION_MINOR 1) set(PV_VERSION_MICRO 0) @@ -186,7 +188,9 @@ install(PROGRAMS pulseview DESTINATION bin/) if(ENABLE_TESTS) - add_definitions(-DBOOST_TEST_DYN_LINK) + add_definitions(pulseview-tests + -DBOOST_TEST_DYN_LINK + ) add_executable(pulseview-test ${pulseview_TEST_SOURCES} diff --git a/config.h.in b/config.h.in index ea9b0d4a..6caa2303 100644 --- a/config.h.in +++ b/config.h.in @@ -20,6 +20,9 @@ #ifndef _PULSEVIEW_CONFIG_H #define _PULSEVIEW_CONFIG_H +/* Application Details */ +#define PV_TITLE "@PV_TITLE@" + /* Pulseview version information */ #define PV_VERSION_MAJOR @PV_VERSION_MAJOR@ #define PV_VERSION_MINOR @PV_VERSION_MINOR@ diff --git a/main.cpp b/main.cpp index febe729c..a94f64c6 100644 --- a/main.cpp +++ b/main.cpp @@ -24,6 +24,8 @@ extern "C" { #include } +#include + #include #include @@ -40,6 +42,25 @@ int main(int argc, char *argv[]) QApplication::setApplicationName("PulseView"); QApplication::setOrganizationDomain("http://www.sigrok.org"); + // Parse arguments + while (1) { + static const struct option long_options[] = { + {"version", no_argument, 0, 'V'}, + {0, 0, 0, 0} + }; + + const char c = getopt_long(argc, argv, "V", long_options, NULL); + if (c == -1) + break; + + switch (c) { + case 'V': + // Print version info + fprintf(stderr, "%s %s\n", PV_TITLE, PV_VERSION_STRING); + return 0; + } + } + // Initialise libsigrok if (sr_init() != SR_OK) { qDebug() << "ERROR: libsigrok init failed."; -- 2.30.2