Skip to content

Commit

Permalink
Fix version numbering in CMakeLists.txt
Browse files Browse the repository at this point in the history
Fixes #115. Read the version number out of `cxxopts.hpp` instead of
having to duplicate it in CMakeLists.txt.
  • Loading branch information
jarro2783 committed Jul 5, 2018
1 parent e725ea3 commit cde83be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion CMakeLists.txt
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion include/cxxopts.hpp
Expand Up @@ -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,
Expand Down

0 comments on commit cde83be

Please sign in to comment.