From cde83be99b6308ccbaf38e2757cdb96386d0715d Mon Sep 17 00:00:00 2001 From: Jarryd Beck Date: Thu, 5 Jul 2018 17:53:53 +1000 Subject: [PATCH] Fix version numbering in CMakeLists.txt Fixes #115. Read the version number out of `cxxopts.hpp` instead of having to duplicate it in CMakeLists.txt. --- CHANGELOG.md | 1 + CMakeLists.txt | 11 ++++++++++- include/cxxopts.hpp | 10 +++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d50eb..6904aea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ options. The project adheres to semantic versioning. ### Bug Fixes * Fix a warning about possible loss of data. +* Fix version numbering in CMakeLists.txt ## 2.1.1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 2949e77..a906518 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,16 @@ project(cxxopts) enable_testing() -set(VERSION "1.2.0") +file(STRINGS "${PROJECT_SOURCE_DIR}/include/cxxopts.hpp" cxxopts_version_defines + REGEX "#define {CXXOPTS__VERSION_(MAJOR|MINOR|PATCH)") +foreach(ver ${cxxopts_version_defines}) + if(ver MATCHES "#define {CXXOPTS__VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$") + set({CXXOPTS__VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "") + endif() +endforeach() +set(VERSION ${CXXOPTS__VERSION_MAJOR}.${CXXOPTS__VERSION_MINOR}.${CXXOPTS__VERSION_PATCH}) + +# set(VERSION "1.2.0") option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON) option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" OFF) diff --git a/include/cxxopts.hpp b/include/cxxopts.hpp index f590587..b6865d9 100644 --- a/include/cxxopts.hpp +++ b/include/cxxopts.hpp @@ -43,11 +43,19 @@ THE SOFTWARE. #define CXXOPTS_HAS_OPTIONAL #endif +#define CXXOPTS__VERSION_MAJOR 2 +#define CXXOPTS__VERSION_MINOR 2 +#define CXXOPTS__VERSION_PATCH 0 + namespace cxxopts { static constexpr struct { uint8_t major, minor, patch; - } version = {2, 1, 0}; + } version = { + CXXOPTS__VERSION_MAJOR, + CXXOPTS__VERSION_MINOR, + CXXOPTS__VERSION_PATCH + }; } //when we ask cxxopts to use Unicode, help strings are processed using ICU,