1
1
from conan import ConanFile
2
2
from conan .errors import ConanInvalidConfiguration
3
- from conan .tools .build import check_min_cppstd
3
+ from conan .tools .apple import fix_apple_shared_install_name
4
+ from conan .tools .build import check_min_cppstd , cross_building
4
5
from conan .tools .cmake import CMake , CMakeDeps , CMakeToolchain , cmake_layout
5
- from conan .tools .env import VirtualBuildEnv
6
- from conan .tools .files import apply_conandata_patches , copy , get , rmdir , save
6
+ from conan .tools .env import VirtualBuildEnv , VirtualRunEnv
7
+ from conan .tools .files import apply_conandata_patches , copy , export_conandata_patches , get , rmdir , save
7
8
from conan .tools .microsoft import is_msvc , is_msvc_static_runtime
8
9
from conan .tools .scm import Version
9
10
import os
10
11
import textwrap
11
12
12
- required_conan_version = ">=1.50.2 <1.51.0 || >=1.51.2 "
13
+ required_conan_version = ">=1.53.0 "
13
14
14
15
15
16
class OnnxConan (ConanFile ):
@@ -20,6 +21,7 @@ class OnnxConan(ConanFile):
20
21
homepage = "https://github.com/onnx/onnx"
21
22
url = "https://github.com/conan-io/conan-center-index"
22
23
24
+ package_type = "library"
23
25
settings = "os" , "arch" , "compiler" , "build_type"
24
26
options = {
25
27
"shared" : [True , False ],
@@ -33,44 +35,47 @@ class OnnxConan(ConanFile):
33
35
@property
34
36
def _protobuf_version (self ):
35
37
# onnx < 1.9.0 doesn't support protobuf >= 3.18
36
- return "3.21.4 " if Version (self .version ) >= "1.9.0" else "3.17.1"
38
+ return "3.21.9 " if Version (self .version ) >= "1.9.0" else "3.17.1"
37
39
38
40
def export_sources (self ):
39
- for p in self .conan_data .get ("patches" , {}).get (self .version , []):
40
- copy (self , p ["patch_file" ], self .recipe_folder , self .export_sources_folder )
41
+ export_conandata_patches (self )
41
42
42
43
def config_options (self ):
43
44
if self .settings .os == "Windows" :
44
45
del self .options .fPIC
45
46
46
47
def configure (self ):
47
48
if self .options .shared :
48
- del self .options .fPIC
49
+ self .options .rm_safe ("fPIC" )
50
+
51
+ def layout (self ):
52
+ cmake_layout (self , src_folder = "src" )
49
53
50
54
def requirements (self ):
51
- self .requires (f"protobuf/{ self ._protobuf_version } " )
55
+ self .requires (f"protobuf/{ self ._protobuf_version } " , run = not cross_building ( self ), transitive_headers = True , transitive_libs = True )
52
56
53
57
def validate (self ):
54
- if self .info . settings .compiler .cppstd :
58
+ if self .settings .compiler .get_safe ( " cppstd" ) :
55
59
check_min_cppstd (self , 11 )
56
- if is_msvc (self ) and self .info . options .shared :
60
+ if is_msvc (self ) and self .options .shared :
57
61
raise ConanInvalidConfiguration ("onnx shared is broken with Visual Studio" )
58
62
59
63
def build_requirements (self ):
60
- if hasattr (self , "settings_build" ):
64
+ if hasattr (self , "settings_build" ) and cross_building ( self ) :
61
65
self .tool_requires (f"protobuf/{ self ._protobuf_version } " )
62
66
63
- def layout (self ):
64
- cmake_layout (self , src_folder = "src" )
65
-
66
67
def source (self ):
67
- get (self , ** self .conan_data ["sources" ][self .version ],
68
- destination = self .source_folder , strip_root = True )
68
+ get (self , ** self .conan_data ["sources" ][self .version ], strip_root = True )
69
69
70
70
def generate (self ):
71
+ env = VirtualBuildEnv (self )
72
+ env .generate ()
73
+ if not cross_building (self ):
74
+ env = VirtualRunEnv (self )
75
+ env .generate (scope = "build" )
71
76
tc = CMakeToolchain (self )
72
77
tc .variables ["ONNX_BUILD_BENCHMARKS" ] = False
73
- tc .variables ["ONNX_USE_PROTOBUF_SHARED_LIBS" ] = self .options ["protobuf" ].shared
78
+ tc .variables ["ONNX_USE_PROTOBUF_SHARED_LIBS" ] = self .dependencies . host ["protobuf" ]. options .shared
74
79
tc .variables ["BUILD_ONNX_PYTHON" ] = False
75
80
tc .variables ["ONNX_GEN_PB_TYPE_STUBS" ] = False
76
81
tc .variables ["ONNX_WERROR" ] = False
@@ -86,8 +91,6 @@ def generate(self):
86
91
tc .generate ()
87
92
deps = CMakeDeps (self )
88
93
deps .generate ()
89
- env = VirtualBuildEnv (self )
90
- env .generate ()
91
94
92
95
def build (self ):
93
96
apply_conandata_patches (self )
@@ -100,6 +103,7 @@ def package(self):
100
103
cmake = CMake (self )
101
104
cmake .install ()
102
105
rmdir (self , os .path .join (self .package_folder , "lib" , "cmake" ))
106
+ fix_apple_shared_install_name (self )
103
107
104
108
# TODO: to remove in conan v2 once legacy generators removed
105
109
self ._create_cmake_module_alias_targets (
@@ -138,7 +142,8 @@ def _onnx_components(self):
138
142
"requires" : ["protobuf::libprotobuf" ]
139
143
},
140
144
"onnxifi" : {
141
- "target" : "onnxifi"
145
+ "target" : "onnxifi" ,
146
+ "system_libs" : [(self .settings .os in ["Linux" , "FreeBSD" ], ["dl" ])],
142
147
},
143
148
"onnxifi_dummy" : {
144
149
"target" : "onnxifi_dummy" ,
@@ -167,10 +172,12 @@ def _register_components(components):
167
172
libs = comp_values .get ("libs" , [])
168
173
defines = comp_values .get ("defines" , [])
169
174
requires = comp_values .get ("requires" , [])
175
+ system_libs = [l for cond , sys_libs in comp_values .get ("system_libs" , []) if cond for l in sys_libs ]
170
176
self .cpp_info .components [comp_name ].set_property ("cmake_target_name" , target )
171
177
self .cpp_info .components [comp_name ].libs = libs
172
178
self .cpp_info .components [comp_name ].defines = defines
173
179
self .cpp_info .components [comp_name ].requires = requires
180
+ self .cpp_info .components [comp_name ].system_libs = system_libs
174
181
175
182
# TODO: to remove in conan v2 once cmake_find_package_* generators removed
176
183
self .cpp_info .components [comp_name ].names ["cmake_find_package" ] = target
0 commit comments