Skip to content

Commit 2d1a4fd

Browse files
authored
(#14312) cpu_features: conan v2 support
1 parent 74374b3 commit 2d1a4fd

File tree

7 files changed

+76
-60
lines changed

7 files changed

+76
-60
lines changed

recipes/cpu_features/all/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

recipes/cpu_features/all/conandata.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ sources:
66
url: "https://github.com/google/cpu_features/archive/refs/tags/v0.6.0.tar.gz"
77
sha256: "95a1cf6f24948031df114798a97eea2a71143bd38a4d07d9a758dda3924c1932"
88
patches:
9-
"0.6.0":
10-
- patch_file: "patches/0.6.0-0001-fix-bundle-install.patch"
11-
base_path: "source_subfolder"
129
"0.7.0":
1310
- patch_file: "patches/0.7.0-0001-support-aarch64-macos.patch"
14-
base_path: "source_subfolder"
11+
"0.6.0":
12+
- patch_file: "patches/0.6.0-0001-fix-bundle-install.patch"

recipes/cpu_features/all/conanfile.py

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from conans import ConanFile, CMake, tools
1+
from conan import ConanFile
2+
from conan.tools.apple import is_apple_os
3+
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
4+
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
5+
from conan.tools.scm import Version
26
import os
37

4-
required_conan_version = ">=1.43.0"
8+
required_conan_version = ">=1.53.0"
59

610

711
class CpuFeaturesConan(ConanFile):
@@ -22,57 +26,49 @@ class CpuFeaturesConan(ConanFile):
2226
"fPIC": True,
2327
}
2428

25-
generators = "cmake",
26-
_cmake = None
27-
28-
@property
29-
def _source_subfolder(self):
30-
return "source_subfolder"
31-
3229
def export_sources(self):
33-
self.copy("CMakeLists.txt")
34-
for patch in self.conan_data.get("patches", {}).get(self.version, []):
35-
self.copy(patch["patch_file"])
30+
export_conandata_patches(self)
3631

3732
def config_options(self):
3833
if self.settings.os == "Windows":
3934
del self.options.fPIC
4035

4136
def configure(self):
4237
if self.options.shared:
43-
del self.options.fPIC
44-
del self.settings.compiler.libcxx
45-
del self.settings.compiler.cppstd
38+
self.options.rm_safe("fPIC")
39+
self.settings.compiler.rm_safe("cppstd")
40+
self.settings.compiler.rm_safe("libcxx")
41+
42+
def layout(self):
43+
cmake_layout(self, src_folder="src")
4644

4745
def source(self):
48-
tools.get(**self.conan_data["sources"][self.version],
49-
strip_root=True, destination=self._source_subfolder)
50-
51-
def _configure_cmake(self):
52-
if self._cmake:
53-
return self._cmake
54-
self._cmake = CMake(self)
55-
if tools.Version(self.version) < "0.7.0":
56-
self._cmake.definitions["BUILD_PIC"] = self.options.get_safe("fPIC", True)
57-
if tools.Version(self.version) >= "0.7.0":
58-
self._cmake.definitions["BUILD_TESTING"] = False
46+
get(self, **self.conan_data["sources"][self.version],
47+
destination=self.source_folder, strip_root=True)
48+
49+
def generate(self):
50+
tc = CMakeToolchain(self)
51+
if Version(self.version) < "0.7.0":
52+
tc.variables["BUILD_PIC"] = self.options.get_safe("fPIC", True)
53+
if Version(self.version) >= "0.7.0":
54+
tc.variables["BUILD_TESTING"] = False
5955
# TODO: should be handled by CMake helper
60-
if tools.is_apple_os(self.settings.os) and self.settings.arch in ["armv8", "armv8_32", "armv8.3"]:
61-
self._cmake.definitions["CMAKE_SYSTEM_PROCESSOR"] = "aarch64"
62-
self._cmake.configure() # Does not support out of source builds
63-
return self._cmake
56+
if is_apple_os(self) and self.settings.arch in ["armv8", "armv8_32", "armv8.3"]:
57+
tc.variables["CMAKE_SYSTEM_PROCESSOR"] = "aarch64"
58+
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
59+
tc.generate()
6460

6561
def build(self):
66-
for patch in self.conan_data.get("patches", {}).get(self.version, []):
67-
tools.patch(**patch)
68-
cmake = self._configure_cmake()
62+
apply_conandata_patches(self)
63+
cmake = CMake(self)
64+
cmake.configure()
6965
cmake.build()
7066

7167
def package(self):
72-
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
73-
cmake = self._configure_cmake()
68+
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
69+
cmake = CMake(self)
7470
cmake.install()
75-
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
71+
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
7672

7773
def package_info(self):
7874
self.cpp_info.set_property("cmake_file_name", "CpuFeatures")
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
cmake_minimum_required(VERSION 3.1)
2-
project(test_package)
2+
project(test_package LANGUAGES C)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup(TARGETS)
6-
7-
find_package(CpuFeatures CONFIG REQUIRED)
4+
find_package(CpuFeatures REQUIRED CONFIG)
85

96
add_executable(${PROJECT_NAME} test_package.c)
10-
target_link_libraries(${PROJECT_NAME} CpuFeatures::cpu_features)
7+
target_link_libraries(${PROJECT_NAME} PRIVATE CpuFeatures::cpu_features)
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
from conans import ConanFile, CMake, tools
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import CMake, cmake_layout
24
import os
35

46

57
class TestPackageConan(ConanFile):
68
settings = "os", "arch", "compiler", "build_type"
7-
generators = "cmake", "cmake_find_package_multi"
9+
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def layout(self):
13+
cmake_layout(self)
14+
15+
def requirements(self):
16+
self.requires(self.tested_reference_str)
817

918
def build(self):
1019
cmake = CMake(self)
1120
cmake.configure()
1221
cmake.build()
1322

1423
def test(self):
15-
if not tools.cross_building(self):
16-
bin_path = os.path.join("bin", "test_package")
17-
self.run(bin_path, run_environment=True)
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)

0 commit comments

Comments
 (0)