From 2fc42d1488d5bf29af9aad1c16a0f2f112db1110 Mon Sep 17 00:00:00 2001 From: Paul Harris Date: Tue, 1 Nov 2022 02:08:43 +0800 Subject: [PATCH] (#13793) cli11: conan v2 support * cli11: conan v2 support * Fix for test_v1_package * Apply suggestions from code review Co-authored-by: Uilian Ries * Update recipes/cli11/all/test_v1_package/CMakeLists.txt Co-authored-by: toge Co-authored-by: Uilian Ries Co-authored-by: toge --- recipes/cli11/all/conanfile.py | 53 +++++++++++++------ recipes/cli11/all/test_package/CMakeLists.txt | 10 ++-- recipes/cli11/all/test_package/conanfile.py | 21 +++++--- .../cli11/all/test_v1_package/CMakeLists.txt | 8 +++ .../cli11/all/test_v1_package/conanfile.py | 17 ++++++ 5 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 recipes/cli11/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/cli11/all/test_v1_package/conanfile.py diff --git a/recipes/cli11/all/conanfile.py b/recipes/cli11/all/conanfile.py index bf1a635513afa..6ccc240eeda4f 100644 --- a/recipes/cli11/all/conanfile.py +++ b/recipes/cli11/all/conanfile.py @@ -1,45 +1,64 @@ -from conans import ConanFile, CMake, tools +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 import os -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.52.0" class CLI11Conan(ConanFile): name = "cli11" homepage = "https://github.com/CLIUtils/CLI11" description = "A command line parser for C++11 and beyond." - topics = ("cli-parser", "cpp11", "no-dependencies", "cli", "header-only") + topics = "cli-parser", "cpp11", "no-dependencies", "cli", "header-only" url = "https://github.com/conan-io/conan-center-index" license = "BSD-3-Clause" settings = "os", "compiler", "build_type", "arch" @property - def _source_subfolder(self): - return "source_subfolder" + def _min_cppstd(self): + return "11" + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, self._min_cppstd) + + def layout(self): + cmake_layout(self, src_folder="src") def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + 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): - self.copy("LICENSE", dst="licenses", src=self._source_subfolder) + copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) cmake = CMake(self) - cmake.definitions["CLI11_BUILD_EXAMPLES"] = False - cmake.definitions["CLI11_BUILD_TESTS"] = False - cmake.definitions["CLI11_BUILD_DOCS"] = False - cmake.configure(source_folder=self._source_subfolder) cmake.install() - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) - tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) # since 2.1.1 - tools.rmdir(os.path.join(self.package_folder, "share")) + rmdir(self, os.path.join(self.package_folder, "share")) def package_id(self): - self.info.header_only() + self.info.clear() def package_info(self): - self.cpp_info.set_property("cmake_target_name", "CLI11::CLI11") 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" diff --git a/recipes/cli11/all/test_package/CMakeLists.txt b/recipes/cli11/all/test_package/CMakeLists.txt index 8f4fafc076f52..0b06b681b8997 100644 --- a/recipes/cli11/all/test_package/CMakeLists.txt +++ b/recipes/cli11/all/test_package/CMakeLists.txt @@ -1,11 +1,9 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.8) project(test_package CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - find_package(CLI11 REQUIRED CONFIG) add_executable(${CMAKE_PROJECT_NAME} test_package.cpp) -set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY CXX_STANDARD 11) -target_link_libraries(${CMAKE_PROJECT_NAME} CLI11::CLI11) +target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE CLI11::CLI11) + +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/cli11/all/test_package/conanfile.py b/recipes/cli11/all/test_package/conanfile.py index b30e638816fc5..a9fb96656f203 100644 --- a/recipes/cli11/all/test_package/conanfile.py +++ b/recipes/cli11/all/test_package/conanfile.py @@ -1,10 +1,19 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake import os -from conans import ConanFile, CMake, tools class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake_find_package_multi", "cmake" + 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) @@ -12,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin","test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/cli11/all/test_v1_package/CMakeLists.txt b/recipes/cli11/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..145dcc03e0f3d --- /dev/null +++ b/recipes/cli11/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package + ${CMAKE_CURRENT_BINARY_DIR}/test_package) diff --git a/recipes/cli11/all/test_v1_package/conanfile.py b/recipes/cli11/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..b30e638816fc5 --- /dev/null +++ b/recipes/cli11/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +import os +from conans import ConanFile, CMake, tools + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake_find_package_multi", "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin","test_package") + self.run(bin_path, run_environment=True)