diff --git a/recipes/cpu_features/all/CMakeLists.txt b/recipes/cpu_features/all/CMakeLists.txt deleted file mode 100644 index 1a04042483d18..0000000000000 --- a/recipes/cpu_features/all/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -cmake_minimum_required(VERSION 3.4) -project(cmake_wrapper) - -set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(KEEP_RPATHS) - -add_subdirectory("source_subfolder") diff --git a/recipes/cpu_features/all/conandata.yml b/recipes/cpu_features/all/conandata.yml index fc86a2c7b0fc0..a6a49730a3d42 100644 --- a/recipes/cpu_features/all/conandata.yml +++ b/recipes/cpu_features/all/conandata.yml @@ -6,9 +6,7 @@ sources: url: "https://github.com/google/cpu_features/archive/refs/tags/v0.6.0.tar.gz" sha256: "95a1cf6f24948031df114798a97eea2a71143bd38a4d07d9a758dda3924c1932" patches: - "0.6.0": - - patch_file: "patches/0.6.0-0001-fix-bundle-install.patch" - base_path: "source_subfolder" "0.7.0": - patch_file: "patches/0.7.0-0001-support-aarch64-macos.patch" - base_path: "source_subfolder" + "0.6.0": + - patch_file: "patches/0.6.0-0001-fix-bundle-install.patch" diff --git a/recipes/cpu_features/all/conanfile.py b/recipes/cpu_features/all/conanfile.py index f840112991c67..67333f1731762 100644 --- a/recipes/cpu_features/all/conanfile.py +++ b/recipes/cpu_features/all/conanfile.py @@ -1,7 +1,11 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.apple import is_apple_os +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir +from conan.tools.scm import Version import os -required_conan_version = ">=1.43.0" +required_conan_version = ">=1.53.0" class CpuFeaturesConan(ConanFile): @@ -22,17 +26,8 @@ class CpuFeaturesConan(ConanFile): "fPIC": True, } - generators = "cmake", - _cmake = None - - @property - def _source_subfolder(self): - return "source_subfolder" - def export_sources(self): - self.copy("CMakeLists.txt") - for patch in self.conan_data.get("patches", {}).get(self.version, []): - self.copy(patch["patch_file"]) + export_conandata_patches(self) def config_options(self): if self.settings.os == "Windows": @@ -40,39 +35,40 @@ def config_options(self): def configure(self): if self.options.shared: - del self.options.fPIC - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + self.options.rm_safe("fPIC") + self.settings.compiler.rm_safe("cppstd") + self.settings.compiler.rm_safe("libcxx") + + def layout(self): + cmake_layout(self, src_folder="src") def source(self): - tools.get(**self.conan_data["sources"][self.version], - strip_root=True, destination=self._source_subfolder) - - def _configure_cmake(self): - if self._cmake: - return self._cmake - self._cmake = CMake(self) - if tools.Version(self.version) < "0.7.0": - self._cmake.definitions["BUILD_PIC"] = self.options.get_safe("fPIC", True) - if tools.Version(self.version) >= "0.7.0": - self._cmake.definitions["BUILD_TESTING"] = False + get(self, **self.conan_data["sources"][self.version], + destination=self.source_folder, strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + if Version(self.version) < "0.7.0": + tc.variables["BUILD_PIC"] = self.options.get_safe("fPIC", True) + if Version(self.version) >= "0.7.0": + tc.variables["BUILD_TESTING"] = False # TODO: should be handled by CMake helper - if tools.is_apple_os(self.settings.os) and self.settings.arch in ["armv8", "armv8_32", "armv8.3"]: - self._cmake.definitions["CMAKE_SYSTEM_PROCESSOR"] = "aarch64" - self._cmake.configure() # Does not support out of source builds - return self._cmake + if is_apple_os(self) and self.settings.arch in ["armv8", "armv8_32", "armv8.3"]: + tc.variables["CMAKE_SYSTEM_PROCESSOR"] = "aarch64" + tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True + tc.generate() def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - cmake = self._configure_cmake() + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy("LICENSE", dst="licenses", src=self._source_subfolder) - cmake = self._configure_cmake() + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) cmake.install() - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) def package_info(self): self.cpp_info.set_property("cmake_file_name", "CpuFeatures") diff --git a/recipes/cpu_features/all/test_package/CMakeLists.txt b/recipes/cpu_features/all/test_package/CMakeLists.txt index 3dcaabf120d13..34c33e1cc8a13 100644 --- a/recipes/cpu_features/all/test_package/CMakeLists.txt +++ b/recipes/cpu_features/all/test_package/CMakeLists.txt @@ -1,10 +1,7 @@ cmake_minimum_required(VERSION 3.1) -project(test_package) +project(test_package LANGUAGES C) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) - -find_package(CpuFeatures CONFIG REQUIRED) +find_package(CpuFeatures REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.c) -target_link_libraries(${PROJECT_NAME} CpuFeatures::cpu_features) +target_link_libraries(${PROJECT_NAME} PRIVATE CpuFeatures::cpu_features) diff --git a/recipes/cpu_features/all/test_package/conanfile.py b/recipes/cpu_features/all/test_package/conanfile.py index 38f4483872d47..0a6bc68712d90 100644 --- a/recipes/cpu_features/all/test_package/conanfile.py +++ b/recipes/cpu_features/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout import os 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) @@ -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/cpu_features/all/test_v1_package/CMakeLists.txt b/recipes/cpu_features/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..0d20897301b68 --- /dev/null +++ b/recipes/cpu_features/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/cpu_features/all/test_v1_package/conanfile.py b/recipes/cpu_features/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..38f4483872d47 --- /dev/null +++ b/recipes/cpu_features/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)