Browse Source

Update cxxopts

master
C. J. Howard 2 years ago
parent
commit
ea0fb23618
18 changed files with 1271 additions and 495 deletions
  1. +24
    -0
      modules/cxxopts/.github/workflows/build.yml
  2. +44
    -0
      modules/cxxopts/.github/workflows/cmake.yml
  3. +2
    -1
      modules/cxxopts/.gitignore
  4. +33
    -5
      modules/cxxopts/.travis.yml
  5. +8
    -0
      modules/cxxopts/BUILD.bazel
  6. +17
    -1
      modules/cxxopts/CHANGELOG.md
  7. +47
    -73
      modules/cxxopts/CMakeLists.txt
  8. +38
    -0
      modules/cxxopts/README.md
  9. +0
    -0
      modules/cxxopts/WORKSPACE
  10. +158
    -0
      modules/cxxopts/cmake/cxxopts.cmake
  11. +23
    -0
      modules/cxxopts/include/CMakeLists.txt
  12. +714
    -334
      modules/cxxopts/include/cxxopts.hpp
  13. +0
    -0
      modules/cxxopts/packaging/cxxopts-config.cmake.in
  14. +7
    -0
      modules/cxxopts/packaging/pkgconfig.pc.in
  15. +5
    -7
      modules/cxxopts/src/CMakeLists.txt
  16. +5
    -2
      modules/cxxopts/src/example.cpp
  17. +50
    -32
      modules/cxxopts/test/CMakeLists.txt
  18. +96
    -40
      modules/cxxopts/test/options.cpp

+ 24
- 0
modules/cxxopts/.github/workflows/build.yml View File

@ -0,0 +1,24 @@
name: Build cxxopts
on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: setup
run: mkdir build; cd build
- name: cmake
run: cmake ..
- name: Build
run: make -j$(nproc)
- name: test
run: ctest

+ 44
- 0
modules/cxxopts/.github/workflows/cmake.yml View File

@ -0,0 +1,44 @@
name: CMake
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-18.04]
compiler: [g++-7, g++-9, g++-10, clang++]
steps:
- uses: actions/checkout@v2
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=${{matrix.compiler}}
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}

+ 2
- 1
modules/cxxopts/.gitignore View File

@ -1,8 +1,9 @@
*.swp
build*
build*/
CMakeCache.txt
Makefile
CMakeFiles/
Testing/
CTestTestfile.cmake
cmake_install.cmake
bazel-*

+ 33
- 5
modules/cxxopts/.travis.yml View File

@ -6,21 +6,35 @@ os:
matrix:
include:
- os: linux
env: COMPILER=g++-4.9
env: COMPILER=g++-6
addons:
apt:
packages:
- g++-4.9
- g++-6
sources: &sources
- llvm-toolchain-trusty-3.8
- llvm-toolchain-trusty-5.0
- ubuntu-toolchain-r-test
- os: linux
env: COMPILER=g++-4.9 UNICODE_OPTIONS=-DCXXOPTS_USE_UNICODE_HELP=Yes
env: COMPILER=g++-6 UNICODE_OPTIONS=-DCXXOPTS_USE_UNICODE_HELP=Yes
addons:
apt:
packages:
- g++-4.9
- g++-6
sources: *sources
- os: linux
env: COMPILER=g++-7
addons:
apt:
packages:
- g++-7
sources: *sources
- os: linux
env: COMPILER=g++-7 UNICODE_OPTIONS=-DCXXOPTS_USE_UNICODE_HELP=Yes
addons:
apt:
packages:
- g++-7
sources: *sources
- os: linux
env: COMPILER=g++-5
@ -36,6 +50,20 @@ matrix:
packages:
- g++-5
sources: *sources
- os: linux
env: COMPILER=g++-4.8
addons:
apt:
packages:
- g++-4.8
sources: *sources
- os: linux
env: COMPILER=g++-4.8 UNICODE_OPTIONS=-DCXXOPTS_USE_UNICODE_HELP=Yes
addons:
apt:
packages:
- g++-4.8
sources: *sources
- os: linux
env: COMPILER=clang++-3.8 CXXFLAGS=-stdlib=libc++
addons:
@ -61,7 +89,7 @@ matrix:
- g++-5
sources: *sources
script: >
cmake -DCXXOPTS_BUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$COMPILER
cmake -Werror=dev -DCXXOPTS_BUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$COMPILER
-DCMAKE_CXX_FLAGS=$CXXFLAGS $UNICODE_OPTIONS $CMAKE_OPTIONS .
&& make && make ARGS=--output-on-failure test

