Commit f089255ad04fd3306ebca7d9dcc46b215202ece6
Committed by
GitHub
1 parent
51861584
Adding support for conan.io (#83)
* Adding fix for #75, rename requires to needs * Removing check for install commands (should still be run in subproject) * Adding conan build * Some small changes to CMake * Adding nicer Travis code * Adding package test, find works now
Showing
10 changed files
with
151 additions
and
25 deletions
.appveyor.yml
| ... | ... | @@ -5,12 +5,17 @@ branches: |
| 5 | 5 | install: |
| 6 | 6 | - set PATH=C:\Python36;%PATH% |
| 7 | 7 | - cmake --version |
| 8 | + - pip install conan | |
| 9 | + - conan user | |
| 10 | + - conan --version | |
| 8 | 11 | |
| 9 | 12 | build_script: |
| 10 | 13 | - mkdir build |
| 11 | 14 | - cd build |
| 12 | 15 | - cmake .. -DCLI_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_GENERATOR="Visual Studio 14 2015" |
| 13 | 16 | - cmake --build . |
| 17 | + - cd .. | |
| 18 | + - conan create . CLIUtils/CLI11 | |
| 14 | 19 | |
| 15 | 20 | test_script: |
| 16 | 21 | - ctest --output-on-failure -C Debug | ... | ... |
.ci/run_codecov.sh
.gitignore
.travis.yml
| ... | ... | @@ -30,8 +30,11 @@ matrix: |
| 30 | 30 | - clang-tidy-3.9 |
| 31 | 31 | env: |
| 32 | 32 | - COMPILER=3.9 |
| 33 | - - CHECK_STYLE=yes | |
| 34 | 33 | - CLI_CXX_STD=14 |
| 34 | + script: | |
| 35 | + - cd "${TRAVIS_BUILD_DIR}" | |
| 36 | + - scripts/check_style.sh | |
| 37 | + - .ci/check_tidy.sh | |
| 35 | 38 | - compiler: clang |
| 36 | 39 | addons: |
| 37 | 40 | apt: |
| ... | ... | @@ -39,8 +42,13 @@ matrix: |
| 39 | 42 | - clang-3.5 |
| 40 | 43 | env: |
| 41 | 44 | - COMPILER=3.5 |
| 42 | - - DEPLOY_MAT=yes | |
| 43 | 45 | - DOXYFILE=$TRAVIS_BUILD_DIR/docs/Doxyfile |
| 46 | + after_success: | |
| 47 | + - | | |
| 48 | + if [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ] | |
| 49 | + then | |
| 50 | + echo "Updating docs" && cd $TRAVIS_BUILD_DIR && .ci/build_docs.sh | |
| 51 | + fi | |
| 44 | 52 | - compiler: gcc |
| 45 | 53 | addons: |
| 46 | 54 | apt: |
| ... | ... | @@ -52,8 +60,12 @@ matrix: |
| 52 | 60 | - lcov |
| 53 | 61 | env: |
| 54 | 62 | - COMPILER=6 |
| 55 | - - COVERALLS=yes | |
| 56 | 63 | - CLI_CXX_STD=14 |
| 64 | + before_install: | |
| 65 | + - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" | |
| 66 | + - cd $TRAVIS_BUILD_DIR | |
| 67 | + - . .ci/build_lcov.sh | |
| 68 | + - .ci/run_codecov.sh | |
| 57 | 69 | - compiler: gcc |
| 58 | 70 | addons: |
| 59 | 71 | apt: |
| ... | ... | @@ -61,38 +73,34 @@ matrix: |
| 61 | 73 | - g++-4.7 |
| 62 | 74 | env: |
| 63 | 75 | - COMPILER=4.7 |
| 76 | + before_install: | |
| 77 | + - python -m pip install --user conan | |
| 78 | + - conan user | |
| 79 | + after_success: | |
| 80 | + - conan create . CLIUtils/CLI11 | |
| 64 | 81 | - os: osx |
| 82 | + compiler: clang | |
| 65 | 83 | before_install: |
| 84 | + - brew update | |
| 85 | + - echo 'brew "python"' > Brewfile | |
| 86 | + - echo 'brew "conan"' >> Brewfile | |
| 87 | + - brew bundle | |
| 66 | 88 | - python -m ensurepip --user |
| 89 | + - conan user | |
| 90 | + after_success: | |
| 91 | + - conan create . CLIUtils/CLI11 | |
| 67 | 92 | install: |
| 68 | 93 | - python -c 'import sys; print(sys.version_info[:])' |
| 69 | 94 | - DEPS_DIR="${TRAVIS_BUILD_DIR}/deps" |
| 70 | 95 | - if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd $TRAVIS_BUILD_DIR && . .ci/prepare_altern.sh ; fi |
| 71 | 96 | - if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_cmake.sh ; fi |
| 72 | 97 | - if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_doxygen.sh ; fi |
| 73 | -- if [ -n "$COVERALLS" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_lcov.sh ; fi | |
| 74 | 98 | - cd "${DEPS_DIR}" |
| 75 | 99 | - if [ "$(python -c 'import sys; print(sys.version_info[0])')" = "2" ] ; then python -m pip install --user pathlib ; fi |
| 76 | 100 | - cmake --version |
| 77 | 101 | script: |
| 78 | 102 | - cd "${TRAVIS_BUILD_DIR}" |
| 79 | -- | | |
| 80 | - if [ -n "$CHECK_STYLE" ] | |
| 81 | - then | |
| 82 | - scripts/check_style.sh | |
| 83 | - .ci/check_tidy.sh | |
| 84 | - else | |
| 85 | - .ci/travis.sh | |
| 86 | - fi | |
| 87 | -after_success: | |
| 88 | -- if [ -n "$COVERALLS" ] ; then cd $TRAVIS_BUILD_DIR && .ci/run_codecov.sh ; fi | |
| 89 | -- echo "${TRAVIS_BRANCH}" | |
| 90 | -- echo "${TRAVIS_PULL_REQUEST}" | |
| 91 | -- | | |
| 92 | - if [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ] && [ -n "$DEPLOY_MAT" ] | |
| 93 | - then | |
| 94 | - echo "Updating docs" && cd $TRAVIS_BUILD_DIR && .ci/build_docs.sh | |
| 95 | - fi | |
| 103 | +- .ci/travis.sh | |
| 96 | 104 | deploy: |
| 97 | 105 | provider: releases |
| 98 | 106 | api_key: | ... | ... |
CMakeLists.txt
| 1 | 1 | cmake_minimum_required(VERSION 3.4 FATAL_ERROR) |
| 2 | 2 | |
| 3 | -project(CLI11 CXX) | |
| 3 | +project(CLI11 LANGUAGES CXX) | |
| 4 | 4 | |
| 5 | -SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) | |
| 5 | +SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) | |
| 6 | 6 | |
| 7 | 7 | set(CLI_CXX_STD "11" CACHE STRING "The CMake standard to require") |
| 8 | 8 | |
| ... | ... | @@ -51,10 +51,43 @@ endif() |
| 51 | 51 | |
| 52 | 52 | file(GLOB CLI_headers "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/*") |
| 53 | 53 | # To see in IDE, must be listed for target |
| 54 | + | |
| 54 | 55 | add_library(CLI11 INTERFACE) |
| 55 | -target_include_directories(CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") | |
| 56 | + | |
| 57 | +# Duplicated because CMake adds the current source dir if you don't. | |
| 58 | +target_include_directories(CLI11 INTERFACE | |
| 59 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | |
| 60 | + $<INSTALL_INTERFACE:include>) | |
| 61 | + | |
| 62 | +# Make add_subdirectory work like find_package | |
| 63 | +add_library(CLI11::CLI11 ALIAS CLI11) | |
| 64 | + | |
| 65 | +# This folder should be installed | |
| 56 | 66 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/CLI DESTINATION include) |
| 57 | 67 | |
| 68 | +# Use find_package on the installed package | |
| 69 | +# Since we have no custom code, we can directly write this | |
| 70 | +# to Config.cmake (otherwise we'd have a custom config and would | |
| 71 | +# import Targets.cmake | |
| 72 | + | |
| 73 | +# Make an export target | |
| 74 | +install(TARGETS CLI11 | |
| 75 | + EXPORT CLI11Targets) | |
| 76 | + | |
| 77 | +# Install the export target as a file | |
| 78 | +install(EXPORT CLI11Targets | |
| 79 | + FILE CLI11Config.cmake | |
| 80 | + NAMESPACE CLI11:: | |
| 81 | + DESTINATION lib/cmake/CLI11) | |
| 82 | + | |
| 83 | +# Use find_package on the installed package | |
| 84 | +export(TARGETS CLI11 | |
| 85 | + NAMESPACE CLI11:: | |
| 86 | + FILE CLI11Targets.cmake) | |
| 87 | + | |
| 88 | +# Register in the user cmake package registry | |
| 89 | +export(PACKAGE CLI11) | |
| 90 | + | |
| 58 | 91 | # Single file test |
| 59 | 92 | find_package(PythonInterp) |
| 60 | 93 | if(CUR_PROJ AND PYTHONINTERP_FOUND) | ... | ... |
cmake/AddGoogletest.cmake
| ... | ... | @@ -15,7 +15,7 @@ download_project(PROJ googletest |
| 15 | 15 | ) |
| 16 | 16 | |
| 17 | 17 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 18 | -add_subdirectory(${googletest_SOURCE_DIR} ${googletest_SOURCE_DIR}) | |
| 18 | +add_subdirectory(${googletest_SOURCE_DIR} ${googletest_SOURCE_DIR} EXCLUDE_FROM_ALL) | |
| 19 | 19 | |
| 20 | 20 | if (CMAKE_CONFIGURATION_TYPES) |
| 21 | 21 | add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} | ... | ... |
conanfile.py
0 → 100644
| 1 | +from conans import ConanFile, CMake | |
| 2 | + | |
| 3 | +class HelloConan(ConanFile): | |
| 4 | + name = "CLI11" | |
| 5 | + version = "1.3.0" | |
| 6 | + url = "https://github.com/CLIUtils/CLI11" | |
| 7 | + settings = "os", "compiler", "arch", "build_type" | |
| 8 | + license = "BSD 3 clause" | |
| 9 | + description = "Command Line Interface toolkit for C++11" | |
| 10 | + | |
| 11 | + exports_sources = "LICENCE", "include/*", "cmake/*", "CMakeLists.txt", "tests/*" | |
| 12 | + | |
| 13 | + def build(self): # this is not building a library, just tests | |
| 14 | + cmake = CMake(self) | |
| 15 | + cmake.definitions["CLI_EXAMPLES"] = "OFF" | |
| 16 | + cmake.definitions["CLI_SINGLE_FILE"] = "OFF" | |
| 17 | + cmake.configure() | |
| 18 | + cmake.build() | |
| 19 | + cmake.test() | |
| 20 | + cmake.install() | |
| 21 | + | |
| 22 | + def package_id(self): | |
| 23 | + self.info.header_only() | ... | ... |
test_package/CMakeLists.txt
0 → 100644
| 1 | +project(PackageTest CXX) | |
| 2 | +cmake_minimum_required(VERSION 3.1) | |
| 3 | + | |
| 4 | +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | |
| 5 | +conan_basic_setup() | |
| 6 | + | |
| 7 | +set(CMAKE_CXX_STANDARD 11) | |
| 8 | +set(CMAKE_CXX_EXTENSIONS OFF) | |
| 9 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
| 10 | + | |
| 11 | +message(STATUS "${CMAKE_PREFIX_PATH}") | |
| 12 | + | |
| 13 | +find_package(CLI11 CONFIG REQUIRED) | |
| 14 | + | |
| 15 | +add_executable(example example.cpp) | |
| 16 | +target_link_libraries(example CLI11::CLI11) | ... | ... |
test_package/conanfile.py
0 → 100644
| 1 | +from conans import ConanFile, CMake | |
| 2 | +import os | |
| 3 | + | |
| 4 | +class HelloTestConan(ConanFile): | |
| 5 | + settings = "os", "compiler", "build_type", "arch" | |
| 6 | + generators = "cmake" | |
| 7 | + | |
| 8 | + def build(self): | |
| 9 | + cmake = CMake(self) | |
| 10 | + cmake.configure() | |
| 11 | + cmake.build() | |
| 12 | + | |
| 13 | + def imports(self): | |
| 14 | + self.copy("*.dll", dst="bin", src="bin") | |
| 15 | + self.copy("*.dylib*", dst="bin", src="lib") | |
| 16 | + | |
| 17 | + def test(self): | |
| 18 | + os.chdir("bin") | |
| 19 | + self.run(".%sexample" % os.sep) | ... | ... |
test_package/example.cpp
0 → 100644
| 1 | +// This file is a "Hello, world!" CLI11 program | |
| 2 | + | |
| 3 | +#include "CLI/CLI.hpp" | |
| 4 | + | |
| 5 | +#include <iostream> | |
| 6 | + | |
| 7 | +int main(int argc, char **argv) { | |
| 8 | + | |
| 9 | + CLI::App app("Some nice discription"); | |
| 10 | + | |
| 11 | + int x = 0; | |
| 12 | + app.add_option("-x", x, "an integer value", true /* show default */); | |
| 13 | + | |
| 14 | + bool flag; | |
| 15 | + app.add_flag("-f,--flag", flag, "a flag option"); | |
| 16 | + | |
| 17 | + CLI11_PARSE(app, argc, argv); | |
| 18 | + | |
| 19 | + return 0; | |
| 20 | +} | ... | ... |