Skip to content

Commit

Permalink
Adding support for conan.io (#83)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
henryiii authored Mar 9, 2018
1 parent 5186158 commit f089255
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ branches:
install:
- set PATH=C:\Python36;%PATH%
- cmake --version
- pip install conan
- conan user
- conan --version

build_script:
- mkdir build
- cd build
- cmake .. -DCLI_SINGLE_FILE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_GENERATOR="Visual Studio 14 2015"
- cmake --build .
- cd ..
- conan create . CLIUtils/CLI11

test_script:
- ctest --output-on-failure -C Debug
Expand Down
1 change: 1 addition & 0 deletions .ci/run_codecov.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set -evx

cd ${TRAVIS_BUILD_DIR}
mkdir -p build
cd build
cmake .. -DCLI_SINGLE_FILE_TESTS=OFF -DCLI_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Coverage
cmake --build . -- -j2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
a.out*
*.swp
/*build*
/test_package/build
/Makefile
/CMakeFiles/*
/cmake_install.cmake
50 changes: 29 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,25 @@ matrix:
- clang-tidy-3.9
env:
- COMPILER=3.9
- CHECK_STYLE=yes
- CLI_CXX_STD=14
script:
- cd "${TRAVIS_BUILD_DIR}"
- scripts/check_style.sh
- .ci/check_tidy.sh
- compiler: clang
addons:
apt:
packages:
- clang-3.5
env:
- COMPILER=3.5
- DEPLOY_MAT=yes
- DOXYFILE=$TRAVIS_BUILD_DIR/docs/Doxyfile
after_success:
- |
if [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ]
then
echo "Updating docs" && cd $TRAVIS_BUILD_DIR && .ci/build_docs.sh
fi
- compiler: gcc
addons:
apt:
Expand All @@ -52,47 +60,47 @@ matrix:
- lcov
env:
- COMPILER=6
- COVERALLS=yes
- CLI_CXX_STD=14
before_install:
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- cd $TRAVIS_BUILD_DIR
- . .ci/build_lcov.sh
- .ci/run_codecov.sh
- compiler: gcc
addons:
apt:
packages:
- g++-4.7
env:
- COMPILER=4.7
before_install:
- python -m pip install --user conan
- conan user
after_success:
- conan create . CLIUtils/CLI11
- os: osx
compiler: clang
before_install:
- brew update
- echo 'brew "python"' > Brewfile
- echo 'brew "conan"' >> Brewfile
- brew bundle
- python -m ensurepip --user
- conan user
after_success:
- conan create . CLIUtils/CLI11
install:
- python -c 'import sys; print(sys.version_info[:])'
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd $TRAVIS_BUILD_DIR && . .ci/prepare_altern.sh ; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_cmake.sh ; fi
- if [ "$TRAVIS_OS_NAME" = "linux" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_doxygen.sh ; fi
- if [ -n "$COVERALLS" ] ; then cd $TRAVIS_BUILD_DIR && . .ci/build_lcov.sh ; fi
- cd "${DEPS_DIR}"
- if [ "$(python -c 'import sys; print(sys.version_info[0])')" = "2" ] ; then python -m pip install --user pathlib ; fi
- cmake --version
script:
- cd "${TRAVIS_BUILD_DIR}"
- |
if [ -n "$CHECK_STYLE" ]
then
scripts/check_style.sh
.ci/check_tidy.sh
else
.ci/travis.sh
fi
after_success:
- if [ -n "$COVERALLS" ] ; then cd $TRAVIS_BUILD_DIR && .ci/run_codecov.sh ; fi
- echo "${TRAVIS_BRANCH}"
- echo "${TRAVIS_PULL_REQUEST}"
- |
if [ "${TRAVIS_BRANCH}" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" == "false" ] && [ -n "$DEPLOY_MAT" ]
then
echo "Updating docs" && cd $TRAVIS_BUILD_DIR && .ci/build_docs.sh
fi
- .ci/travis.sh
deploy:
provider: releases
api_key:
Expand Down
39 changes: 36 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.4 FATAL_ERROR)

project(CLI11 CXX)
project(CLI11 LANGUAGES CXX)

SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

set(CLI_CXX_STD "11" CACHE STRING "The CMake standard to require")

Expand Down Expand Up @@ -51,10 +51,43 @@ endif()

file(GLOB CLI_headers "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/*")
# To see in IDE, must be listed for target

add_library(CLI11 INTERFACE)
target_include_directories(CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")

# Duplicated because CMake adds the current source dir if you don't.
target_include_directories(CLI11 INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

# Make add_subdirectory work like find_package
add_library(CLI11::CLI11 ALIAS CLI11)

# This folder should be installed
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/CLI DESTINATION include)

# Use find_package on the installed package
# Since we have no custom code, we can directly write this
# to Config.cmake (otherwise we'd have a custom config and would
# import Targets.cmake

# Make an export target
install(TARGETS CLI11
EXPORT CLI11Targets)

# Install the export target as a file
install(EXPORT CLI11Targets
FILE CLI11Config.cmake
NAMESPACE CLI11::
DESTINATION lib/cmake/CLI11)

# Use find_package on the installed package
export(TARGETS CLI11
NAMESPACE CLI11::
FILE CLI11Targets.cmake)

# Register in the user cmake package registry
export(PACKAGE CLI11)

# Single file test
find_package(PythonInterp)
if(CUR_PROJ AND PYTHONINTERP_FOUND)
Expand Down
2 changes: 1 addition & 1 deletion cmake/AddGoogletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ download_project(PROJ googletest
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_SOURCE_DIR})
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_SOURCE_DIR} EXCLUDE_FROM_ALL)

if (CMAKE_CONFIGURATION_TYPES)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}
Expand Down
23 changes: 23 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from conans import ConanFile, CMake

class HelloConan(ConanFile):
name = "CLI11"
version = "1.3.0"
url = "https://github.com/CLIUtils/CLI11"
settings = "os", "compiler", "arch", "build_type"
license = "BSD 3 clause"
description = "Command Line Interface toolkit for C++11"

exports_sources = "LICENCE", "include/*", "cmake/*", "CMakeLists.txt", "tests/*"

def build(self): # this is not building a library, just tests
cmake = CMake(self)
cmake.definitions["CLI_EXAMPLES"] = "OFF"
cmake.definitions["CLI_SINGLE_FILE"] = "OFF"
cmake.configure()
cmake.build()
cmake.test()
cmake.install()

def package_id(self):
self.info.header_only()
16 changes: 16 additions & 0 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
project(PackageTest CXX)
cmake_minimum_required(VERSION 3.1)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

message(STATUS "${CMAKE_PREFIX_PATH}")

find_package(CLI11 CONFIG REQUIRED)

add_executable(example example.cpp)
target_link_libraries(example CLI11::CLI11)
19 changes: 19 additions & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake
import os

class HelloTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def imports(self):
self.copy("*.dll", dst="bin", src="bin")
self.copy("*.dylib*", dst="bin", src="lib")

def test(self):
os.chdir("bin")
self.run(".%sexample" % os.sep)
20 changes: 20 additions & 0 deletions test_package/example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is a "Hello, world!" CLI11 program

#include "CLI/CLI.hpp"

#include <iostream>

int main(int argc, char **argv) {

CLI::App app("Some nice discription");

int x = 0;
app.add_option("-x", x, "an integer value", true /* show default */);

bool flag;
app.add_flag("-f,--flag", flag, "a flag option");

CLI11_PARSE(app, argc, argv);

return 0;
}

0 comments on commit f089255

Please sign in to comment.