+ 8
- 0
modules/cxxopts/BUILD.bazel View File

@ -0,0 +1,8 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
cc_library(
name = "cxxopts",
hdrs = ["include/cxxopts.hpp"],
strip_include_prefix = "include",
visibility = ["//visibility:public"],
)

+ 17
- 1
modules/cxxopts/CHANGELOG.md View File

@ -3,7 +3,7 @@
This is the changelog for `cxxopts`, a C++11 library for parsing command line
options. The project adheres to semantic versioning.
## Next version
## 3.0
### Changed
@ -12,6 +12,22 @@ options. The project adheres to semantic versioning.
* Fix duplicate default options when there is a short and long option.
* Add `CXXOPTS_NO_EXCEPTIONS` to disable exceptions.
* Fix char parsing for space and check for length.
* Change argument type in `Options::parse` from `char**` to `const char**`.
* Refactor parser to not change its arguments.
* `ParseResult` doesn't depend on a reference to the parser.
* Fixed several warnings and code quality issues.
* Improved formatting for help descriptions.
* Improve integer parsing.
### Added
* A list of unmatched arguments is available in `ParseResult`.
* Support single letter options with argument attached.
* Use <optional> if it is present.
### Bug Fixes
* Fix missing option name in exception.
## 2.2

+ 47
- 73
modules/cxxopts/CMakeLists.txt View File

