forked from conan-community/conan-opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
419 lines (380 loc) · 18.1 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile, CMake, tools
from conans.model.version import Version
from conans.errors import ConanInvalidConfiguration
import os
class OpenCVConan(ConanFile):
name = "opencv"
version = "4.0.1"
license = "BSD-3-Clause"
homepage = "https://github.com/opencv/opencv"
url = "https://github.com/conan-community/conan-opencv"
author = "Conan Community"
topics = ("conan", "opencv", "computer-vision",
"image-processing", "deep-learning")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False],
"fPIC": [True, False],
"contrib": [True, False],
"jpeg": [True, False],
"jpegturbo": [True, False],
"tiff": [True, False],
"webp": [True, False],
"png": [True, False],
"jasper": [True, False],
"openexr": [True, False],
"gtk": [None, 2, 3],
"nonfree": [True, False],
"dc1394": [True, False],
"carotene": [True, False],
"cuda": [True, False]}
default_options = {"shared": False,
"fPIC": True,
"contrib": False,
"jpeg": True,
"jpegturbo": False,
"tiff": True,
"webp": True,
"png": True,
"jasper": True,
"openexr": True,
"gtk": 3,
"nonfree": False,
"dc1394": True,
"carotene": False,
"cuda": False}
exports_sources = ["CMakeLists.txt"]
exports = "LICENSE"
generators = "cmake"
description = "OpenCV is an open source computer vision and machine learning software library."
short_paths = True
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
def configure(self):
compiler_version = Version(self.settings.compiler.version.value)
if self.settings.compiler == "Visual Studio" and compiler_version < "14":
raise ConanInvalidConfiguration(
"OpenCV 4.x requires Visual Studio 2015 and higher")
if self.options.cuda and not self.options.contrib:
raise ConanInvalidConfiguration(
"opencv:cuda requires opencv:contrib")
def source(self):
sha256 = "7b86a0ee804244e0c407321f895b15e4a7162e9c5c0d2efc85f1cadec4011af4"
tools.get("{}/archive/{}.tar.gz".format(self.homepage,
self.version))
os.rename('opencv-%s' % self.version, self._source_subfolder)
sha256 = "0d8acbad4b7074cfaafd906a7419c23629179d5e98894714402090b192ef8237"
tools.get(
"https://github.com/opencv/opencv_contrib/archive/{}.tar.gz".format(self.version))
os.rename('opencv_contrib-%s' % self.version, 'contrib')
if self.settings.os != 'Android' and not self.options.carotene:
tools.rmdir(os.path.join(self._source_subfolder, '3rdparty'))
def config_options(self):
if self.settings.os == 'Windows':
del self.options.fPIC
if self.settings.os != 'Linux':
del self.options.gtk
def system_requirements(self):
if self.settings.os == 'Linux' and tools.os_info.is_linux:
if tools.os_info.with_apt:
installer = tools.SystemPackageTool()
arch_suffix = ''
if self.settings.arch == 'x86':
arch_suffix = ':i386'
elif self.settings.arch == 'x86_64':
arch_suffix = ':amd64'
packages = []
if self.options.gtk == 2:
packages.append('libgtk2.0-dev%s' % arch_suffix)
elif self.options.gtk == 3:
packages.append('libgtk-3-dev%s' % arch_suffix)
for package in packages:
installer.install(package)
elif tools.os_info.with_yum:
installer = tools.SystemPackageTool()
arch_suffix = ''
if self.settings.arch == 'x86':
arch_suffix = '.i686'
elif self.settings.arch == 'x86_64':
arch_suffix = '.x86_64'
packages = []
if self.options.gtk == 2:
packages.append('gtk2-devel%s' % arch_suffix)
elif self.options.gtk == 3:
packages.append('gtk3-devel%s' % arch_suffix)
for package in packages:
installer.install(package)
def requirements(self):
self.requires.add('zlib/1.2.11@conan/stable')
if self.options.jpeg:
# NOTE : use the same libjpeg implementation as jasper uses
# otherwise, jpeg_create_decompress will fail on version check
if self.options.jpegturbo:
self.requires.add('libjpeg-turbo/1.5.2@bincrafters/stable')
else:
self.requires.add('libjpeg/9c@bincrafters/stable')
if self.options.tiff:
self.requires.add('libtiff/4.0.9@bincrafters/stable')
if self.options.webp:
self.requires.add('libwebp/1.0.0@bincrafters/stable')
if self.options.png:
self.requires.add('libpng/1.6.34@bincrafters/stable')
if self.options.jasper:
self.requires.add('jasper/2.0.14@conan/stable')
if self.options.openexr:
self.requires.add('openexr/2.3.0@conan/stable')
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions['BUILD_EXAMPLES'] = False
cmake.definitions['BUILD_DOCS'] = False
cmake.definitions['BUILD_TESTS'] = False
cmake.definitions['BUILD_PERF_TEST'] = False
cmake.definitions['WITH_IPP'] = False
cmake.definitions['BUILD_IPP_IW'] = False
cmake.definitions['BUILD_opencv_apps'] = False
cmake.definitions['BUILD_opencv_java'] = False
cmake.definitions['BUILD_opencv_python'] = False
cmake.definitions['BUILD_opencv_python2'] = False
cmake.definitions['BUILD_opencv_python3'] = False
cmake.definitions['INSTALL_C_EXAMPLES'] = False
cmake.definitions['INSTALL_PYTHON_EXAMPLES'] = False
cmake.definitions['BUILD_opencv_python_bindings_generator'] = False
cmake.definitions['BUILD_opencv_js'] = False
cmake.definitions['BUILD_opencv_java_bindings_generator'] = False
if self.settings.compiler == 'Visual Studio':
cmake.definitions['BUILD_WITH_STATIC_CRT'] = 'MT' in str(
self.settings.compiler.runtime)
if self.settings.os != 'Windows':
cmake.definitions['ENABLE_PIC'] = self.options.fPIC
# 3rd-party
# disable builds for all 3rd-party components, use libraries from conan only
cmake.definitions['BUILD_ZLIB'] = False
cmake.definitions['BUILD_TIFF'] = False
cmake.definitions['BUILD_JASPER'] = False
cmake.definitions['BUILD_JPEG'] = False
cmake.definitions['BUILD_PNG'] = False
cmake.definitions['BUILD_OPENEXR'] = False
cmake.definitions['BUILD_WEBP'] = False
cmake.definitions['BUILD_TBB'] = False
cmake.definitions['BUILD_IPP_IW'] = False
cmake.definitions['BUILD_ITT'] = False
cmake.definitions['BUILD_JPEG_TURBO_DISABLE'] = True
cmake.definitions['WITH_JPEG'] = self.options.jpeg
cmake.definitions['WITH_TIFF'] = self.options.tiff
cmake.definitions['WITH_WEBP'] = self.options.webp
cmake.definitions['WITH_PNG'] = self.options.png
cmake.definitions['WITH_JASPER'] = self.options.jasper
cmake.definitions['WITH_OPENEXR'] = self.options.openexr
cmake.definitions["WITH_1394"] = self.options.dc1394
cmake.definitions['WITH_PROTOBUF'] = False
cmake.definitions['WITH_FFMPEG'] = False
cmake.definitions['WITH_QUIRC'] = False
cmake.definitions['WITH_CAROTENE'] = self.options.carotene
cmake.definitions['WITH_CUDA'] = self.options.cuda
# This allows compilation on older GCC/NVCC, otherwise build errors.
cmake.definitions['CUDA_NVCC_FLAGS'] = '--expt-relaxed-constexpr'
if self.options.openexr:
cmake.definitions['OPENEXR_ROOT'] = self.deps_cpp_info['openexr'].rootpath
# system libraries
if self.settings.os == 'Linux':
cmake.definitions['WITH_GTK'] = self.options.gtk is not None
cmake.definitions['WITH_GTK_2_X'] = self.options.gtk == 2
if self.options.contrib:
cmake.definitions['OPENCV_EXTRA_MODULES_PATH'] = os.path.join(
self.build_folder, 'contrib', 'modules')
if self.options.nonfree:
cmake.definitions['OPENCV_ENABLE_NONFREE'] = True
if self.settings.os == 'Android':
cmake.definitions['ANDROID_STL'] = self.settings.compiler.libcxx
cmake.definitions['ANDROID_NATIVE_API_LEVEL'] = self.settings.os.api_level
cmake.definitions['BUILD_PERF_TESTS'] = False
cmake.definitions['BUILD_ANDROID_EXAMPLES'] = False
arch = str(self.settings.arch)
if arch.startswith(('armv7', 'armv8')):
cmake.definitions['ANDROID_ABI'] = 'NEON'
else:
cmake.definitions['ANDROID_ABI'] = {'armv5': 'armeabi',
'armv6': 'armeabi-v6',
'armv7': 'armeabi-v7a',
'armv7hf': 'armeabi-v7a',
'armv8': 'arm64-v8a'}.get(arch, arch)
if 'ANDROID_NDK_HOME' in os.environ:
cmake.definitions['ANDROID_NDK'] = os.environ.get(
'ANDROID_NDK_HOME')
cmake.configure(build_folder=self._build_subfolder)
return cmake
def build(self):
# https://github.com/opencv/opencv/issues/8010
if str(self.settings.compiler) == 'clang' and str(self.settings.compiler.version) == '3.9':
tools.replace_in_file(os.path.join(self._source_subfolder, 'modules', 'imgproc', 'CMakeLists.txt'),
'ocv_define_module(imgproc opencv_core WRAP java python js)',
'ocv_define_module(imgproc opencv_core WRAP java python js)\n'
'set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/'
'imgwarp.cpp PROPERTIES COMPILE_FLAGS "-O0")')
# allow to find conan-supplied OpenEXR
if self.options.openexr:
find_openexr = os.path.join(
self._source_subfolder, 'cmake', 'OpenCVFindOpenEXR.cmake')
tools.replace_in_file(find_openexr,
r'SET(OPENEXR_ROOT "C:/Deploy" CACHE STRING "Path to the OpenEXR \"Deploy\" folder")',
'')
tools.replace_in_file(find_openexr, r'set(OPENEXR_ROOT "")', '')
tools.replace_in_file(
find_openexr, 'SET(OPENEXR_LIBSEARCH_SUFFIXES x64/Release x64 x64/Debug)', '')
tools.replace_in_file(find_openexr, 'SET(OPENEXR_LIBSEARCH_SUFFIXES Win32/Release Win32 Win32/Debug)',
'')
def openexr_library_names(name):
# OpenEXR library may have different names, depends on namespace versioning, static, debug, etc.
reference = str(self.requires["openexr"])
version_name = reference.split("@")[0]
version = version_name.split("/")[1]
version_tokens = version.split('.')
major, minor = version_tokens[0], version_tokens[1]
suffix = '%s_%s' % (major, minor)
names = ['%s-%s' % (name, suffix),
'%s-%s_s' % (name, suffix),
'%s-%s_d' % (name, suffix),
'%s-%s_s_d' % (name, suffix),
'%s' % name,
'%s_s' % name,
'%s_d' % name,
'%s_s_d' % name]
return ' '.join(names)
for lib in ['Half', 'Iex', 'Imath', 'IlmImf', 'IlmThread']:
tools.replace_in_file(find_openexr, 'NAMES %s' %
lib, 'NAMES %s' % openexr_library_names(lib))
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
cmake.patch_config_paths()
def add_libraries_from_pc(self, library):
pkg_config = tools.PkgConfig(library)
libs = [lib[2:] for lib in pkg_config.libs_only_l] # cut -l prefix
lib_paths = [lib[2:]
for lib in pkg_config.libs_only_L] # cut -L prefix
self.cpp_info.libs.extend(libs)
self.cpp_info.libdirs.extend(lib_paths)
self.cpp_info.sharedlinkflags.extend(pkg_config.libs_only_other)
self.cpp_info.exelinkflags.extend(pkg_config.libs_only_other)
def package_info(self):
opencv_libs = ["stitching",
"photo",
"video",
"ml",
"calib3d",
"features2d",
"highgui",
"videoio",
"flann",
"imgcodecs",
"objdetect",
"imgproc",
"core"]
if self.settings.os != 'Android':
# gapi depends on ade but ade disabled for Android
# https://github.com/opencv/opencv/blob/4.0.1/modules/gapi/cmake/DownloadADE.cmake#L2
opencv_libs.append("gapi")
if self.options.contrib:
opencv_libs = [
"aruco",
"bgsegm",
"bioinspired",
"ccalib",
"datasets",
"dpm",
"face",
"freetype",
"fuzzy",
"hfs",
"img_hash",
"line_descriptor",
"optflow",
"phase_unwrapping",
"plot",
"reg",
"rgbd",
"saliency",
"shape",
"stereo",
"structured_light",
"superres",
"surface_matching",
"tracking",
"videostab",
"xfeatures2d",
"ximgproc",
"xobjdetect",
"xphoto"] + opencv_libs
if self.options.cuda:
opencv_libs = ["cudaarithm",
"cudabgsegm",
"cudacodec",
"cudafeatures2d",
"cudafilters",
"cudaimgproc",
"cudalegacy",
"cudaobjdetect",
"cudaoptflow",
"cudastereo",
"cudawarping",
"cudev"
] + opencv_libs
suffix = 'd' if self.settings.build_type == 'Debug' and self.settings.compiler == 'Visual Studio' else ''
version = self.version.replace(
".", "") if self.settings.os == "Windows" else ""
for lib in opencv_libs:
self.cpp_info.libs.append("opencv_%s%s%s" % (lib, version, suffix))
if self.settings.compiler == 'Visual Studio':
arch = {'x86': 'x86',
'x86_64': 'x64'}.get(str(self.settings.arch))
vc = 'vc%s' % str(self.settings.compiler.version)
bindir = os.path.join(self.package_folder, arch, vc, 'bin')
libdir = os.path.join(
self.package_folder, arch, vc, 'lib' if self.options.shared else 'staticlib')
self.cpp_info.bindirs.append(bindir)
self.cpp_info.libdirs.append(libdir)
if self.options.cuda:
cuda_platform = {'x86': 'Win32',
'x86_64': 'x64'}.get(str(self.settings.arch))
cuda_path = os.environ.get('CUDA_PATH')
self.cpp_info.libdirs.append(os.path.join(cuda_path, "lib", cuda_platform))
if self.options.cuda:
self.cpp_info.libs.extend(["nvrtc", "cudart", "cuda"])
if self.settings.os == "Linux":
self.cpp_info.libs.extend([
"pthread",
"m",
"dl"])
if self.options.gtk == 2:
self.add_libraries_from_pc('gtk+-2.0')
elif self.options.gtk == 3:
self.add_libraries_from_pc('gtk+-3.0')
elif self.settings.os == 'Macos':
for framework in ['OpenCL',
'Accelerate',
'CoreMedia',
'CoreVideo',
'CoreGraphics',
'AVFoundation',
'QuartzCore',
'Cocoa']:
self.cpp_info.exelinkflags.append('-framework %s' % framework)
self.cpp_info.sharedlinkflags = self.cpp_info.exelinkflags
elif self.settings.os == 'Windows':
self.cpp_info.libs.append('Vfw32')
if self.settings.os == 'Android' and not self.options.shared:
self.cpp_info.includedirs.append(
os.path.join('sdk', 'native', 'jni', 'include'))
self.cpp_info.libdirs.append(
os.path.join('sdk', 'native', 'staticlibs'))
else:
self.cpp_info.includedirs.append(
os.path.join('include', 'opencv4'))
self.cpp_info.libdirs.append(
os.path.join('lib', 'opencv4', '3rdparty'))
if not self.options.shared:
self.cpp_info.libs.append('ade')