This repository has been archived by the owner on Sep 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
conanfile.py
164 lines (148 loc) · 7.35 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild
import os
import six
import shutil
class LZMAConan(ConanFile):
name = "lzma"
version = "5.2.4"
description = "LZMA library is part of XZ Utils (a free general-purpose data compression software.)"
url = "https://github.com/bincrafters/conan-lzma"
homepage = "https://tukaani.org"
license = "Public Domain"
author = "Bincrafters <bincrafters@gmail.com>"
exports = ["LICENSE.md"]
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {'shared': False, 'fPIC': True}
description = "LZMA library is part of XZ Utils"
_source_subfolder = 'sources'
# copied from conan, need to make expose it
def _system_registry_key(self, key, subkey, query):
from six.moves import winreg # @UnresolvedImport
try:
hkey = winreg.OpenKey(key, subkey)
except (OSError, WindowsError): # Raised by OpenKey/Ex if the function fails (py3, py2)
return None
else:
try:
value, _ = winreg.QueryValueEx(hkey, query)
return value
except EnvironmentError:
return None
finally:
winreg.CloseKey(hkey)
def _find_windows_10_sdk(self):
"""finds valid Windows 10 SDK version which can be passed to vcvarsall.bat (vcvars_command)"""
# uses the same method as VCVarsQueryRegistry.bat
from six.moves import winreg # @UnresolvedImport
hives = [
(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Wow6432Node'),
(winreg.HKEY_CURRENT_USER, r'SOFTWARE\Wow6432Node'),
(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE'),
(winreg.HKEY_CURRENT_USER, r'SOFTWARE')
]
for key, subkey in hives:
subkey = r'%s\Microsoft\Microsoft SDKs\Windows\v10.0' % subkey
installation_folder = self._system_registry_key(key, subkey, 'InstallationFolder')
if installation_folder:
if os.path.isdir(installation_folder):
include_dir = os.path.join(installation_folder, 'include')
for sdk_version in os.listdir(include_dir):
if (os.path.isdir(os.path.join(include_dir, sdk_version))
and sdk_version.startswith('10.')):
windows_h = os.path.join(include_dir, sdk_version, 'um', 'Windows.h')
if os.path.isfile(windows_h):
return sdk_version
return None
@property
def _use_winbash(self):
# Linux MinGW doesn't require MSYS2 bash obviously
return tools.os_info.is_windows and (self.settings.compiler == 'gcc' or tools.cross_building(self.settings))
def build_requirements(self):
if self._use_winbash and "CONAN_BASH_PATH" not in os.environ:
self.build_requires("msys2_installer/latest@bincrafters/stable")
def _effective_msbuild_type(self):
# treat 'RelWithDebInfo' and 'MinSizeRel' as 'Release'
return 'Debug' if self.settings.build_type == 'Debug' else 'Release'
def configure(self):
del self.settings.compiler.libcxx
if self.settings.compiler == 'Visual Studio':
del self.options.fPIC
def source(self):
archive_name = "xz-%s.tar.gz" % self.version
source_url = "https://tukaani.org/xz/%s" % archive_name
tools.get(source_url)
os.rename('xz-' + self.version, self._source_subfolder)
def _build_msvc(self):
# windows\INSTALL-MSVC.txt
compiler_version = float(self.settings.compiler.version.value)
msvc_version = 'vs2017' if compiler_version >= 15 else 'vs2013'
with tools.chdir(os.path.join(self._source_subfolder, 'windows', msvc_version)):
target = 'liblzma_dll' if self.options.shared else 'liblzma'
msbuild = MSBuild(self)
winsdk_version = self._find_windows_10_sdk()
if not winsdk_version:
raise Exception("Windows 10 SDK wasn't found")
if msvc_version == "vs2017":
for project in ["liblzma.vcxproj", "liblzma_dll.vcxproj"]:
tools.replace_in_file(project,
"<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>",
"<WindowsTargetPlatformVersion>%s</WindowsTargetPlatformVersion>" % winsdk_version)
msbuild.build(
'xz_win.sln',
targets=[target],
build_type=self._effective_msbuild_type(),
platforms={'x86': 'Win32', 'x86_64': 'x64'},
use_env=False,
winsdk_version=winsdk_version)
def _build_configure(self):
with tools.chdir(self._source_subfolder):
env_build = AutoToolsBuildEnvironment(self, win_bash=self._use_winbash)
args = ['--disable-xz',
'--disable-xzdec',
'--disable-lzmadec',
'--disable-lzmainfo',
'--disable-scripts',
'--disable-doc']
if self.settings.os != "Windows" and self.options.fPIC:
args.append('--with-pic')
if self.options.shared:
args.extend(['--disable-static', '--enable-shared'])
else:
args.extend(['--enable-static', '--disable-shared'])
if self.settings.build_type == 'Debug':
args.append('--enable-debug')
env_build.configure(args=args, build=False)
env_build.make()
env_build.install()
def build(self):
if self.settings.compiler == 'Visual Studio':
self._build_msvc()
else:
self._build_configure()
def package(self):
self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder)
if self.settings.compiler == "Visual Studio":
inc_dir = os.path.join(self._source_subfolder, 'src', 'liblzma', 'api')
self.copy(pattern="*.h", dst="include", src=inc_dir, keep_path=True)
arch = {'x86': 'Win32', 'x86_64': 'x64'}.get(str(self.settings.arch))
target = 'liblzma_dll' if self.options.shared else 'liblzma'
compiler_version = float(self.settings.compiler.version.value)
msvc_version = 'vs2017' if compiler_version >= 15 else 'vs2013'
bin_dir = os.path.join(self._source_subfolder, 'windows', msvc_version,
str(self._effective_msbuild_type()), arch, target)
self.copy(pattern="*.lib", dst="lib", src=bin_dir, keep_path=False)
if self.options.shared:
self.copy(pattern="*.dll", dst="bin", src=bin_dir, keep_path=False)
shutil.move(os.path.join(self.package_folder, 'lib', 'liblzma.lib'),
os.path.join(self.package_folder, 'lib', 'lzma.lib'))
la = os.path.join(self.package_folder, "lib", "liblzma.la")
if os.path.isfile(la):
os.unlink(la)
def package_info(self):
self.cpp_info.builddirs = ["lib/pkgconfig"]
if not self.options.shared:
self.cpp_info.defines.append('LZMA_API_STATIC')
self.cpp_info.libs = tools.collect_libs(self)