@ -1,15 +1,15 @@
# Copyright (c) 2014 Jarryd Beck
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -17,92 +17,66 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.1...3.19)
# parse the current version from the cxxopts header
file(STRINGS "${CMAKE_CURRENT_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})
message(STATUS "cxxopts version ${VERSION}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(cxxopts)
set("PROJECT_DESCRIPTION" "A header-only lightweight C++ command line option parser")
set("PROJECT_HOMEPAGE_URL" "https://github.com/jarro2783/cxxopts")
project(cxxopts VERSION "${VERSION}" LANGUAGES CXX)
# Get the version of the library
cxxopts_getversion(VERSION)
enable_testing()
project(cxxopts
VERSION "${VERSION}"
LANGUAGES CXX
)
option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON)
option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ON)
# Must include after the project call due to GNUInstallDirs requiring a language be enabled (IE. CXX)
include(GNUInstallDirs)
# request c++11 without gnu extension for the whole project and enable more warnings
if (CXXOPTS_CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${CXXOPTS_CXX_STANDARD})
else()
set(CMAKE_CXX_STANDARD 11)
# Determine whether this is a standalone project or included by other projects
set(CXXOPTS_STANDALONE_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CXXOPTS_STANDALONE_PROJECT ON)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
# Establish the project options
option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ${CXXOPTS_STANDALONE_PROJECT})
option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ${CXXOPTS_STANDALONE_PROJECT})
option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ${CXXOPTS_STANDALONE_PROJECT})
option(CXXOPTS_ENABLE_WARNINGS "Add warnings to CMAKE_CXX_FLAGS" ${CXXOPTS_STANDALONE_PROJECT})
option(CXXOPTS_USE_UNICODE_HELP "Use ICU Unicode library" OFF)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow")
if (CXXOPTS_STANDALONE_PROJECT)
cxxopts_set_cxx_standard()
endif()
if (CXXOPTS_ENABLE_WARNINGS)
cxxopts_enable_warnings()
endif()
add_library(cxxopts INTERFACE)
add_library(cxxopts::cxxopts ALIAS cxxopts)
add_subdirectory(include)
# optionally, enable unicode support using the ICU library
set(CXXOPTS_USE_UNICODE_HELP FALSE CACHE BOOL "Use ICU Unicode library")
# Link against the ICU library when requested
if(CXXOPTS_USE_UNICODE_HELP)
find_package(PkgConfig)
pkg_check_modules(ICU REQUIRED icu-uc)
target_link_libraries(cxxopts INTERFACE ${ICU_LDFLAGS})
target_compile_options(cxxopts INTERFACE ${ICU_CFLAGS})
target_compile_definitions(cxxopts INTERFACE CXXOPTS_USE_UNICODE)
cxxopts_use_unicode()
endif()
target_include_directories(cxxopts INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if(CXXOPTS_ENABLE_INSTALL)
include(CMakePackageConfigHelpers)
set(CXXOPTS_CMAKE_DIR "lib/cmake/cxxopts" CACHE STRING
"Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
set(targets_export_name cxxopts-targets)
# Generate the version, config and target files into the build directory.
write_basic_package_version_file(
${version_config}
VERSION ${VERSION}
COMPATIBILITY AnyNewerVersion)
configure_package_config_file(
${PROJECT_SOURCE_DIR}/cxxopts-config.cmake.in
${project_config}
INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})
export(TARGETS cxxopts NAMESPACE cxxopts::
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
# Install version, config and target files.
install(
FILES ${project_config} ${version_config}
DESTINATION ${CXXOPTS_CMAKE_DIR})
install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
NAMESPACE cxxopts::)
# Install cxxopts when requested by the user
if (CXXOPTS_ENABLE_INSTALL)
cxxopts_install_logic()
endif()
# Install the header file and export the target
install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION lib)
install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION include)
# Build examples when requested by the user
if (CXXOPTS_BUILD_EXAMPLES)
add_subdirectory(src)
endif()
add_subdirectory(src)
add_subdirectory(test)
# Enable testing when requested by the user
if (CXXOPTS_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()

+ 38
- 0
modules/cxxopts/README.md View File

@ -5,6 +5,25 @@
Note that `master` is generally a work in progress, and you probably want to use a
tagged release version.
## Version 3 breaking changes
If you have used version 2, there are a couple of breaking changes in version 3
that you should be aware of. If you are new to `cxxopts` you can skip this
section.
The parser no longer modifies its arguments, so you can pass a const `argc` and
`argv` and expect them not to be changed.
The `ParseResult` object no longer depends on the parser. So it can be returned
from a scope outside the parser and still work. Now that the inputs are not
modified, `ParseResult` stores a list of the unmatched arguments. These are
retrieved like follows:
```cpp
auto result = options.parse(argc, argv);
result.unmatched(); // get the unmatched arguments
```
# Quick start
This is a lightweight C++ option parser library, supporting the standard GNU
@ -69,6 +88,23 @@ exception will be thrown.
Note that the result of `options.parse` should only be used as long as the
`options` object that created it is in scope.
## Unrecognised arguments
You can allow unrecognised arguments to be skipped. This applies to both
positional arguments that are not parsed into another option, and `--`
arguments that do not match an argument that you specify. This is done by
calling:
```cpp
options.allow_unrecognised_options();
```
and in the result object they are retrieved with:
```cpp
result.unmatched()
```
## Exceptions
Exceptional situations throw C++ exceptions. There are two types of
@ -125,6 +161,8 @@ Note that the default and implicit value is always stored as a string,
regardless of the type that you want to store it in. It will be parsed as
though it was given on the command line.
Default values are not counted by `Options::count`.
## Boolean values
Boolean options have a default implicit value of `"true"`, which can be

+ 0
- 0
modules/cxxopts/WORKSPACE View File


+ 158
- 0
modules/cxxopts/cmake/cxxopts.cmake View File

@ -0,0 +1,158 @@
# Copyright (c) 2014 Jarryd Beck
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
if (CMAKE_VERSION VERSION_GREATER 3.10 OR CMAKE_VERSION VERSION_EQUAL 3.10)
# Use include_guard() added in cmake 3.10
include_guard()
endif()
include(CMakePackageConfigHelpers)
function(cxxopts_getversion version_arg)
# Parse the current version from the cxxopts header
file(STRINGS "${CMAKE_CURRENT_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})
# Give feedback to the user. Prefer DEBUG when available since large projects tend to have a lot
# going on already
if (CMAKE_VERSION VERSION_GREATER 3.15 OR CMAKE_VERSION VERSION_EQUAL 3.15)
message(DEBUG "cxxopts version ${VERSION}")
else()
message(STATUS "cxxopts version ${VERSION}")
endif()
# Return the information to the caller
set(${version_arg} ${VERSION} PARENT_SCOPE)
endfunction()
# Optionally, enable unicode support using the ICU library
function(cxxopts_use_unicode)
find_package(PkgConfig)
pkg_check_modules(ICU REQUIRED icu-uc)
target_link_libraries(cxxopts INTERFACE ${ICU_LDFLAGS})
target_compile_options(cxxopts INTERFACE ${ICU_CFLAGS})
target_compile_definitions(cxxopts INTERFACE CXXOPTS_USE_UNICODE)
endfunction()
# Request C++11 without gnu extension for the whole project and enable more warnings
macro(cxxopts_set_cxx_standard)
if (CXXOPTS_CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${CXXOPTS_CXX_STANDARD})
else()
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
endmacro()
# Helper function to enable warnings
function(cxxopts_enable_warnings)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER_EQUAL 5.0)
set(COMPILER_SPECIFIC_FLAGS "-Wsuggest-override")
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion ${COMPILER_SPECIFIC_FLAGS}")
endif()
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} PARENT_SCOPE)
endfunction()
# Helper function to ecapsulate install logic
function(cxxopts_install_logic)
string(REPLACE "/${CMAKE_LIBRARY_ARCHITECTURE}" "" CMAKE_INSTALL_LIBDIR_ARCHIND "${CMAKE_INSTALL_LIBDIR}")
set(CXXOPTS_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR_ARCHIND}/cmake/cxxopts" CACHE STRING "Installation directory for cmake files, relative to ${CMAKE_INSTALL_PREFIX}.")
set(version_config "${PROJECT_BINARY_DIR}/cxxopts-config-version.cmake")
set(project_config "${PROJECT_BINARY_DIR}/cxxopts-config.cmake")
set(targets_export_name cxxopts-targets)
set(PackagingTemplatesDir "${PROJECT_SOURCE_DIR}/packaging")
if(${CMAKE_VERSION} VERSION_GREATER "3.14")
set(OPTIONAL_ARCH_INDEPENDENT "ARCH_INDEPENDENT")
endif()
# Generate the version, config and target files into the build directory.
write_basic_package_version_file(
${version_config}
VERSION ${VERSION}
COMPATIBILITY AnyNewerVersion
${OPTIONAL_ARCH_INDEPENDENT}
)
configure_package_config_file(
${PackagingTemplatesDir}/cxxopts-config.cmake.in
${project_config}
INSTALL_DESTINATION ${CXXOPTS_CMAKE_DIR})
export(TARGETS cxxopts NAMESPACE cxxopts::
FILE ${PROJECT_BINARY_DIR}/${targets_export_name}.cmake)
# Install version, config and target files.
install(
FILES ${project_config} ${version_config}
DESTINATION ${CXXOPTS_CMAKE_DIR})
install(EXPORT ${targets_export_name} DESTINATION ${CXXOPTS_CMAKE_DIR}
NAMESPACE cxxopts::)
# Install the header file and export the target
install(TARGETS cxxopts EXPORT ${targets_export_name} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${PROJECT_SOURCE_DIR}/include/cxxopts.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "cxxopt developers")
set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}")
set(CPACK_DEBIAN_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_RPM_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_PACKAGE_HOMEPAGE_URL "${PROJECT_HOMEPAGE_URL}")
set(CPACK_PACKAGE_MAINTAINER "${CPACK_PACKAGE_VENDOR}")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_PACKAGE_MAINTAINER}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
set(CPACK_DEBIAN_PACKAGE_NAME "lib${PROJECT_NAME}-dev")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6-dev")
set(CPACK_DEBIAN_PACKAGE_SUGGESTS "cmake, pkg-config, pkg-conf")
set(CPACK_RPM_PACKAGE_NAME "lib${PROJECT_NAME}-devel")
set(CPACK_RPM_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}")
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_NSIS_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_COMPRESSION_TYPE "xz")
set(PKG_CONFIG_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc")
configure_file("${PackagingTemplatesDir}/pkgconfig.pc.in" "${PKG_CONFIG_FILE_NAME}" @ONLY)
install(FILES "${PKG_CONFIG_FILE_NAME}"
DESTINATION "${CMAKE_INSTALL_LIBDIR_ARCHIND}/pkgconfig"
)
include(CPack)
endfunction()

+ 23
- 0
modules/cxxopts/include/CMakeLists.txt View File

@ -0,0 +1,23 @@
# Copyright (c) 2014 Jarryd Beck
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
target_include_directories(cxxopts INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)

+ 714
- 334
modules/cxxopts/include/cxxopts.hpp
File diff suppressed because it is too large
View File


modules/cxxopts/cxxopts-config.cmake.in → modules/cxxopts/packaging/cxxopts-config.cmake.in View File


+ 7
- 0
modules/cxxopts/packaging/pkgconfig.pc.in View File

@ -0,0 +1,7 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@
Cflags: -I${includedir}

+ 5
- 7
modules/cxxopts/src/CMakeLists.txt View File

@ -1,15 +1,15 @@
# Copyright (c) 2014 Jarryd Beck
#
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -18,7 +18,5 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
if(CXXOPTS_BUILD_EXAMPLES)
add_executable(example example.cpp)
target_link_libraries(example cxxopts)
endif()
add_executable(example example.cpp)
target_link_libraries(example cxxopts)

+ 5
- 2
modules/cxxopts/src/example.cpp View File

@ -27,7 +27,7 @@ THE SOFTWARE.
#include "cxxopts.hpp"
void
parse(int argc, char* argv[])
parse(int argc, const char* argv[])
{
try
{
@ -39,6 +39,8 @@ parse(int argc, char* argv[])
bool apple = false;
options
.set_width(70)
.set_tab_expansion()
.allow_unrecognised_options()
.add_options()
("a,apple", "an apple", cxxopts::value<bool>(apple))
@ -56,6 +58,7 @@ parse(int argc, char* argv[])
("long-description",
"thisisareallylongwordthattakesupthewholelineandcannotbebrokenataspace")
("help", "Print help")
("tab-expansion", "Tab\texpansion")
("int", "An integer", cxxopts::value<int>(), "N")
("float", "A floating point number", cxxopts::value<float>())
("vector", "A list of doubles", cxxopts::value<std::vector<double>>())
@ -160,7 +163,7 @@ parse(int argc, char* argv[])
}
}
int main(int argc, char* argv[])
int main(int argc, const char* argv[])
{
parse(argc, argv);

+ 50
- 32
modules/cxxopts/test/CMakeLists.txt View File

@ -1,35 +1,53 @@
if (CXXOPTS_BUILD_TESTS)
add_executable(options_test main.cpp options.cpp)
target_link_libraries(options_test cxxopts)
add_test(options options_test)
# Copyright (c) 2014 Jarryd Beck
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# test if the targets are findable from the build directory
add_test(find-package-test ${CMAKE_CTEST_COMMAND}
-C ${CMAKE_BUILD_TYPE}
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}/find-package-test"
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-Dcxxopts_DIR=${PROJECT_BINARY_DIR}"
)
add_executable(options_test main.cpp options.cpp)
target_link_libraries(options_test cxxopts)
add_test(options options_test)
# test if the targets are findable when add_subdirectory is used
add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND}
-C ${CMAKE_BUILD_TYPE}
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}/add-subdirectory-test"
"${CMAKE_CURRENT_BINARY_DIR}/add-subdirectory-test"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
)
# test if the targets are findable from the build directory
add_test(find-package-test ${CMAKE_CTEST_COMMAND}
-C ${CMAKE_BUILD_TYPE}
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}/find-package-test"
"${CMAKE_CURRENT_BINARY_DIR}/find-package-test"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
"-Dcxxopts_DIR=${PROJECT_BINARY_DIR}"
)
add_executable(link_test link_a.cpp link_b.cpp)
target_link_libraries(link_test cxxopts)
endif()
# test if the targets are findable when add_subdirectory is used
add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND}
-C ${CMAKE_BUILD_TYPE}
--build-and-test
"${CMAKE_CURRENT_SOURCE_DIR}/add-subdirectory-test"
"${CMAKE_CURRENT_BINARY_DIR}/add-subdirectory-test"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-options
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
)
add_executable(link_test link_a.cpp link_b.cpp)
target_link_libraries(link_test cxxopts)

