diff --git a/CHANGELOG.md b/CHANGELOG.md index 2540ce2d6..9666aa5f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,12 @@ ## WIP -* Support compiling the tests with an external copy of Catch2. [#653][] +* Bugfix(cmake): Enforce at least C++11 when using CMake target [#656][] +* Build: Don't run doxygen and CTest includes if a submodule [#653][] +* Build: Support compiling the tests with an external copy of Catch2 [#653][] [#653]: https://github.com/CLIUtils/CLI11/pull/653 +[#656]: https://github.com/CLIUtils/CLI11/pull/656 ## Version 2.1: Names and callbacks diff --git a/CMakeLists.txt b/CMakeLists.txt index 3227e409d..ffa3b50c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,18 +30,29 @@ project( # Print the version number of CMake if this is the main project if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) message(STATUS "CMake ${CMAKE_VERSION}") + + find_package(Doxygen) + + if(CMAKE_VERSION VERSION_LESS 3.10) + message(STATUS "CMake 3.10+ adds Doxygen support. Update CMake to build documentation") + elseif(NOT Doxygen_FOUND) + message(STATUS "Doxygen not found, building docs has been disabled") + endif() + + include(CTest) +else() + if(NOT DEFINED BUILD_TESTING) + set(BUILD_TESTING OFF) + endif() endif() include(CMakeDependentOption) include(GNUInstallDirs) -include(CTest) if(NOT CMAKE_VERSION VERSION_LESS 3.11) include(FetchContent) endif() -find_package(Doxygen) - list(APPEND force-libcxx "CMAKE_CXX_COMPILER_ID STREQUAL \"Clang\"") list(APPEND force-libcxx "CMAKE_SYSTEM_NAME STREQUAL \"Linux\"") list(APPEND force-libcxx "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME") @@ -118,12 +129,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set_property(GLOBAL PROPERTY USE_FOLDERS ON) endif() -if(CMAKE_VERSION VERSION_LESS 3.10) - message(STATUS "CMake 3.10+ adds Doxygen support. Update CMake to build documentation") -elseif(NOT Doxygen_FOUND) - message(STATUS "Doxygen not found, building docs has been disabled") -endif() - # Special target that adds warnings. Is not exported. add_library(CLI11_warnings INTERFACE) @@ -154,6 +159,22 @@ add_library(CLI11::CLI11 ALIAS CLI11) # for add_subdirectory calls target_include_directories(CLI11 INTERFACE $ $) +if(CMAKE_VERSION VERSION_LESS 3.8) + # This might not be a complete list + target_compile_features( + CLI11 + INTERFACE cxx_lambdas + cxx_nullptr + cxx_override + cxx_range_for + cxx_right_angle_brackets + cxx_strong_enums + cxx_constexpr + cxx_auto_type) +else() + target_compile_features(CLI11 INTERFACE cxx_std_11) +endif() + # To see in IDE, headers must be listed for target set(header-patterns "${PROJECT_SOURCE_DIR}/include/CLI/*") if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND NOT CMAKE_VERSION VERSION_LESS 3.12) @@ -254,6 +275,7 @@ if(CLI11_SINGLE_FILE) endif() if(CLI11_BUILD_TESTS) + include(CTest) add_subdirectory(tests) endif() diff --git a/README.md b/README.md index d6508443b..d63bfeb5c 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,16 @@ ![CLI11 Logo](./docs/CLI11_300.png) -[![Build Status Linux and macOS][travis-badge]][travis] -[![Build Status Windows][appveyor-badge]][appveyor] [![Build Status Azure][azure-badge]][azure] [![Actions Status][actions-badge]][actions-link] [![Code Coverage][codecov-badge]][codecov] [![Codacy Badge][codacy-badge]][codacy-link] -[![Gitter chat][gitter-badge]][gitter] [![License: BSD][license-badge]](./LICENSE) -[![Latest release][releases-badge]][github releases] [![DOI][doi-badge]][doi-link] + +[![Gitter chat][gitter-badge]][gitter] +[![Latest GHA release][releases-badge]][github releases] +[![Latest release][repology-badge]][repology] [![Conan.io][conan-badge]][conan-link] [![Conda Version][conda-badge]][conda-link] [![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 " ### Introduction 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. -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. +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. 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. You can be notified when new releases are made by subscribing to 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: * 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. * 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+. * Work on Linux, macOS, and Windows. -* Well tested using [Travis][] (Linux) and [AppVeyor][] (Windows) or [Azure][] (all three). "Well" is defined as having good coverage measured by [CodeCov][]. +* Well tested on all common platforms and compilers. "Well" is defined as having good coverage measured by [CodeCov][]. * Clear help printing. * Nice error messages. * 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 There are some other possible "features" that are intentionally not supported by this library: * Non-standard variations on syntax, like `-long` options. This is non-standard and should be avoided, so that is enforced by this library. -* 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. +* 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). * Autocomplete: This might eventually be added to both Plumbum and CLI11, but it is not supported yet. * 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. @@ -139,7 +139,7 @@ To use, there are several methods: * 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. * 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)` * 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`. -* 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: +* 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: ```bash if(NOT DEFINED CLI11_DIR) @@ -159,15 +159,27 @@ And then in the source code (adding several headers might be needed to prevent l * 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][]. (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 using C++11 is all you really need.) +* 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: + +```cmake +include(FetchContent) +FetchContent_Declare( + cli11 + GIT_REPOSITORY https://github.com/CLIUtils/CLI11 + GIT_TAG v2.1.1 +) + +FetchContent_MakeAvailable(cli11) +``` + +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`. To build the tests, checkout the repository and use CMake: ```bash -mkdir build -cd build -cmake .. -make -GTEST_COLOR=1 CTEST_OUTPUT_ON_FAILURE=1 make test +cmake -S . -B build +cmake --build build +CTEST_OUTPUT_ON_FAILURE=1 cmake --build build -t test ```
Note: Special instructions for GCC 8

@@ -1010,12 +1022,10 @@ CLI11 was developed at the [University of Cincinnati][] to support of the [GooFi [doi-link]: https://zenodo.org/badge/latestdoi/80064252 [azure-badge]: https://dev.azure.com/CLIUtils/CLI11/_apis/build/status/CLIUtils.CLI11?branchName=master [azure]: https://dev.azure.com/CLIUtils/CLI11 -[travis-badge]: https://img.shields.io/travis/CLIUtils/CLI11/master.svg?label=Linux/macOS -[travis]: https://travis-ci.org/CLIUtils/CLI11 -[appveyor-badge]: https://img.shields.io/appveyor/ci/HenrySchreiner/cli11/master.svg?label=AppVeyor -[appveyor]: https://ci.appveyor.com/project/HenrySchreiner/cli11 -[actions-badge]: https://github.com/CLIUtils/CLI11/workflows/Tests/badge.svg -[actions-link]: https://github.com/CLIUtils/CLI11/actions +[actions-link]: https://github.com/CLIUtils/CLI11/actions +[actions-badge]: https://github.com/CLIUtils/CLI11/actions/workflows/tests.yml/badge.svg +[repology-badge]: https://repology.org/badge/latest-versions/cli11.svg +[repology]: https://repology.org/project/cli11/versions [codecov-badge]: https://codecov.io/gh/CLIUtils/CLI11/branch/master/graph/badge.svg [codecov]: https://codecov.io/gh/CLIUtils/CLI11 [gitter-badge]: https://badges.gitter.im/CLI11gitter/Lobby.svg