diff --git a/recipes/xtensor/all/conandata.yml b/recipes/xtensor/all/conandata.yml index 99f4ce4af7773..5b2596a448217 100644 --- a/recipes/xtensor/all/conandata.yml +++ b/recipes/xtensor/all/conandata.yml @@ -26,19 +26,13 @@ sources: patches: "0.24.2": - patch_file: "patches/0.24.0-cxx11-abi.patch" - base_path: "source_subfolder" "0.24.0": - patch_file: "patches/0.24.0-cxx11-abi.patch" - base_path: "source_subfolder" "0.23.10": - patch_file: "patches/0.23.9-cxx11-abi.patch" - base_path: "source_subfolder" "0.23.9": - patch_file: "patches/0.23.9-cxx11-abi.patch" - base_path: "source_subfolder" "0.21.5": - patch_file: "patches/0.21.5-cxx11-abi.patch" - base_path: "source_subfolder" "0.21.4": - patch_file: "patches/0.21.4-cxx11-abi.patch" - base_path: "source_subfolder" diff --git a/recipes/xtensor/all/conanfile.py b/recipes/xtensor/all/conanfile.py index baa6ad0bc0c84..52e5e88678830 100644 --- a/recipes/xtensor/all/conanfile.py +++ b/recipes/xtensor/all/conanfile.py @@ -1,9 +1,13 @@ -from conans import ConanFile, tools -from conans.errors import ConanInvalidConfiguration +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, save +from conan.tools.layout import basic_layout +from conan.tools.scm import Version import os import textwrap -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.52.0" class XtensorConan(ConanFile): @@ -26,23 +30,38 @@ class XtensorConan(ConanFile): } @property - def _source_subfolder(self): - return "source_subfolder" + def _min_cppstd(self): + return "14" + + @property + def _compilers_minimum_version(self): + # https://github.com/xtensor-stack/xtensor/blob/master/README.md + return { + "Visual Studio": "14", + "msvc": "190", + "gcc": "4.9", + "clang": "4", + } def export_sources(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + export_conandata_patches(self) + + def layout(self): + basic_layout(self, src_folder="src") def requirements(self): self.requires("xtl/0.7.4") - self.requires("nlohmann_json/3.10.5") + self.requires("nlohmann_json/3.11.2") if self.options.xsimd: - if tools.Version(self.version) < "0.24.0": + if Version(self.version) < "0.24.0": self.requires("xsimd/7.5.0") else: - self.requires("xsimd/8.1.0") + self.requires("xsimd/9.0.1") if self.options.tbb: - self.requires("onetbb/2021.3.0") + self.requires("onetbb/2021.7.0") + + def package_id(self): + self.info.clear() def validate(self): if self.options.tbb and self.options.openmp: @@ -50,36 +69,31 @@ def validate(self): "The options 'tbb' and 'openmp' can not be used together." ) - # https://github.com/xtensor-stack/xtensor/blob/master/README.md - # - On Windows platforms, Visual C++ 2015 Update 2, or more recent - # - On Unix platforms, gcc 4.9 or a recent version of Clang - version = tools.Version(self.settings.compiler.version) - compiler = self.settings.compiler - if compiler == "Visual Studio" and version < "16": + if self.settings.compiler.get_safe("cppstd"): + check_min_cppstd(self, self._min_cppstd) + + def loose_lt_semver(v1, v2): + lv1 = [int(v) for v in v1.split(".")] + lv2 = [int(v) for v in v2.split(".")] + min_length = min(len(lv1), len(lv2)) + return lv1[:min_length] < lv2[:min_length] + + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and loose_lt_semver(str(self.settings.compiler.version), minimum_version): raise ConanInvalidConfiguration( - "xtensor requires at least Visual Studio version 15.9, please use 16" + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support.", ) - if (compiler == "gcc" and version < "5.0") or ( - compiler == "clang" and version < "4" - ): - raise ConanInvalidConfiguration("xtensor requires at least C++14") - - def package_id(self): - self.info.header_only() 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 build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) + apply_conandata_patches(self) def package(self): - self.copy("LICENSE", dst="licenses", src=self._source_subfolder) - self.copy( - "*.hpp", dst="include", src=os.path.join(self._source_subfolder, "include") - ) + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + copy(self, "*.hpp", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include")) # TODO: to remove in conan v2 once cmake_find_package* generators removed self._create_cmake_module_alias_targets( @@ -87,26 +101,27 @@ def package(self): {"xtensor": "xtensor::xtensor"} ) - @staticmethod - def _create_cmake_module_alias_targets(module_file, targets): + def _create_cmake_module_alias_targets(self, module_file, targets): content = "" for alias, aliased in targets.items(): - content += textwrap.dedent("""\ + content += textwrap.dedent(f"""\ if(TARGET {aliased} AND NOT TARGET {alias}) add_library({alias} INTERFACE IMPORTED) set_property(TARGET {alias} PROPERTY INTERFACE_LINK_LIBRARIES {aliased}) endif() - """.format(alias=alias, aliased=aliased)) - tools.save(module_file, content) + """) + save(self, module_file, content) @property def _module_file_rel_path(self): - return os.path.join("lib", "cmake", "conan-official-{}-targets.cmake".format(self.name)) + return os.path.join("lib", "cmake", f"conan-official-{self.name}-targets.cmake") def package_info(self): self.cpp_info.set_property("cmake_file_name", "xtensor") self.cpp_info.set_property("cmake_target_name", "xtensor") self.cpp_info.set_property("pkg_config_name", "xtensor") + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] if self.options.xsimd: self.cpp_info.defines.append("XTENSOR_USE_XSIMD") if self.options.tbb: diff --git a/recipes/xtensor/all/test_package/CMakeLists.txt b/recipes/xtensor/all/test_package/CMakeLists.txt index 0e4d9800858f9..ed456ebb1ccdb 100644 --- a/recipes/xtensor/all/test_package/CMakeLists.txt +++ b/recipes/xtensor/all/test_package/CMakeLists.txt @@ -1,15 +1,12 @@ cmake_minimum_required(VERSION 3.8) -project(test_package CXX) +project(test_package LANGUAGES CXX) include(CheckCXXCompilerFlag) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - find_package(xtensor REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} xtensor) +target_link_libraries(${PROJECT_NAME} PRIVATE xtensor) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14) foreach(flag "-march=native" "-mtune=native") diff --git a/recipes/xtensor/all/test_package/conanfile.py b/recipes/xtensor/all/test_package/conanfile.py index 8ac27b308f404..0a6bc68712d90 100644 --- a/recipes/xtensor/all/test_package/conanfile.py +++ b/recipes/xtensor/all/test_package/conanfile.py @@ -1,11 +1,19 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os -from conans import ConanFile, CMake, tools - -class XtensorTestConan(ConanFile): +class TestPackageConan(ConanFile): settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" + 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) @@ -13,5 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - self.run(os.path.join("bin", "test_package"), 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/xtensor/all/test_v1_package/CMakeLists.txt b/recipes/xtensor/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..0d20897301b68 --- /dev/null +++ b/recipes/xtensor/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/xtensor/all/test_v1_package/conanfile.py b/recipes/xtensor/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/xtensor/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +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): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True)