+ 96
- 40
modules/cxxopts/test/options.cpp View File

@ -8,7 +8,7 @@ class Argv {
public:
Argv(std::initializer_list<const char*> args)
: m_argv(new char*[args.size()])
: m_argv(new const char*[args.size()])
, m_argc(static_cast<int>(args.size()))
{
int i = 0;
@ -26,7 +26,7 @@ class Argv {
}
}
char** argv() const {
const char** argv() const {
return m_argv.get();
}
@ -36,8 +36,8 @@ class Argv {
private:
std::vector<std::unique_ptr<char[]>> m_args;
std::unique_ptr<char*[]> m_argv;
std::vector<std::unique_ptr<char[]>> m_args{};
std::unique_ptr<const char*[]> m_argv;
int m_argc;
};
@ -69,7 +69,7 @@ TEST_CASE("Basic options", "[options]")
"--space",
});
char** actual_argv = argv.argv();
auto** actual_argv = argv.argv();
auto argc = argv.argc();
auto result = options.parse(argc, actual_argv);
@ -125,7 +125,7 @@ TEST_CASE("No positional", "[positional]")
Argv av({"tester", "a", "b", "def"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
@ -154,7 +154,7 @@ TEST_CASE("All positional", "[positional]")
auto result = options.parse(argc, argv);
REQUIRE(argc == 1);
CHECK(result.unmatched().size() == 0);
REQUIRE(positional.size() == 3);
CHECK(positional[0] == "a");
@ -177,12 +177,12 @@ TEST_CASE("Some positional explicit", "[positional]")
Argv av({"tester", "--output", "a", "b", "c", "d"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
CHECK(argc == 1);
CHECK(result.unmatched().size() == 0);
CHECK(result.count("output"));
CHECK(result["input"].as<std::string>() == "b");
CHECK(result["output"].as<std::string>() == "a");
@ -203,17 +203,16 @@ TEST_CASE("No positional with extras", "[positional]")
Argv av({"extras", "--", "a", "b", "c", "d"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto old_argv = argv;
auto old_argc = argc;
options.parse(argc, argv);
auto result = options.parse(argc, argv);
REQUIRE(argc == old_argc - 1);
CHECK(argv[0] == std::string("extras"));
CHECK(argv[1] == std::string("a"));
auto& unmatched = result.unmatched();
CHECK((unmatched == std::vector<std::string>{"a", "b", "c", "d"}));
}
TEST_CASE("Positional not valid", "[positional]") {
@ -226,12 +225,37 @@ TEST_CASE("Positional not valid", "[positional]") {
Argv av({"foobar", "bar", "baz"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::option_not_exists_exception&);
}
TEST_CASE("Positional with empty arguments", "[positional]") {
cxxopts::Options options("positional_with_empty_arguments", "positional with empty argument");
options.add_options()
("long", "a long option", cxxopts::value<std::string>())
("program", "program to run", cxxopts::value<std::string>())
("programArgs", "program arguments", cxxopts::value<std::vector<std::string>>())
;
options.parse_positional("program", "programArgs");
Argv av({"foobar", "--long", "long_value", "--", "someProgram", "ab", "-c", "d", "--ef", "gh", "--ijk=lm", "n", "", "o", });
std::vector<std::string> expected({"ab", "-c", "d", "--ef", "gh", "--ijk=lm", "n", "", "o", });
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
auto actual = result["programArgs"].as<std::vector<std::string>>();
REQUIRE(result.count("program") == 1);
REQUIRE(result["program"].as<std::string>() == "someProgram");
REQUIRE(result.count("programArgs") == expected.size());
REQUIRE(actual == expected);
}
TEST_CASE("Empty with implicit value", "[implicit]")
{
cxxopts::Options options("empty_implicit", "doesn't handle empty");
@ -241,7 +265,7 @@ TEST_CASE("Empty with implicit value", "[implicit]")
Argv av({"implicit", "--implicit="});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
@ -260,7 +284,7 @@ TEST_CASE("Boolean without implicit value", "[implicit]")
SECTION("When no value provided") {
Argv av({"no_implicit", "--bool"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::missing_argument_exception&);
@ -269,7 +293,7 @@ TEST_CASE("Boolean without implicit value", "[implicit]")
SECTION("With equal-separated true") {
Argv av({"no_implicit", "--bool=true"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
@ -280,7 +304,7 @@ TEST_CASE("Boolean without implicit value", "[implicit]")
SECTION("With equal-separated false") {
Argv av({"no_implicit", "--bool=false"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
@ -291,7 +315,7 @@ TEST_CASE("Boolean without implicit value", "[implicit]")
SECTION("With space-separated true") {
Argv av({"no_implicit", "--bool", "true"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
@ -302,7 +326,7 @@ TEST_CASE("Boolean without implicit value", "[implicit]")
SECTION("With space-separated false") {
Argv av({"no_implicit", "--bool", "false"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
@ -323,7 +347,7 @@ TEST_CASE("Default values", "[default]")
SECTION("Sets defaults") {
Argv av({"implicit"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
@ -339,7 +363,7 @@ TEST_CASE("Default values", "[default]")
SECTION("When values provided") {
Argv av({"implicit", "--default", "5"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
@ -374,7 +398,7 @@ TEST_CASE("Integers", "[options]")
Argv av({"ints", "--", "5", "6", "-6", "0", "0xab", "0xAf", "0x0"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
options.parse_positional("positional");
@ -401,7 +425,7 @@ TEST_CASE("Leading zero integers", "[options]")
Argv av({"ints", "--", "05", "06", "0x0ab", "0x0001"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
options.parse_positional("positional");
@ -425,7 +449,7 @@ TEST_CASE("Unsigned integers", "[options]")
Argv av({"ints", "--", "-2"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
options.parse_positional("positional");
@ -504,7 +528,7 @@ TEST_CASE("Floats", "[options]")
Argv av({"floats", "--double", "0.5", "--", "4", "-4", "1.5e6", "-1.5e6"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
options.parse_positional("positional");
@ -529,7 +553,7 @@ TEST_CASE("Invalid integers", "[integer]") {
Argv av({"ints", "--", "Ae"});
char **argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
options.parse_positional("positional");
@ -554,7 +578,7 @@ TEST_CASE("Booleans", "[boolean]") {
Argv av({"booleans", "--bool=false", "--debug=true", "--timing", "--verbose=1", "--dry-run=0", "extra"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
@ -588,7 +612,7 @@ TEST_CASE("std::vector", "[vector]") {
Argv av({"vector", "--vector", "1,-2.1,3,4.5"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
options.parse(argc, argv);
@ -609,7 +633,7 @@ TEST_CASE("std::optional", "[optional]") {
Argv av({"optional", "--optional", "foo"});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
options.parse(argc, argv);
@ -632,9 +656,10 @@ TEST_CASE("Unrecognised options", "[options]") {
"--long",
"-su",
"--another_unknown",
"-a",
});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
SECTION("Default behaviour") {
@ -643,9 +668,9 @@ TEST_CASE("Unrecognised options", "[options]") {
SECTION("After allowing unrecognised options") {
options.allow_unrecognised_options();
CHECK_NOTHROW(options.parse(argc, argv));
REQUIRE(argc == 3);
CHECK_THAT(argv[1], Catch::Equals("--unknown"));
auto result = options.parse(argc, argv);
auto& unmatched = result.unmatched();
CHECK((unmatched == std::vector<std::string>{"--unknown", "-u", "--another_unknown", "-a"}));
}
}
@ -661,7 +686,7 @@ TEST_CASE("Allow bad short syntax", "[options]") {
"-some_bad_short",
});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
SECTION("Default behaviour") {
@ -684,7 +709,7 @@ TEST_CASE("Invalid option syntax", "[options]") {
"--a",
});
char** argv = av.argv();
auto** argv = av.argv();
auto argc = av.argc();
SECTION("Default behaviour") {
@ -704,7 +729,7 @@ TEST_CASE("Options empty", "[options]") {
"--unknown"
});
auto argc = argv_.argc();
char** argv = argv_.argv();
auto** argv = argv_.argv();
CHECK(options.groups().empty());
CHECK_THROWS_AS(options.parse(argc, argv), cxxopts::option_not_exists_exception&);
@ -733,7 +758,7 @@ TEST_CASE("Initializer list with group", "[options]") {
"8000",
"-t",
});
char** actual_argv = argv.argv();
auto** actual_argv = argv.argv();
auto argc = argv.argc();
auto result = options.parse(argc, actual_argv);
@ -763,7 +788,7 @@ TEST_CASE("Option add with add_option(string, Option)", "[options]") {
"4"
});
auto argc = argv_.argc();
char** argv = argv_.argv();
auto** argv = argv_.argv();
auto result = options.parse(argc, argv);
CHECK(result.arguments().size()==2);
@ -774,3 +799,34 @@ TEST_CASE("Option add with add_option(string, Option)", "[options]") {
CHECK(result["aggregate"].as<int>() == 4);
CHECK(result["test"].as<int>() == 5);
}
TEST_CASE("Const array", "[const]") {
const char* const option_list[] = {"empty", "options"};
cxxopts::Options options("Empty options", " - test constness");
auto result = options.parse(2, option_list);
}
TEST_CASE("Parameter follow option", "[parameter]") {
cxxopts::Options options("param_follow_opt", " - test parameter follow option without space.");
options.add_options()
("j,job", "Job", cxxopts::value<std::vector<unsigned>>());
Argv av({"implicit",
"-j", "9",
"--job", "7",
"--job=10",
"-j5",
});
auto ** argv = av.argv();
auto argc = av.argc();
auto result = options.parse(argc, argv);
REQUIRE(result.count("job") == 4);
auto job_values = result["job"].as<std::vector<unsigned>>();
CHECK(job_values[0] == 9);
CHECK(job_values[1] == 7);
CHECK(job_values[2] == 10);
CHECK(job_values[3] == 5);
}

Loading…
Cancel
Save