diff --git a/recipes/cxxopts/all/conandata.yml b/recipes/cxxopts/all/conandata.yml index cc2bb6b4b5c85..80d718f14d1a0 100644 --- a/recipes/cxxopts/all/conandata.yml +++ b/recipes/cxxopts/all/conandata.yml @@ -1,13 +1,13 @@ sources: - "1.4.4": - url: https://github.com/jarro2783/cxxopts/archive/v1.4.4.zip - sha256: 7c8ec885fcc58e10a8268b57ae04d5cbeac895d150d3a09c15605ff7ef05cf87 - "2.2.0": - url: https://github.com/jarro2783/cxxopts/archive/v2.2.0.zip - sha256: f9640c00d9938bedb291a21f9287902a3a8cee38db6910b905f8eba4a6416204 - "2.2.1": - url: https://github.com/jarro2783/cxxopts/archive/v2.2.1.zip - sha256: 7021ce97f51a40f7fd3558da416ab6914b1d3f758ccf68a1e8734ad10b49b676 "3.0.0": - url: https://github.com/jarro2783/cxxopts/archive/v3.0.0.zip - sha256: 1eefdf5af3ba0c66458258de05df2a113262ad5e85cac489de0a456088e9f9b0 + url: "https://github.com/jarro2783/cxxopts/archive/refs/tags/v3.0.0.tar.gz" + sha256: "36f41fa2a46b3c1466613b63f3fa73dc24d912bc90d667147f1e43215a8c6d00" + "2.2.1": + url: "https://github.com/jarro2783/cxxopts/archive/refs/tags/v2.2.1.tar.gz" + sha256: "984aa3c8917d649b14d7f6277104ce38dd142ce378a9198ec926f03302399681" + "2.2.0": + url: "https://github.com/jarro2783/cxxopts/archive/refs/tags/v2.2.0.tar.gz" + sha256: "447dbfc2361fce9742c5d1c9cfb25731c977b405f9085a738fbd608626da8a4d" + "1.4.4": + url: "https://github.com/jarro2783/cxxopts/archive/refs/tags/v1.4.4.tar.gz" + sha256: "1d0eedb39ecbc64a0f82d8b6fe40d5c8e611501702969cfbd14a07ce6ddb8501" diff --git a/recipes/cxxopts/all/conanfile.py b/recipes/cxxopts/all/conanfile.py index c7ce483a6966b..c9aafdc057393 100644 --- a/recipes/cxxopts/all/conanfile.py +++ b/recipes/cxxopts/all/conanfile.py @@ -1,6 +1,12 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import copy, get +from conan.tools.layout import basic_layout +from conan.tools.scm import Version import os -from conans import ConanFile, tools -from conans.errors import ConanInvalidConfiguration + +required_conan_version = ">=1.51.1" class CxxOptsConan(ConanFile): @@ -10,17 +16,18 @@ class CxxOptsConan(ConanFile): description = "Lightweight C++ option parser library, supporting the standard GNU style syntax for options." license = "MIT" topics = ("option-parser", "positional-arguments ", "header-only") - settings = "compiler" - options = { "unicode": [True, False] } - default_options = { "unicode": False } - no_copy_source = True - @property - def _source_subfolder(self): - return "source_subfolder" + settings = "os", "arch", "compiler", "build_type" + options = { + "unicode": [True, False], + } + default_options = { + "unicode": False, + } + no_copy_source = True @property - def _minimum_cpp_standard(self): + def _min_cppstd(self): return 11 @property @@ -32,33 +39,41 @@ def _minimum_compilers_version(self): "apple-clang": "8", } - def configure(self): - if self.settings.compiler.get_safe("cppstd"): - tools.check_min_cppstd(self, self._minimum_cpp_standard) - min_version = self._minimum_compilers_version.get(str(self.settings.compiler)) - if not min_version: - self.output.warn("{} recipe lacks information about the {} compiler support.".format( - self.name, self.settings.compiler)) - else: - if tools.Version(self.settings.compiler.version) < min_version: - raise ConanInvalidConfiguration("{} requires C++{} support. The current compiler {} {} does not support it.".format( - self.name, self._minimum_cpp_standard, self.settings.compiler, self.settings.compiler.version)) + def layout(self): + basic_layout(self, src_folder="src") def requirements(self): if self.options.unicode: - self.requires("icu/70.1") + self.requires("icu/71.1") + + def package_id(self): + self.info.clear() + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, self._min_cppstd) + min_version = self._minimum_compilers_version.get(str(self.settings.compiler)) + if min_version and Version(self.settings.compiler.version) < min_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support", + ) 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 package(self): - self.copy("LICENSE", dst="licenses", src=self._source_subfolder) - self.copy("{}.hpp".format(self.name), dst="include", src=os.path.join(self._source_subfolder, "include")) + def build(self): + pass - def package_id(self): - self.info.header_only() + def package(self): + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + copy(self, "cxxopts.hpp", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include")) def package_info(self): + self.cpp_info.set_property("cmake_file_name", "cxxopts") + self.cpp_info.set_property("cmake_target_name", "cxxopts::cxxopts") + self.cpp_info.set_property("pkg_config_name", "cxxopts") + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] if self.options.unicode: self.cpp_info.defines = ["CXXOPTS_USE_UNICODE"] diff --git a/recipes/cxxopts/all/test_package/CMakeLists.txt b/recipes/cxxopts/all/test_package/CMakeLists.txt index 7f2172dfd2a9c..6f5decb20d62e 100644 --- a/recipes/cxxopts/all/test_package/CMakeLists.txt +++ b/recipes/cxxopts/all/test_package/CMakeLists.txt @@ -1,9 +1,8 @@ -cmake_minimum_required(VERSION 3.1.3) -project(test_package CXX) +cmake_minimum_required(VERSION 3.8) +project(test_package LANGUAGES CXX) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) +find_package(cxxopts REQUIRED CONFIG) -add_executable(${PROJECT_NAME} main.cpp) -target_link_libraries(${PROJECT_NAME} CONAN_PKG::cxxopts) -set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE cxxopts::cxxopts) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/cxxopts/all/test_package/conanfile.py b/recipes/cxxopts/all/test_package/conanfile.py index 7da0637b28118..284c7dbfedbea 100644 --- a/recipes/cxxopts/all/test_package/conanfile.py +++ b/recipes/cxxopts/all/test_package/conanfile.py @@ -1,10 +1,20 @@ -import os +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout from io import StringIO -from conans import ConanFile, CMake, tools +import os + class TestPackageConan(ConanFile): - settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) @@ -12,13 +22,13 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): + if can_run(self): output = StringIO() - bin_path = os.path.join("bin", "test_package") - option_string = "-f 41 --bar baria --baz"; + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + option_string = "-f 41 --bar baria --baz" if self.options["cxxopts"].unicode: - option_string += " -q quxis"; - self.run("{} {}".format(bin_path, option_string), run_environment=True, output=output) + option_string += " -q quxis" + self.run(f"{bin_path} {option_string}", env="conanrun", output=output) output_lines = set(output.getvalue().splitlines()) expected_lines = {"foo:41", "bar:baria", "baz:1"} if self.options["cxxopts"].unicode: diff --git a/recipes/cxxopts/all/test_package/main.cpp b/recipes/cxxopts/all/test_package/test_package.cpp similarity index 100% rename from recipes/cxxopts/all/test_package/main.cpp rename to recipes/cxxopts/all/test_package/test_package.cpp diff --git a/recipes/cxxopts/all/test_v1_package/CMakeLists.txt b/recipes/cxxopts/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..0d20897301b68 --- /dev/null +++ b/recipes/cxxopts/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +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/cxxopts/all/test_v1_package/conanfile.py b/recipes/cxxopts/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..c68398ab15a88 --- /dev/null +++ b/recipes/cxxopts/all/test_v1_package/conanfile.py @@ -0,0 +1,27 @@ +from conans import ConanFile, CMake, tools +from io import StringIO +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + output = StringIO() + bin_path = os.path.join("bin", "test_package") + option_string = "-f 41 --bar baria --baz" + if self.options["cxxopts"].unicode: + option_string += " -q quxis" + self.run(f"{bin_path} {option_string}", run_environment=True, output=output) + output_lines = set(output.getvalue().splitlines()) + expected_lines = {"foo:41", "bar:baria", "baz:1"} + if self.options["cxxopts"].unicode: + expected_lines.add("qux:quxis") + assert(expected_lines.issubset(output_lines)) diff --git a/recipes/cxxopts/config.yml b/recipes/cxxopts/config.yml index cc3a23a64de0f..69689683a4346 100644 --- a/recipes/cxxopts/config.yml +++ b/recipes/cxxopts/config.yml @@ -1,9 +1,9 @@ versions: - "1.4.4": - folder: all - "2.2.0": + "3.0.0": folder: all "2.2.1": folder: all - "3.0.0": + "2.2.0": + folder: all + "1.4.4": folder: all