Skip to content

Commit a393e35

Browse files
authored
fix(build): simplify runs from master projects, require C++11 minimally if possible (#656)
1 parent 229844f commit a393e35

File tree

5 files changed

+77
-36
lines changed

5 files changed

+77
-36
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ on:
33
push:
44
branches:
55
- master
6+
- main
67
- v*
78
tags:
89
- "*"
910
pull_request:
10-
branches:
11-
- master
1211

1312
jobs:
1413
single-header:

.github/workflows/tests.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ on:
33
push:
44
branches:
55
- master
6+
- main
67
- v*
78
pull_request:
8-
branches:
9-
- master
109

1110
jobs:
1211
cuda-build:
@@ -161,3 +160,10 @@ jobs:
161160
cmake-version: "3.21"
162161
args: -DCLI11_SANITIZERS=ON -DCLI11_BUILD_EXAMPLES_JSON=ON
163162
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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
## WIP
44

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][]
69

710
[#653]: https://github.com/CLIUtils/CLI11/pull/653
11+
[#656]: https://github.com/CLIUtils/CLI11/pull/656
812

913
## Version 2.1: Names and callbacks
1014

CMakeLists.txt

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ cmake_minimum_required(VERSION 3.4)
22
# Note: this is a header only library. If you have an older CMake than 3.4,
33
# just add the CLI11/include directory and that's all you need to do.
44

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
66
# of CMake. For most of the policies, the new version is better (hence the change).
77
# We don't use the 3.4...3.21 syntax because of a bug in an older MSVC's
88
# built-in and modified CMake 3.11
9-
if(${CMAKE_VERSION} VERSION_LESS 3.21)
9+
if(${CMAKE_VERSION} VERSION_LESS 3.22)
1010
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
1111
else()
12-
cmake_policy(VERSION 3.21)
12+
cmake_policy(VERSION 3.22)
1313
endif()
1414

1515
set(VERSION_REGEX "#define CLI11_VERSION[ \t]+\"(.+)\"")
@@ -30,18 +30,29 @@ project(
3030
# Print the version number of CMake if this is the main project
3131
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
3232
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()
3347
endif()
3448

3549
include(CMakeDependentOption)
3650
include(GNUInstallDirs)
37-
include(CTest)
3851

3952
if(NOT CMAKE_VERSION VERSION_LESS 3.11)
4053
include(FetchContent)
4154
endif()
4255

43-
find_package(Doxygen)
44-
4556
list(APPEND force-libcxx "CMAKE_CXX_COMPILER_ID STREQUAL \"Clang\"")
4657
list(APPEND force-libcxx "CMAKE_SYSTEM_NAME STREQUAL \"Linux\"")
4758
list(APPEND force-libcxx "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME")
@@ -118,12 +129,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
118129
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
119130
endif()
120131

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-
127132
# Special target that adds warnings. Is not exported.
128133
add_library(CLI11_warnings INTERFACE)
129134

@@ -154,6 +159,22 @@ add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls
154159
target_include_directories(CLI11 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
155160
$<INSTALL_INTERFACE:include>)
156161

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+
157178
# To see in IDE, headers must be listed for target
158179
set(header-patterns "${PROJECT_SOURCE_DIR}/include/CLI/*")
159180
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT CMAKE_VERSION VERSION_LESS 3.12)
@@ -254,6 +275,7 @@ if(CLI11_SINGLE_FILE)
254275
endif()
255276

256277
if(CLI11_BUILD_TESTS)
278+
include(CTest)
257279
add_subdirectory(tests)
258280
endif()
259281

README.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
![CLI11 Logo](./docs/CLI11_300.png)
44

5-
[![Build Status Linux and macOS][travis-badge]][travis]
6-
[![Build Status Windows][appveyor-badge]][appveyor]
75
[![Build Status Azure][azure-badge]][azure]
86
[![Actions Status][actions-badge]][actions-link]
97
[![Code Coverage][codecov-badge]][codecov]
108
[![Codacy Badge][codacy-badge]][codacy-link]
11-
[![Gitter chat][gitter-badge]][gitter]
129
[![License: BSD][license-badge]](./LICENSE)
13-
[![Latest release][releases-badge]][github releases]
1410
[![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]
1515
[![Conan.io][conan-badge]][conan-link]
1616
[![Conda Version][conda-badge]][conda-link]
1717
[![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 "
6464
### Introduction
6565

6666
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.
6868
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.
6969

7070
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:
7777
* 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.
7878
* 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+.
7979
* 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][].
8181
* Clear help printing.
8282
* Nice error messages.
8383
* 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
128128
There are some other possible "features" that are intentionally not supported by this library:
129129

130130
* 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).
132132
* Autocomplete: This might eventually be added to both Plumbum and CLI11, but it is not supported yet.
133133
* 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.
134134

@@ -139,7 +139,7 @@ To use, there are several methods:
139139
* 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.
140140
* 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)`
141141
* 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:
143143

144144
```bash
145145
if(NOT DEFINED CLI11_DIR)
@@ -159,15 +159,27 @@ And then in the source code (adding several headers might be needed to prevent l
159159
* 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][].
160160
(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
161161
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`.
162176

163177
To build the tests, checkout the repository and use CMake:
164178

165179
```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
171183
```
172184

173185
<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
10101022
[doi-link]: https://zenodo.org/badge/latestdoi/80064252
10111023
[azure-badge]: https://dev.azure.com/CLIUtils/CLI11/_apis/build/status/CLIUtils.CLI11?branchName=master
10121024
[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
10191029
[codecov-badge]: https://codecov.io/gh/CLIUtils/CLI11/branch/master/graph/badge.svg
10201030
[codecov]: https://codecov.io/gh/CLIUtils/CLI11
10211031
[gitter-badge]: https://badges.gitter.im/CLI11gitter/Lobby.svg

0 commit comments

Comments
 (0)