diff --git a/recipes/cli11/all/conandata.yml b/recipes/cli11/all/conandata.yml new file mode 100644 index 0000000..5c3db6a --- /dev/null +++ b/recipes/cli11/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "2.5.0": + url: "https://github.com/CLIUtils/CLI11/archive/v2.5.0.tar.gz" + sha256: "17e02b4cddc2fa348e5dbdbb582c59a3486fa2b2433e70a0c3bacb871334fd55" \ No newline at end of file diff --git a/recipes/cli11/all/conanfile.py b/recipes/cli11/all/conanfile.py new file mode 100644 index 0000000..9b075b1 --- /dev/null +++ b/recipes/cli11/all/conanfile.py @@ -0,0 +1,96 @@ +from conan import ConanFile +from conan.tools.files import get, copy, rmdir +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.build import check_min_cppstd +from conan.tools.scm import Version +import os + +required_conan_version = ">=1.52.0" + +class CLI11Conan(ConanFile): + name = "cli11" + description = "A command line parser for C++11 and beyond." + license = "BSD-3-Clause" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/CLIUtils/CLI11" + topics = "cli-parser", "cpp11", "no-dependencies", "cli" + package_type = "header-library" + settings = "os", "arch", "compiler", "build_type" + no_copy_source = True + + options = { + "header_only": [True, False] + } + default_options = { + "header_only": True + } + + @property + def _min_cppstd(self): + return "11" + + @property + def _supports_compilation(self): + return Version(self.version) >= "2.3" + + def configure(self): + if not self._supports_compilation: + # TODO: Back to config_options after Conan 1 freeze + del self.options.header_only + elif not self.options.header_only: + self.package_type = "static-library" + + def layout(self): + cmake_layout(self, src_folder="src") + + def package_id(self): + if not self._supports_compilation or self.info.options.header_only: + self.info.clear() + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, self._min_cppstd) + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + if self._supports_compilation: + tc.variables["CLI11_PRECOMPILED"] = not self.options.header_only + tc.variables["CLI11_BUILD_EXAMPLES"] = False + tc.variables["CLI11_BUILD_TESTS"] = False + tc.variables["CLI11_BUILD_DOCS"] = False + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + cmake = CMake(self) + cmake.install() + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) + # since 2.1.1 + rmdir(self, os.path.join(self.package_folder, "share")) + + def package_info(self): + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + + if self._supports_compilation and not self.options.get_safe("header_only"): + self.cpp_info.libdirs = ["lib"] + self.cpp_info.libs = ["CLI11"] + self.cpp_info.defines = ["CLI11_COMPILE"] + + self.cpp_info.set_property("cmake_file_name", "CLI11") + self.cpp_info.set_property("cmake_target_name", "CLI11::CLI11") + self.cpp_info.set_property("pkg_config_name", "CLI11") + + # TODO: to remove in conan v2 once cmake_find_package_* generators removed + self.cpp_info.names["cmake_find_package"] = "CLI11" + self.cpp_info.names["cmake_find_package_multi"] = "CLI11" + self.cpp_info.names["pkg_config"] = "CLI11" \ No newline at end of file diff --git a/recipes/cli11/all/test_package/CMakeLists.txt b/recipes/cli11/all/test_package/CMakeLists.txt new file mode 100644 index 0000000..278d0f3 --- /dev/null +++ b/recipes/cli11/all/test_package/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(CLI11 REQUIRED CONFIG) + +add_executable(${CMAKE_PROJECT_NAME} test_package.cpp) +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE CLI11::CLI11) + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) \ No newline at end of file diff --git a/recipes/cli11/all/test_package/conanfile.py b/recipes/cli11/all/test_package/conanfile.py new file mode 100644 index 0000000..2c76a79 --- /dev/null +++ b/recipes/cli11/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") \ No newline at end of file diff --git a/recipes/cli11/all/test_package/test_package.cpp b/recipes/cli11/all/test_package/test_package.cpp new file mode 100644 index 0000000..dfac198 --- /dev/null +++ b/recipes/cli11/all/test_package/test_package.cpp @@ -0,0 +1,27 @@ +#include +#include +#include + +int main(int argc, char **argv) { + int count{0}; + int v{0}; + double value{0.0}; // = 3.14; + std::string file; + CLI::App app("K3Pi goofit fitter"); + + CLI::Option *opt = app.add_option("-f,--file,file", file, "File name"); + CLI::Option *copt = app.add_option("-c,--count", count, "Counter"); + CLI::Option *flag = app.add_flag("--flag", v, "Some flag that can be passed multiple times"); + + app.add_option("-d,--double", value, "Some Value"); + CLI11_PARSE(app, argc, argv); + + std::cout << "Working on file: " << file << ", direct count: " << app.count("--file") + << ", opt count: " << opt->count() << std::endl; + std::cout << "Working on count: " << count << ", direct count: " << app.count("--count") + << ", opt count: " << copt->count() << std::endl; + std::cout << "Received flag: " << v << " (" << flag->count() << ") times\n"; + std::cout << "Some value: " << value << std::endl; + + return 0; +} \ No newline at end of file diff --git a/recipes/cli11/config.yml b/recipes/cli11/config.yml new file mode 100644 index 0000000..fca5391 --- /dev/null +++ b/recipes/cli11/config.yml @@ -0,0 +1,3 @@ +versions: + "2.5.0": + folder: all \ No newline at end of file