Commit cde83be99b6308ccbaf38e2757cdb96386d0715d

Authored by Jarryd Beck
1 parent e725ea30

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
... ... @@ -12,6 +12,7 @@ options. The project adheres to semantic versioning.
12 12 ### Bug Fixes
13 13  
14 14 * Fix a warning about possible loss of data.
  15 +* Fix version numbering in CMakeLists.txt
15 16  
16 17 ## 2.1.1
17 18  
... ...
CMakeLists.txt
... ... @@ -22,7 +22,16 @@ project(cxxopts)
22 22  
23 23 enable_testing()
24 24  
25   -set(VERSION "1.2.0")
  25 +file(STRINGS "${PROJECT_SOURCE_DIR}/include/cxxopts.hpp" cxxopts_version_defines
  26 + REGEX "#define {CXXOPTS__VERSION_(MAJOR|MINOR|PATCH)")
  27 +foreach(ver ${cxxopts_version_defines})
  28 + if(ver MATCHES "#define {CXXOPTS__VERSION_(MAJOR|MINOR|PATCH) +([^ ]+)$")
  29 + set({CXXOPTS__VERSION_${CMAKE_MATCH_1} "${CMAKE_MATCH_2}" CACHE INTERNAL "")
  30 + endif()
  31 +endforeach()
  32 +set(VERSION ${CXXOPTS__VERSION_MAJOR}.${CXXOPTS__VERSION_MINOR}.${CXXOPTS__VERSION_PATCH})
  33 +
  34 +# set(VERSION "1.2.0")
26 35  
27 36 option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
28 37 option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" OFF)
... ...
include/cxxopts.hpp
... ... @@ -43,11 +43,19 @@ THE SOFTWARE.
43 43 #define CXXOPTS_HAS_OPTIONAL
44 44 #endif
45 45  
  46 +#define CXXOPTS__VERSION_MAJOR 2
  47 +#define CXXOPTS__VERSION_MINOR 2
  48 +#define CXXOPTS__VERSION_PATCH 0
  49 +
46 50 namespace cxxopts
47 51 {
48 52 static constexpr struct {
49 53 uint8_t major, minor, patch;
50   - } version = {2, 1, 0};
  54 + } version = {
  55 + CXXOPTS__VERSION_MAJOR,
  56 + CXXOPTS__VERSION_MINOR,
  57 + CXXOPTS__VERSION_PATCH
  58 + };
51 59 }
52 60  
53 61 //when we ask cxxopts to use Unicode, help strings are processed using ICU,
... ...