Commit a393e353efbb68a027ed4c8fd1353e2b51d03f47

Authored by Henry Schreiner
Committed by GitHub
1 parent 229844f4

fix(build): simplify runs from master projects, require C++11 minimally if possible (#656)

.github/workflows/build.yml
@@ -3,12 +3,11 @@ on: @@ -3,12 +3,11 @@ on:
3 push: 3 push:
4 branches: 4 branches:
5 - master 5 - master
  6 + - main
6 - v* 7 - v*
7 tags: 8 tags:
8 - "*" 9 - "*"
9 pull_request: 10 pull_request:
10 - branches:  
11 - - master  
12 11
13 jobs: 12 jobs:
14 single-header: 13 single-header:
.github/workflows/tests.yml
@@ -3,10 +3,9 @@ on: @@ -3,10 +3,9 @@ on:
3 push: 3 push:
4 branches: 4 branches:
5 - master 5 - master
  6 + - main
6 - v* 7 - v*
7 pull_request: 8 pull_request:
8 - branches:  
9 - - master  
10 9
11 jobs: 10 jobs:
12 cuda-build: 11 cuda-build:
@@ -161,3 +160,10 @@ jobs: @@ -161,3 +160,10 @@ jobs:
161 cmake-version: "3.21" 160 cmake-version: "3.21"
162 args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON 161 args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
163 if: success() || failure() 162 if: success() || failure()
  163 +
  164 + - name: Check CMake 3.22 (full)
  165 + uses: ./.github/actions/quick_cmake
  166 + with:
  167 + cmake-version: "3.22"
  168 + args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
  169 + if: success() || failure()
CHANGELOG.md
@@ -2,9 +2,13 @@ @@ -2,9 +2,13 @@
2 2
3 ## WIP 3 ## WIP
4 4
5 -* Support compiling the tests with an external copy of Catch2. [#653][] 5 +* Bugfix(cmake): Enforce at least C++11 when using CMake target [#656][]
  6 +* Build: Don't run doxygen and CTest includes if a submodule [#656][]
  7 +* Build: Avoid a warning on CMake 3.22 [#656][]
  8 +* Build: Support compiling the tests with an external copy of Catch2 [#653][]
6 9
7 [#653]: https://github.com/CLIUtils/CLI11/pull/653 10 [#653]: https://github.com/CLIUtils/CLI11/pull/653
  11 +[#656]: https://github.com/CLIUtils/CLI11/pull/656
8 12
9 ## Version 2.1: Names and callbacks 13 ## Version 2.1: Names and callbacks
10 14
CMakeLists.txt
@@ -2,14 +2,14 @@ cmake_minimum_required(VERSION 3.4) @@ -2,14 +2,14 @@ cmake_minimum_required(VERSION 3.4)
2 # Note: this is a header only library. If you have an older CMake than 3.4, 2 # Note: this is a header only library. If you have an older CMake than 3.4,
3 # just add the CLI11/include directory and that's all you need to do. 3 # just add the CLI11/include directory and that's all you need to do.
4 4
5 -# Make sure users don't get warnings on a tested (3.4 to 3.21) version 5 +# Make sure users don't get warnings on a tested (3.4 to 3.22) version
6 # of CMake. For most of the policies, the new version is better (hence the change). 6 # of CMake. For most of the policies, the new version is better (hence the change).
7 # We don't use the 3.4...3.21 syntax because of a bug in an older MSVC's 7 # We don't use the 3.4...3.21 syntax because of a bug in an older MSVC's
8 # built-in and modified CMake 3.11 8 # built-in and modified CMake 3.11
9 -if(${CMAKE_VERSION} VERSION_LESS 3.21) 9 +if(${CMAKE_VERSION} VERSION_LESS 3.22)
10 cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) 10 cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
11 else() 11 else()
12 - cmake_policy(VERSION 3.21) 12 + cmake_policy(VERSION 3.22)
13 endif() 13 endif()
14 14
15 set(VERSION_REGEX "#define CLI11_VERSION[ \t]+\"(.+)\"") 15 set(VERSION_REGEX "#define CLI11_VERSION[ \t]+\"(.+)\"")
@@ -30,18 +30,29 @@ project( @@ -30,18 +30,29 @@ project(
30 # Print the version number of CMake if this is the main project 30 # Print the version number of CMake if this is the main project
31 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) 31 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
32 message(STATUS "CMake ${CMAKE_VERSION}") 32 message(STATUS "CMake ${CMAKE_VERSION}")
  33 +
  34 + find_package(Doxygen)
  35 +
  36 + if(CMAKE_VERSION VERSION_LESS 3.10)
  37 + message(STATUS "CMake 3.10+ adds Doxygen support. Update CMake to build documentation")
  38 + elseif(NOT Doxygen_FOUND)
  39 + message(STATUS "Doxygen not found, building docs has been disabled")
  40 + endif()
  41 +
  42 + include(CTest)
  43 +else()
  44 + if(NOT DEFINED BUILD_TESTING)
  45 + set(BUILD_TESTING OFF)
  46 + endif()
33 endif() 47 endif()
34 48
35 include(CMakeDependentOption) 49 include(CMakeDependentOption)
36 include(GNUInstallDirs) 50 include(GNUInstallDirs)
37 -include(CTest)  
38 51
39 if(NOT CMAKE_VERSION VERSION_LESS 3.11) 52 if(NOT CMAKE_VERSION VERSION_LESS 3.11)
40 include(FetchContent) 53 include(FetchContent)
41 endif() 54 endif()
42 55
43 -find_package(Doxygen)  
44 -  
45 list(APPEND force-libcxx "CMAKE_CXX_COMPILER_ID STREQUAL \"Clang\"") 56 list(APPEND force-libcxx "CMAKE_CXX_COMPILER_ID STREQUAL \"Clang\"")
46 list(APPEND force-libcxx "CMAKE_SYSTEM_NAME STREQUAL \"Linux\"") 57 list(APPEND force-libcxx "CMAKE_SYSTEM_NAME STREQUAL \"Linux\"")
47 list(APPEND force-libcxx "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME") 58 list(APPEND force-libcxx "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME")
@@ -118,12 +129,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) @@ -118,12 +129,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
118 set_property(GLOBAL PROPERTY USE_FOLDERS ON) 129 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
119 endif() 130 endif()
120 131
121 -if(CMAKE_VERSION VERSION_LESS 3.10)  
122 - message(STATUS "CMake 3.10+ adds Doxygen support. Update CMake to build documentation")  
123 -elseif(NOT Doxygen_FOUND)  
124 - message(STATUS "Doxygen not found, building docs has been disabled")  
125 -endif()  
126 -  
127 # Special target that adds warnings. Is not exported. 132 # Special target that adds warnings. Is not exported.
128 add_library(CLI11_warnings INTERFACE) 133 add_library(CLI11_warnings INTERFACE)
129 134
@@ -154,6 +159,22 @@ add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls @@ -154,6 +159,22 @@ add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls
154 target_include_directories(CLI11 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> 159 target_include_directories(CLI11 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
155 $<INSTALL_INTERFACE:include>) 160 $<INSTALL_INTERFACE:include>)
156 161
  162 +if(CMAKE_VERSION VERSION_LESS 3.8)
  163 + # This might not be a complete list
  164 + target_compile_features(
  165 + CLI11
  166 + INTERFACE cxx_lambdas
  167 + cxx_nullptr
  168 + cxx_override
  169 + cxx_range_for
  170 + cxx_right_angle_brackets
  171 + cxx_strong_enums
  172 + cxx_constexpr
  173 + cxx_auto_type)
  174 +else()
  175 + target_compile_features(CLI11 INTERFACE cxx_std_11)
  176 +endif()
  177 +
157 # To see in IDE, headers must be listed for target 178 # To see in IDE, headers must be listed for target
158 set(header-patterns "${PROJECT_SOURCE_DIR}/include/CLI/*") 179 set(header-patterns "${PROJECT_SOURCE_DIR}/include/CLI/*")
159 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT CMAKE_VERSION VERSION_LESS 3.12) 180 if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT CMAKE_VERSION VERSION_LESS 3.12)
@@ -254,6 +275,7 @@ if(CLI11_SINGLE_FILE) @@ -254,6 +275,7 @@ if(CLI11_SINGLE_FILE)
254 endif() 275 endif()
255 276
256 if(CLI11_BUILD_TESTS) 277 if(CLI11_BUILD_TESTS)
  278 + include(CTest)
257 add_subdirectory(tests) 279 add_subdirectory(tests)
258 endif() 280 endif()
259 281
README.md
@@ -2,16 +2,16 @@ @@ -2,16 +2,16 @@
2 2
3 ![CLI11 Logo](./docs/CLI11_300.png) 3 ![CLI11 Logo](./docs/CLI11_300.png)
4 4
5 -[![Build Status Linux and macOS][travis-badge]][travis]  
6 -[![Build Status Windows][appveyor-badge]][appveyor]  
7 [![Build Status Azure][azure-badge]][azure] 5 [![Build Status Azure][azure-badge]][azure]
8 [![Actions Status][actions-badge]][actions-link] 6 [![Actions Status][actions-badge]][actions-link]
9 [![Code Coverage][codecov-badge]][codecov] 7 [![Code Coverage][codecov-badge]][codecov]
10 [![Codacy Badge][codacy-badge]][codacy-link] 8 [![Codacy Badge][codacy-badge]][codacy-link]
11 -[![Gitter chat][gitter-badge]][gitter]  
12 [![License: BSD][license-badge]](./LICENSE) 9 [![License: BSD][license-badge]](./LICENSE)
13 -[![Latest release][releases-badge]][github releases]  
14 [![DOI][doi-badge]][doi-link] 10 [![DOI][doi-badge]][doi-link]
  11 +
  12 +[![Gitter chat][gitter-badge]][gitter]
  13 +[![Latest GHA release][releases-badge]][github releases]
  14 +[![Latest release][repology-badge]][repology]
15 [![Conan.io][conan-badge]][conan-link] 15 [![Conan.io][conan-badge]][conan-link]
16 [![Conda Version][conda-badge]][conda-link] 16 [![Conda Version][conda-badge]][conda-link]
17 [![Try CLI11 2.1 online][wandbox-badge]][wandbox-link] 17 [![Try CLI11 2.1 online][wandbox-badge]][wandbox-link]
@@ -64,7 +64,7 @@ Features that were added in the last released major version are marked with &quot;รฐลธโ€  @@ -64,7 +64,7 @@ Features that were added in the last released major version are marked with &quot;รฐลธโ€ 
64 ### Introduction 64 ### Introduction
65 65
66 CLI11 provides all the features you expect in a powerful command line parser, with a beautiful, minimal syntax and no dependencies beyond C++11. It is header only, and comes in a single file form for easy inclusion in projects. It is easy to use for small projects, but powerful enough for complex command line projects, and can be customized for frameworks. 66 CLI11 provides all the features you expect in a powerful command line parser, with a beautiful, minimal syntax and no dependencies beyond C++11. It is header only, and comes in a single file form for easy inclusion in projects. It is easy to use for small projects, but powerful enough for complex command line projects, and can be customized for frameworks.
67 -It is tested on [Travis][], [AppVeyor][], [Azure][], and [GitHub Actions][actions-link], and is used by the [GooFit GPU fitting framework][goofit]. It was inspired by [`plumbum.cli`][plumbum] for Python. CLI11 has a user friendly introduction in this README, a more in-depth tutorial [GitBook][], as well as [API documentation][api-docs] generated by Travis. 67 +It is tested on [Azure][] and [GitHub Actions][actions-link], and was originally used by the [GooFit GPU fitting framework][goofit]. It was inspired by [`plumbum.cli`][plumbum] for Python. CLI11 has a user friendly introduction in this README, a more in-depth tutorial [GitBook][], as well as [API documentation][api-docs] generated by Travis.
68 See the [changelog](./CHANGELOG.md) or [GitHub Releases][] for details for current and past releases. Also see the [Version 1.0 post][], [Version 1.3 post][], [Version 1.6 post][], or [Version 2.0 post][] for more information. 68 See the [changelog](./CHANGELOG.md) or [GitHub Releases][] for details for current and past releases. Also see the [Version 1.0 post][], [Version 1.3 post][], [Version 1.6 post][], or [Version 2.0 post][] for more information.
69 69
70 You can be notified when new releases are made by subscribing to <https://github.com/CLIUtils/CLI11/releases.atom> on an RSS reader, like Feedly, or use the releases mode of the GitHub watching tool. 70 You can be notified when new releases are made by subscribing to <https://github.com/CLIUtils/CLI11/releases.atom> on an RSS reader, like Feedly, or use the releases mode of the GitHub watching tool.
@@ -77,7 +77,7 @@ An acceptable CLI parser library should be all of the following: @@ -77,7 +77,7 @@ An acceptable CLI parser library should be all of the following:
77 * Short, simple syntax: This is one of the main reasons to use a CLI parser, it should make variables from the command line nearly as easy to define as any other variables. If most of your program is hidden in CLI parsing, this is a problem for readability. 77 * Short, simple syntax: This is one of the main reasons to use a CLI parser, it should make variables from the command line nearly as easy to define as any other variables. If most of your program is hidden in CLI parsing, this is a problem for readability.
78 * C++11 or better: Should work with GCC 4.8+ (default on CentOS/RHEL 7), Clang 3.4+, AppleClang 7+, NVCC 7.0+, or MSVC 2015+. 78 * C++11 or better: Should work with GCC 4.8+ (default on CentOS/RHEL 7), Clang 3.4+, AppleClang 7+, NVCC 7.0+, or MSVC 2015+.
79 * Work on Linux, macOS, and Windows. 79 * Work on Linux, macOS, and Windows.
80 -* Well tested using [Travis][] (Linux) and [AppVeyor][] (Windows) or [Azure][] (all three). "Well" is defined as having good coverage measured by [CodeCov][]. 80 +* Well tested on all common platforms and compilers. "Well" is defined as having good coverage measured by [CodeCov][].
81 * Clear help printing. 81 * Clear help printing.
82 * Nice error messages. 82 * Nice error messages.
83 * Standard shell idioms supported naturally, like grouping flags, a positional separator, etc. 83 * Standard shell idioms supported naturally, like grouping flags, a positional separator, etc.
@@ -128,7 +128,7 @@ So, this library was designed to provide a great syntax, good compiler compatibi @@ -128,7 +128,7 @@ So, this library was designed to provide a great syntax, good compiler compatibi
128 There are some other possible "features" that are intentionally not supported by this library: 128 There are some other possible "features" that are intentionally not supported by this library:
129 129
130 * Non-standard variations on syntax, like `-long` options. This is non-standard and should be avoided, so that is enforced by this library. 130 * Non-standard variations on syntax, like `-long` options. This is non-standard and should be avoided, so that is enforced by this library.
131 -* Completion of partial options, such as Python's `argparse` supplies for incomplete arguments. It's better not to guess. Most third party command line parsers for python actually reimplement command line parsing rather than using argparse because of this perceived design flaw. 131 +* Completion of partial options, such as Python's `argparse` supplies for incomplete arguments. It's better not to guess. Most third party command line parsers for python actually reimplement command line parsing rather than using argparse because of this perceived design flaw (recent versions do have an option to disable it).
132 * Autocomplete: This might eventually be added to both Plumbum and CLI11, but it is not supported yet. 132 * Autocomplete: This might eventually be added to both Plumbum and CLI11, but it is not supported yet.
133 * Wide strings / unicode: Since this uses the standard library only, it might be hard to properly implement, but I would be open to suggestions in how to do this. 133 * Wide strings / unicode: Since this uses the standard library only, it might be hard to properly implement, but I would be open to suggestions in how to do this.
134 134
@@ -139,7 +139,7 @@ To use, there are several methods: @@ -139,7 +139,7 @@ To use, there are several methods:
139 * All-in-one local header: Copy `CLI11.hpp` from the [most recent release][github releases] into your include directory, and you are set. This is combined from the source files for every release. This includes the entire command parser library, but does not include separate utilities (like `Timer`, `AutoTimer`). The utilities are completely self contained and can be copied separately. 139 * All-in-one local header: Copy `CLI11.hpp` from the [most recent release][github releases] into your include directory, and you are set. This is combined from the source files for every release. This includes the entire command parser library, but does not include separate utilities (like `Timer`, `AutoTimer`). The utilities are completely self contained and can be copied separately.
140 * All-in-one global header: Like above, but copying the file to a shared folder location like `/opt/CLI11`. Then, the C++ include path has to be extended to point at this folder. With CMake, use `include_directories(/opt/CLI11)` 140 * All-in-one global header: Like above, but copying the file to a shared folder location like `/opt/CLI11`. Then, the C++ include path has to be extended to point at this folder. With CMake, use `include_directories(/opt/CLI11)`
141 * Local headers and target: Use `CLI/*.hpp` files. You could check out the repository as a git submodule, for example. With CMake, you can use `add_subdirectory` and the `CLI11::CLI11` interface target when linking. If not using a submodule, you must ensure that the copied files are located inside the same tree directory than your current project, to prevent an error with CMake and `add_subdirectory`. 141 * Local headers and target: Use `CLI/*.hpp` files. You could check out the repository as a git submodule, for example. With CMake, you can use `add_subdirectory` and the `CLI11::CLI11` interface target when linking. If not using a submodule, you must ensure that the copied files are located inside the same tree directory than your current project, to prevent an error with CMake and `add_subdirectory`.
142 -* Global headers: Use `CLI/*.hpp` files stored in a shared folder. You could check out the git repository in a system-wide folder, for example `/opt/`. With CMake, you could add to the include path via: 142 +* Global headers: Use `CLI/*.hpp` files stored in a shared folder. You could check out the git repository to a system-wide folder, for example `/opt/`. With CMake, you could add to the include path via:
143 143
144 ```bash 144 ```bash
145 if(NOT DEFINED CLI11_DIR) 145 if(NOT DEFINED CLI11_DIR)
@@ -159,15 +159,27 @@ And then in the source code (adding several headers might be needed to prevent l @@ -159,15 +159,27 @@ And then in the source code (adding several headers might be needed to prevent l
159 * Global headers and target: configuring and installing the project is required for linking CLI11 to your project in the same way as you would do with any other external library. With CMake, this step allows using `find_package(CLI11 CONFIG REQUIRED)` and then using the `CLI11::CLI11` target when linking. If `CMAKE_INSTALL_PREFIX` was changed during install to a specific folder like `/opt/CLI11`, then you have to pass `-DCLI11_DIR=/opt/CLI11` when building your current project. You can also use [Conan.io][conan-link] or [Hunter][]. 159 * Global headers and target: configuring and installing the project is required for linking CLI11 to your project in the same way as you would do with any other external library. With CMake, this step allows using `find_package(CLI11 CONFIG REQUIRED)` and then using the `CLI11::CLI11` target when linking. If `CMAKE_INSTALL_PREFIX` was changed during install to a specific folder like `/opt/CLI11`, then you have to pass `-DCLI11_DIR=/opt/CLI11` when building your current project. You can also use [Conan.io][conan-link] or [Hunter][].
160 (These are just conveniences to allow you to use your favorite method of managing packages; it's just header only so including the correct path and 160 (These are just conveniences to allow you to use your favorite method of managing packages; it's just header only so including the correct path and
161 using C++11 is all you really need.) 161 using C++11 is all you really need.)
  162 +* Via FetchContent in CMake 3.14+ (or 3.11+ with more work): you can add this with fetch-content, then use the `CLI11::CLI11` target as above, and CMake will download the project in the configure stage:
  163 +
  164 +```cmake
  165 +include(FetchContent)
  166 +FetchContent_Declare(
  167 + cli11
  168 + GIT_REPOSITORY https://github.com/CLIUtils/CLI11
  169 + GIT_TAG v2.1.1
  170 +)
  171 +
  172 +FetchContent_MakeAvailable(cli11)
  173 +```
  174 +
  175 +It is highly recommended that you use the git hash for `GIT_TAG` instead of a tag or branch, as that will both be more secure, as well as faster to reconfigure - CMake will not have to reach out to the internet to see if the tag moved. You can also download just the single header file from the releases using `file(DOWNLOAD`.
162 176
163 To build the tests, checkout the repository and use CMake: 177 To build the tests, checkout the repository and use CMake:
164 178
165 ```bash 179 ```bash
166 -mkdir build  
167 -cd build  
168 -cmake ..  
169 -make  
170 -GTEST_COLOR=1 CTEST_OUTPUT_ON_FAILURE=1 make test 180 +cmake -S . -B build
  181 +cmake --build build
  182 +CTEST_OUTPUT_ON_FAILURE=1 cmake --build build -t test
171 ``` 183 ```
172 184
173 <details><summary>Note: Special instructions for GCC 8</summary><p> 185 <details><summary>Note: Special instructions for GCC 8</summary><p>
@@ -1010,12 +1022,10 @@ CLI11 was developed at the [University of Cincinnati][] to support of the [GooFi @@ -1010,12 +1022,10 @@ CLI11 was developed at the [University of Cincinnati][] to support of the [GooFi
1010 [doi-link]: https://zenodo.org/badge/latestdoi/80064252 1022 [doi-link]: https://zenodo.org/badge/latestdoi/80064252
1011 [azure-badge]: https://dev.azure.com/CLIUtils/CLI11/_apis/build/status/CLIUtils.CLI11?branchName=master 1023 [azure-badge]: https://dev.azure.com/CLIUtils/CLI11/_apis/build/status/CLIUtils.CLI11?branchName=master
1012 [azure]: https://dev.azure.com/CLIUtils/CLI11 1024 [azure]: https://dev.azure.com/CLIUtils/CLI11
1013 -[travis-badge]: https://img.shields.io/travis/CLIUtils/CLI11/master.svg?label=Linux/macOS  
1014 -[travis]: https://travis-ci.org/CLIUtils/CLI11  
1015 -[appveyor-badge]: https://img.shields.io/appveyor/ci/HenrySchreiner/cli11/master.svg?label=AppVeyor  
1016 -[appveyor]: https://ci.appveyor.com/project/HenrySchreiner/cli11  
1017 -[actions-badge]: https://github.com/CLIUtils/CLI11/workflows/Tests/badge.svg  
1018 -[actions-link]: https://github.com/CLIUtils/CLI11/actions 1025 +[actions-link]: https://github.com/CLIUtils/CLI11/actions
  1026 +[actions-badge]: https://github.com/CLIUtils/CLI11/actions/workflows/tests.yml/badge.svg
  1027 +[repology-badge]: https://repology.org/badge/latest-versions/cli11.svg
  1028 +[repology]: https://repology.org/project/cli11/versions
1019 [codecov-badge]: https://codecov.io/gh/CLIUtils/CLI11/branch/master/graph/badge.svg 1029 [codecov-badge]: https://codecov.io/gh/CLIUtils/CLI11/branch/master/graph/badge.svg
1020 [codecov]: https://codecov.io/gh/CLIUtils/CLI11 1030 [codecov]: https://codecov.io/gh/CLIUtils/CLI11
1021 [gitter-badge]: https://badges.gitter.im/CLI11gitter/Lobby.svg 1031 [gitter-badge]: https://badges.gitter.im/CLI11gitter/Lobby.svg