-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconanfile.py
118 lines (98 loc) · 4.85 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
from conans import ConanFile, tools, AutoToolsBuildEnvironment
import shutil
import os
import platform
class LibusbConan(ConanFile):
name = 'libusb'
source_version = '1.0.23'
package_version = '0'
version = '%s-%s' % (source_version, package_version)
build_requires = (
'llvm/5.0.2-1@vuo/stable',
'macos-sdk/11.0-0@vuo/stable',
)
settings = 'os', 'compiler', 'build_type', 'arch'
url = 'https://github.com/libusb/libusb'
license = 'https://github.com/libusb/libusb/blob/master/COPYING'
description = 'A library for USB device access'
source_dir = 'libusb-%s' % source_version
build_x86_dir = '_build_x86'
build_arm_dir = '_build_arm'
install_x86_dir = '_install_x86'
install_arm_dir = '_install_arm'
install_universal_dir = '_install_universal_dir'
def requirements(self):
if platform.system() == 'Linux':
self.requires('patchelf/0.10pre-1@vuo/stable')
elif platform.system() != 'Darwin':
raise Exception('Unknown platform "%s"' % platform.system())
def source(self):
tools.get('https://github.com/libusb/libusb/releases/download/v%s/libusb-%s.tar.bz2' % (self.source_version, self.source_version),
sha256='db11c06e958a82dac52cf3c65cb4dd2c3f339c8a988665110e0d24d19312ad8d')
self.run('mv %s/COPYING %s/%s.txt' % (self.source_dir, self.source_dir, self.name))
def build(self):
autotools = AutoToolsBuildEnvironment(self)
# The LLVM/Clang libs get automatically added by the `requires` line,
# but this package doesn't need to link with them.
autotools.libs = []
autotools.flags.append('-Oz')
if platform.system() == 'Darwin':
autotools.flags.append('-isysroot %s' % self.deps_cpp_info['macos-sdk'].rootpath)
autotools.flags.append('-mmacosx-version-min=10.11')
autotools.link_flags.append('-Wl,-install_name,@rpath/libusb.dylib')
common_configure_args = [
'--quiet',
'--disable-dependency-tracking',
'--disable-static',
'--enable-shared',
]
env_vars = {
'CC' : self.deps_cpp_info['llvm'].rootpath + '/bin/clang',
'CXX': self.deps_cpp_info['llvm'].rootpath + '/bin/clang++',
}
with tools.environment_append(env_vars):
build_root = os.getcwd()
self.output.info("=== Build for x86_64 ===")
tools.mkdir(self.build_x86_dir)
with tools.chdir(self.build_x86_dir):
autotools.flags.append('-arch x86_64')
autotools.link_flags.append('-arch x86_64')
autotools.configure(configure_dir='../%s' % self.source_dir,
build=False,
host=False,
args=common_configure_args + [
'--prefix=%s/%s' % (build_root, self.install_x86_dir),
])
autotools.make(args=['--quiet'])
autotools.make(target='install', args=['--quiet'])
self.output.info("=== Build for arm64 ===")
tools.mkdir(self.build_arm_dir)
with tools.chdir(self.build_arm_dir):
autotools.flags.remove('-arch x86_64')
autotools.flags.append('-arch arm64')
autotools.link_flags.remove('-arch x86_64')
autotools.link_flags.append('-arch arm64')
autotools.configure(configure_dir='../%s' % self.source_dir,
build=False,
host=False,
args=common_configure_args + [
'--prefix=%s/%s' % (build_root, self.install_arm_dir),
'--host=x86_64-apple-darwin15.0.0',
])
autotools.make(args=['--quiet'])
autotools.make(target='install', args=['--quiet'])
def package(self):
if platform.system() == 'Darwin':
libext = 'dylib'
elif platform.system() == 'Linux':
libext = 'so'
else:
raise Exception('Unknown platform "%s"' % platform.system())
tools.mkdir(self.install_universal_dir)
with tools.chdir(self.install_universal_dir):
self.run('lipo -create ../%s/lib/libusb-1.0.%s ../%s/lib/libusb-1.0.%s -output libusb.%s' % (self.install_x86_dir, libext, self.install_arm_dir, libext, libext))
self.copy('*.h', src='%s/include' % self.install_x86_dir, dst='include')
self.copy('libusb.%s' % libext, src=self.install_universal_dir, dst='lib')
self.copy('%s.txt' % self.name, src=self.source_dir, dst='license')
def package_info(self):
self.cpp_info.libs = ['usb']