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.
This commit is contained in:
Jarryd Beck 2018-07-05 17:53:53 +10:00
parent e725ea3084
commit cde83be99b
3 changed files with 20 additions and 2 deletions

View File

@ -12,6 +12,7 @@ options. The project adheres to semantic versioning.
### Bug Fixes ### Bug Fixes
* Fix a warning about possible loss of data. * Fix a warning about possible loss of data.
* Fix version numbering in CMakeLists.txt
## 2.1.1 ## 2.1.1

View File

@ -22,7 +22,16 @@ project(cxxopts)
enable_testing() 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_EXAMPLES "Set to ON to build examples" ON)
option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" OFF) option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" OFF)

View File

@ -43,11 +43,19 @@ THE SOFTWARE.
#define CXXOPTS_HAS_OPTIONAL #define CXXOPTS_HAS_OPTIONAL
#endif #endif
#define CXXOPTS__VERSION_MAJOR 2
#define CXXOPTS__VERSION_MINOR 2
#define CXXOPTS__VERSION_PATCH 0
namespace cxxopts namespace cxxopts
{ {
static constexpr struct { static constexpr struct {
uint8_t major, minor, patch; 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, //when we ask cxxopts to use Unicode, help strings are processed using ICU,