-
Notifications
You must be signed in to change notification settings - Fork 2
/
conanfile.py
248 lines (215 loc) · 10.4 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import conans
import os
class CMake(conans.CMake):
def configure(self, args=None, defs=None, source_folder=None, build_folder=None,
cache_build_folder=None, pkg_config_paths=None):
env_prefix = "CONAN_CMAKE_CUSTOM_"
cmake_params = [
"-D%s=%s" % (key.replace(env_prefix, ''), value)
for key, value in os.environ.items() if key.startswith(env_prefix)
]
if args is not None:
args.extend(cmake_params)
else:
args = cmake_params
super().configure(
args=args, defs=defs, source_folder=source_folder, build_folder=build_folder,
cache_build_folder=cache_build_folder, pkg_config_paths=pkg_config_paths
)
class MicroblinkConanFile(object):
options = {
'log_level': ['Verbose', 'Debug', 'Info', 'WarningsAndErrors'],
'enable_timer': [True, False],
'enable_testing': [True, False]
}
default_options = {
'log_level': 'WarningsAndErrors',
'enable_timer': False,
'enable_testing': False
}
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
no_copy_source = True
def configure(self):
# iOS and MacOS have fat binaries, so those packages don't depend on arch setting
if self.settings.os in ['iOS', 'Macos']:
self.settings.remove('arch')
def add_base_args(self, args):
if 'log_level' in self.options:
if self.options.log_level == 'Verbose':
args.append('-DMB_GLOBAL_LOG_LEVEL=LOG_VERBOSE')
elif self.options.log_level == 'Debug':
args.append('-DMB_GLOBAL_LOG_LEVEL=LOG_DEBUG')
elif self.options.log_level == 'Info':
args.append('-DMB_GLOBAL_LOG_LEVEL=LOG_INFO')
elif self.options.log_level == 'WarningsAndErrors':
args.append('-DMB_GLOBAL_LOG_LEVEL=LOG_WARNINGS_AND_ERRORS')
if 'enable_timer' in self.options:
if self.options.enable_timer:
args.append('-DMB_GLOBAL_ENABLE_TIMER=ON')
if 'enable_testing' in self.options:
args.append(f'-DMB_ENABLE_TESTING={self.options.enable_testing}')
def build_with_args(self, args, target=None):
# always build release, whether full release or dev-release (in debug mode)
cmake = CMake(self, build_type='Release')
args.append(f'-DMB_CONAN_PACKAGE_NAME={self.name}')
if self.settings.build_type == 'Debug':
args.extend(['-DCMAKE_BUILD_TYPE=Release', '-DMB_DEV_RELEASE=ON'])
self.add_base_args(args)
# this makes packages forward compatible with future compiler updates
args.append('-DMB_TREAT_WARNINGS_AS_ERRORS=OFF')
cmake.configure(args=args)
if self.settings.os == 'iOS':
if self.settings.os.sdk != None: # noqa: E711
if self.settings.os.sdk == 'device':
cmake.build(args=['--', '-sdk', 'iphoneos', 'ONLY_ACTIVE_ARCH=NO'])
elif self.settings.os.sdk == 'simulator':
cmake.build(args=['--', '-sdk', 'iphonesimulator', 'ONLY_ACTIVE_ARCH=NO'])
elif self.settings.os.sdk == 'maccatalyst':
# CMake currently does not support invoking Mac Catalyst builds
self.run(
"xcodebuild build -configuration Release -scheme ALL_BUILD " +
"-destination 'platform=macOS,variant=Mac Catalyst' ONLY_ACTIVE_ARCH=NO"
)
else:
# backward compatibility with old iOS toolchain and CMakeBuild < 12.0.0
cmake.build(target=target)
else:
cmake.build(target=target)
def cmake_install(self):
# always build release, whether full release or dev-release (in debug mode)
cmake = CMake(self, build_type='Release')
if self.settings.os == 'iOS':
if self.settings.os.sdk != None: # noqa: E711
if self.settings.os.sdk == 'device':
cmake.install(args=['--', '-sdk', 'iphoneos', 'ONLY_ACTIVE_ARCH=NO'])
elif self.settings.os.sdk == 'simulator':
cmake.install(args=['--', '-sdk', 'iphonesimulator', 'ONLY_ACTIVE_ARCH=NO'])
elif self.settings.os.sdk == 'maccatalyst':
# CMake currently does not support invoking Mac Catalyst builds
self.run(
"xcodebuild build -configuration Release -scheme install " +
"-destination 'platform=macOS,variant=Mac Catalyst' ONLY_ACTIVE_ARCH=NO"
)
else:
# backward compatibility with old iOS toolchain and CMakeBuild < 12.0.0
cmake.install()
else:
cmake.install()
def build(self):
self.build_with_args([])
def package_all_headers(self):
self.copy("*.h*", dst="include", src=f"{self.name}/Source")
def package_public_headers(self):
self.copy("*.h*", dst="include", src=f"{self.name}/Include")
def package_custom_libraries(self, libs, subfolders=['']):
for lib in libs:
if self.settings.os == 'Windows':
self.copy(f"{lib}.lib", src="lib", dst="lib", keep_path=False)
self.copy(f"*{lib}.pdb", src="lib", dst="lib", keep_path=False)
if self.settings.os == 'iOS':
for subfolder in subfolders:
if subfolder != '':
prefix = f'{subfolder}/'
else:
prefix = ''
if self.settings.os.sdk != None: # noqa: E711
if self.settings.os.sdk == 'device':
self.copy(f"{prefix}Release-iphoneos/{lib}.a", dst="lib", keep_path=False)
elif self.settings.os.sdk == 'simulator':
self.copy(f"{prefix}Release-iphonesimulator/{lib}.a", dst="lib", keep_path=False)
elif self.settings.os.sdk == 'maccatalyst':
self.copy(f"{prefix}Release-maccatalyst/{lib}.a", dst="lib", keep_path=False)
# Cases when add_subdirectory is used (GTest, cpuinfo)
self.copy(f"{lib}.a", src='lib', dst="lib", keep_path=False)
else:
# First copy device-only libraries (in case fat won't exists
# (i.e. CMakeBuild >= 12.0.0 is used))
self.copy(f"{prefix}Release-iphoneos/{lib}.a", dst="lib", keep_path=False)
# copy fat libraries if they exist (and overwrite those copied in previous step)
self.copy(f"*Release/{lib}.a", dst="lib", keep_path=False)
else:
self.copy(f"{lib}.a", src='lib', dst="lib", keep_path=False)
def package_all_libraries(self, subfolders=['']):
self.package_custom_libraries(['*'], subfolders)
def package(self):
self.package_public_headers()
self.package_all_libraries()
def ignore_testing_for_package_id(self):
del self.info.options.enable_testing
def common_settings_for_package_id(self):
# Conan uses semver_mode by default for all dependencies. However,
# we want some specific dependencies to be used in full_package mode,
# most notably header only libraries.
# Dependency user can always override this default behaviour.
full_package_mode_deps = {
'Boost',
'ConfigEx',
'Eigen',
'Err',
'Functionoid',
'Pimpl',
'RapidJSON',
'UTFCpp',
'Variant',
'range-v3',
}
for r in self.requires:
if r in full_package_mode_deps:
self.info.requires[r].full_package_mode()
def package_id(self):
self.ignore_testing_for_package_id()
self.common_settings_for_package_id()
def package_info(self):
if self.settings.build_type == 'Debug' \
and not conans.tools.cross_building(self.settings) and \
self.settings.compiler in ['clang', 'apple-clang'] and \
self.settings.os != 'Windows':
# runtime checks are enabled, so we need to add ASAN/UBSAN linker flags
runtime_check_flags = ['-fsanitize=undefined', '-fsanitize=address']
if self.settings.compiler == 'clang':
runtime_check_flags.append('-fsanitize=integer')
self.cpp_info.sharedlinkflags.extend(runtime_check_flags)
self.cpp_info.exelinkflags.extend(runtime_check_flags)
class MicroblinkRecognizerConanFile(MicroblinkConanFile):
options = {
'result_jsonization': ['Off', 'Serialization', 'SerializationAndTesting'],
'binary_serialization': [True, False]
}
default_options = {
'result_jsonization': 'Off'
}
def init(self):
base = self.python_requires['MicroblinkConanFile'].module.MicroblinkConanFile
self.options.update(base.options)
self.default_options.update(base.default_options)
def config_options(self):
if self.options.binary_serialization == None: # noqa: E711
if self.settings.os == 'Android':
self.options.binary_serialization = True
else:
self.options.binary_serialization = False
def configure(self):
super().configure()
self.options['*'].result_jsonization = self.options.result_jsonization
self.options['*'].binary_serialization = self.options.binary_serialization
self.options['*'].enable_testing = self.options.enable_testing
def common_recognizer_build_args(self):
cmake_args = [
f'-DRecognizer_RESULT_JSONIZATION={self.options.result_jsonization}',
f'-DRecognizer_BINARY_SERIALIZATION={self.options.binary_serialization}',
f'-DMB_ENABLE_TESTING={self.options.enable_testing}'
]
return cmake_args
def build(self):
self.build_with_args(self.common_recognizer_build_args())
def package_id(self):
self.common_settings_for_package_id()
def package(self):
self.package_public_headers()
self.package_all_libraries()
self.copy('features_*.cmake')
self.copy('Dictionary/Dictionaries/*.zzip', dst='res')
class MicroblinkConanFilePackage(conans.ConanFile):
name = "MicroblinkConanFile"
version = "8.2.1"