forked from conan-community/conan-openssl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconanfile.py
395 lines (348 loc) · 19.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
from conans import ConanFile, AutoToolsBuildEnvironment
from conans import tools
from conans import __version__ as client_version
import os
import subprocess
from conans.model.version import Version
class OpenSSLConan(ConanFile):
name = "OpenSSL"
version = "1.0.2n"
settings = "os", "compiler", "arch", "build_type"
url = "http://github.com/lasote/conan-openssl"
license = "The current OpenSSL licence is an 'Apache style' license: https://www.openssl.org/source/license.html"
description = "OpenSSL is an open source project that provides a robust, commercial-grade, and full-featured " \
"toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols"
# https://github.com/openssl/openssl/blob/OpenSSL_1_0_2l/INSTALL
options = {"no_threads": [True, False],
"no_zlib": [True, False],
"shared": [True, False],
"no_asm": [True, False],
"386": [True, False],
"no_sse2": [True, False],
"no_bf": [True, False],
"no_cast": [True, False],
"no_des": [True, False],
"no_dh": [True, False],
"no_dsa": [True, False],
"no_hmac": [True, False],
"no_md2": [True, False],
"no_md5": [True, False],
"no_mdc2": [True, False],
"no_rc2": [True, False],
"no_rc4": [True, False],
"no_rc5": [True, False],
"no_rsa": [True, False],
"no_sha": [True, False]}
default_options = "=False\n".join(options.keys()) + "=False"
# When a new version is available they move the tar.gz to old/ location
source_tgz = "https://www.openssl.org/source/openssl-%s.tar.gz" % version
source_tgz_old = "https://www.openssl.org/source/old/1.0.2/openssl-%s.tar.gz" % version
def build_requirements(self):
# useful for example for conditional build_requires
if self.settings.compiler == "Visual Studio":
self.build_requires("strawberryperl/5.26.0@conan/stable")
if not self.options.no_asm and self.settings.arch == "x86":
self.build_requires("nasm/2.13.01@conan/stable")
def source(self):
self.output.info("Downloading %s" % self.source_tgz)
try:
tools.download(self.source_tgz_old, "openssl.tar.gz")
except:
tools.download(self.source_tgz, "openssl.tar.gz")
tools.unzip("openssl.tar.gz")
tools.check_sha256("openssl.tar.gz",
"370babb75f278c39e0c50e8c4e7493bc0f18db6867478341a832a982fd15a8fe")
os.unlink("openssl.tar.gz")
def configure(self):
if client_version < Version("1.0.0"):
raise Exception("This recipe only works with Conan client >= 1.0.0")
del self.settings.compiler.libcxx
if self.settings.os == "Android" and self.settings.compiler == "clang":
raise Exception("Not supported Android + Clang, please submit a patch if you know "
"how to build it: %s" % self.url)
def requirements(self):
if not self.options.no_zlib:
self.requires("zlib/1.2.11@ant/stable")
@property
def subfolder(self):
return "openssl-%s" % self.version
def build(self):
"""
For Visual Studio (tried with 2010) compiling need:
- perl: http://www.activestate.com/activeperl/downloads
- nasm: http://www.nasm.us/
Put perl and nasm bin folder in USER PATH (not system path, so the visual 2010 command system symbol can find it)
Open the visual 2010 command system symbol and run conan.
Here are good page explaining it: http://hostagebrain.blogspot.com.es/2015/04/build-openssl-on-windows.html
"""
config_options_string = ""
if "zlib" in self.deps_cpp_info.deps:
zlib_info = self.deps_cpp_info["zlib"]
include_path = zlib_info.include_paths[0]
if self.settings.os == "Windows":
lib_path = "%s/%s.lib" % (zlib_info.lib_paths[0], zlib_info.libs[0])
else:
lib_path = zlib_info.lib_paths[0] # Just path, linux will find the right file
config_options_string += ' --with-zlib-include="%s"' % include_path
config_options_string += ' --with-zlib-lib="%s"' % lib_path
tools.replace_in_file("./openssl-%s/Configure" % self.version, "::-lefence::", "::")
tools.replace_in_file("./openssl-%s/Configure" % self.version, "::-lefence ", "::")
self.output.info("=====> Options: %s" % config_options_string)
for option_name in self.options.values.fields:
activated = getattr(self.options, option_name)
if activated:
self.output.info("Activated option! %s" % option_name)
config_options_string += " %s" % option_name.replace("_", "-")
if self.settings.os in ["Linux", "SunOS", "FreeBSD", "Android"]:
self.unix_build(config_options_string)
elif self.settings.os == "Macos":
self.osx_build(config_options_string)
elif self.settings.os == "iOS":
self.ios_build(config_options_string)
elif self.settings.compiler == "Visual Studio":
self.visual_build(config_options_string)
elif self.settings.os == "Windows" and self.settings.compiler == "gcc":
self.mingw_build(config_options_string)
else:
raise Exception("Unsupported operating system: %s" % self.settings.os)
self.output.info("----------BUILD END-------------")
def run_in_src(self, command, show_output=False):
if not show_output and self.settings.os != "Windows":
command += ' | while read line; do printf "%c" .; done'
# pipe doesn't fail if first part fails
command = 'bash -l -c -o pipefail "%s"' % command.replace('"', '\\"')
with tools.chdir(self.subfolder):
self.run(command)
self.output.writeln(" ")
def unix_build(self, config_options_string):
env_build = AutoToolsBuildEnvironment(self)
extra_flags = ' '.join(env_build.flags)
target_prefix = ""
if self.settings.build_type == "Debug":
config_options_string = " no-asm" + config_options_string
extra_flags += " -O0"
target_prefix = "debug-"
if self.settings.compiler in ["apple-clang", "clang", "gcc"]:
extra_flags += " -g3 -fno-omit-frame-pointer -fno-inline-functions"
if self.settings.os == "Linux":
if self.settings.arch == "x86":
target = "%slinux-generic32" % target_prefix
elif self.settings.arch == "x86_64":
target = "%slinux-x86_64" % target_prefix
elif "armv7" in str(self.settings.arch):
target = "%slinux-armv4" % target_prefix
elif self.settings.arch == "armv8": # Thanks @dashaomai!
target = "%slinux-aarch64" % target_prefix
elif self.settings.os == "Android":
if "armv7" in self.settings.arch:
target = "android-armv7"
elif self.settings.arch == "armv8":
target = "android-aarch64"
elif self.settings.arch == "x86":
target = "android-x86"
elif self.settings.arch == "mips":
target = "android-mips"
else:
raise Exception("Unsupported arch for android")
elif self.settings.os == "SunOS":
if self.settings.compiler in ["apple-clang", "clang", "gcc"]:
suffix = "-gcc"
elif self.settings.compiler == "sun-cc":
suffix = "-cc"
else:
raise Exception("Unsupported compiler on SunOS: %s" % self.settings.compiler)
# OpenSSL has no debug profile for non sparcv9 machine
if self.settings.arch != "sparcv9":
target_prefix = ""
if self.settings.arch in ["sparc", "x86"]:
target = "%ssolaris-%s%s" % (target_prefix, self.settings.arch, suffix)
elif self.settings.arch in ["sparcv9", "x86_64"]:
target = "%ssolaris64-%s%s" % (target_prefix, self.settings.arch, suffix)
else:
raise Exception("Unsupported arch on SunOS: %s" % self.settings.arch)
elif self.settings.os == "FreeBSD":
target = "%sBSD-%s" % (target_prefix, self.settings.arch)
else:
raise Exception("Unsupported operating system: %s" % self.settings.os)
config_line = "./Configure %s -fPIC %s %s" % (config_options_string, target, extra_flags)
self.output.warn(config_line)
self.run_in_src(config_line)
if self.settings.os != "Android":
self.run_in_src("make depend")
self.output.warn("----------MAKE OPENSSL %s-------------" % self.version)
self.run_in_src("make", show_output=True)
def ios_build(self, config_options_string):
def call(cmd):
return subprocess.check_output(cmd, shell=False).strip()
def find_sysroot(sdk_name):
return call(["xcrun", "--show-sdk-path", "-sdk", sdk_name])
def find_program(program, sdk_name=None):
args = ["xcrun", "--find", program]
if sdk_name:
args.extend(["-sdk", sdk_name])
return call(args)
def to_apple_arch(arch):
"""converts conan-style architecture into Apple-style arch"""
return {'x86': 'i386',
'x86_64': 'x86_64',
'armv7': 'armv7',
'armv8': 'arm64',
'armv7s': 'armv7s',
'armv7k': 'armv7k'}.get(str(arch))
def apple_sdk_name(settings):
"""returns proper SDK name suitable for OS and architecture
we're building for (considering simulators)"""
arch = settings.get_safe('arch')
_os = settings.get_safe('os')
if str(arch).startswith('x86'):
return {'Macos': 'macosx',
'iOS': 'iphonesimulator',
'watchOS': 'watchsimulator',
'tvOS': 'appletvsimulator'}.get(str(_os))
elif str(arch).startswith('arm'):
return {'iOS': 'iphoneos',
'watchOS': 'watchos',
'tvOS': 'appletvos'}.get(str(_os))
else:
return None
command = "./Configure iphoneos-cross %s" % config_options_string
sdk = apple_sdk_name(self.settings)
sysroot = find_sysroot(sdk)
cc = find_program("clang", sdk)
cc += " -arch %s" % to_apple_arch(self.settings.arch)
if not str(self.settings.arch).startswith("arm"):
cc += " -DOPENSSL_NO_ASM"
os.environ["CROSS_SDK"] = os.path.basename(sysroot)
os.environ["CROSS_TOP"] = os.path.dirname(os.path.dirname(sysroot))
command = 'CC="%s" %s' % (cc, command)
self.run_in_src(command)
# REPLACE -install_name FOR FOLLOW THE CONAN RULES,
# DYNLIBS IDS AND OTHER DYNLIB DEPS WITHOUT PATH, JUST THE LIBRARY NAME
old_str = 'SHAREDFLAGS="$$SHAREDFLAGS -install_name $(INSTALLTOP)/$(LIBDIR)/$$SHLIB$'
new_str = 'SHAREDFLAGS="$$SHAREDFLAGS -install_name $$SHLIB$'
tools.replace_in_file("./openssl-%s/Makefile.shared" % self.version, old_str, new_str)
self.output.warn("----------MAKE OPENSSL %s-------------" % self.version)
self.run_in_src("make")
def osx_build(self, config_options_string):
m32_suff = " -m32" if self.settings.arch == "x86" else ""
if self.settings.arch == "x86_64":
command = "./Configure darwin64-x86_64-cc %s" % config_options_string
else:
command = "./config %s %s" % (config_options_string, m32_suff)
self.run_in_src(command)
# REPLACE -install_name FOR FOLLOW THE CONAN RULES,
# DYNLIBS IDS AND OTHER DYNLIB DEPS WITHOUT PATH, JUST THE LIBRARY NAME
old_str = 'SHAREDFLAGS="$$SHAREDFLAGS -install_name $(INSTALLTOP)/$(LIBDIR)/$$SHLIB$'
new_str = 'SHAREDFLAGS="$$SHAREDFLAGS -install_name $$SHLIB$'
tools.replace_in_file("./openssl-%s/Makefile.shared" % self.version, old_str, new_str)
self.output.warn("----------MAKE OPENSSL %s-------------" % self.version)
self.run_in_src("make")
def visual_build(self, config_options_string):
self.run_in_src("perl --version")
self.output.warn("----------CONFIGURING OPENSSL FOR WINDOWS. %s-------------" % self.version)
debug = "debug-" if self.settings.build_type == "Debug" else ""
arch = "32" if self.settings.arch == "x86" else "64A"
configure_type = debug + "VC-WIN" + arch
no_asm = "no-asm" if self.options.no_asm else ""
# Will output binaries to ./binaries
with tools.vcvars(self.settings, filter_known_paths=False):
config_command = "perl Configure %s %s --prefix=../binaries" % (configure_type, no_asm)
whole_command = "%s %s" % (config_command, config_options_string)
self.output.warn(whole_command)
self.run_in_src(whole_command)
if not self.options.no_asm and self.settings.arch == "x86":
# The 64 bits builds do not require the do_nasm
# http://p-nand-q.com/programming/windows/building_openssl_with_visual_studio_2013.html
self.run_in_src(r"ms\do_nasm")
else:
if arch == "64A":
self.run_in_src(r"ms\do_win64a")
else:
self.run_in_src(r"ms\do_ms")
runtime = self.settings.compiler.runtime
# Replace runtime in ntdll.mak and nt.mak
def replace_runtime_in_file(filename):
runtimes = ["MDd", "MTd", "MD", "MT"]
for e in runtimes:
try:
tools.replace_in_file(filename, "/%s" % e, "/%s" % runtime)
self.output.warn("replace vs runtime %s in %s" % ("/%s" % e, filename))
return # we found a runtime argument in the file, so we can exit the function
except:
pass
raise Exception("Could not find any vs runtime in file")
replace_runtime_in_file("./openssl-%s/ms/ntdll.mak" % self.version)
replace_runtime_in_file("./openssl-%s/ms/nt.mak" % self.version)
if self.settings.arch == "x86": # Do not consider warning as errors, 1.0.2n error with x86 builds
tools.replace_in_file("./openssl-%s/ms/nt.mak" % self.version, "-WX", "")
tools.replace_in_file("./openssl-%s/ms/ntdll.mak" % self.version, "-WX", "")
make_command = "nmake -f ms\\ntdll.mak" if self.options.shared else "nmake -f ms\\nt.mak "
self.output.warn("----------MAKE OPENSSL %s-------------" % self.version)
self.run_in_src(make_command)
self.run_in_src("%s install" % make_command)
# Rename libs with the arch
renames = {"./binaries/lib/libeay32.lib": "./binaries/lib/libeay32%s.lib" % runtime,
"./binaries/lib/ssleay32.lib": "./binaries/lib/ssleay32%s.lib" % runtime}
for old, new in renames.items():
if os.path.exists(old):
os.rename(old, new)
def mingw_build(self, config_options_string):
# https://netix.dl.sourceforge.net/project/msys2/Base/x86_64/msys2-x86_64-20161025.exe
config_options_string = tools.unix_path(config_options_string)
if self.settings.build_type == "Debug":
config_options_string = "-g " + config_options_string
if self.settings.arch == "x86":
config_line = "./Configure mingw %s" % config_options_string
else:
config_line = "./Configure mingw64 %s" % config_options_string
self.output.warn(config_line)
with tools.chdir(self.subfolder):
tools.run_in_windows_bash(self, config_line)
self.output.warn("----------MAKE OPENSSL %s-------------" % self.version)
# tools.run_in_windows_bash(self, "make depend")
tools.run_in_windows_bash(self, "make")
def package(self):
# Copy the license files
self.copy("%s/LICENSE" % self.subfolder, keep_path=False)
self.copy(pattern="*applink.c", dst="include/openssl/", keep_path=False)
if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
self._copy_visual_binaries()
self.copy(pattern="*.h", dst="include/openssl/", src="binaries/include/", keep_path=False)
elif self.settings.os == "Windows" and self.settings.compiler == "gcc":
self.copy(pattern="%s/include/*" % self.subfolder, dst="include/openssl/", keep_path=False)
if self.options.shared:
self.copy(pattern="%s/libcrypto.dll.a" % self.subfolder, dst="lib", keep_path=False)
self.copy(pattern="%s/libssl.dll.a" % self.subfolder, dst="lib", keep_path=False)
self.copy(pattern="%s/libeay32.dll" % self.subfolder, dst="bin", keep_path=False)
self.copy(pattern="%s/ssleay32.dll" % self.subfolder, dst="bin", keep_path=False)
else:
self.copy(pattern="%s/libcrypto.a" % self.subfolder, dst="lib", keep_path=False)
self.copy(pattern="%s/libssl.a" % self.subfolder, dst="lib", keep_path=False)
else:
if self.options.shared:
self.copy(pattern="*libcrypto*.dylib", dst="lib", keep_path=False)
self.copy(pattern="*libssl*.dylib", dst="lib", keep_path=False)
self.copy(pattern="*libcrypto.so*", dst="lib", keep_path=False)
self.copy(pattern="*libssl.so*", dst="lib", keep_path=False)
else:
self.copy("*.a", "lib", keep_path=False)
self.copy(pattern="%s/include/*" % self.subfolder, dst="include/openssl/", keep_path=False)
def _copy_visual_binaries(self):
self.copy(pattern="*.lib", dst="lib", src="binaries/lib", keep_path=False)
self.copy(pattern="*.dll", dst="bin", src="binaries/bin", keep_path=False)
self.copy(pattern="*.dll", dst="bin", src="binaries/bin", keep_path=False)
suffix = str(self.settings.compiler.runtime)
lib_path = os.path.join(self.package_folder, "lib")
current_ssleay = os.path.join(lib_path, "ssleay32%s.lib" % suffix)
current_libeay = os.path.join(lib_path, "libeay32%s.lib" % suffix)
os.rename(current_ssleay, os.path.join(lib_path, "ssleay32.lib"))
os.rename(current_libeay, os.path.join(lib_path, "libeay32.lib"))
def package_info(self):
if self.settings.compiler == "Visual Studio":
self.cpp_info.libs = ["ssleay32", "libeay32", "crypt32", "msi", "ws2_32"]
elif self.settings.compiler == "gcc" and self.settings.os == "Windows":
self.cpp_info.libs = ["ssl", "crypto", "ws2_32"]
elif self.settings.os == "Linux":
self.cpp_info.libs = ["ssl", "crypto", "dl"]
else:
self.cpp_info.libs = ["ssl", "crypto"]