-
Notifications
You must be signed in to change notification settings - Fork 1
/
conanfile.py
221 lines (199 loc) · 10.5 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
from conans import ConanFile, tools, CMake, AutoToolsBuildEnvironment
from conans.util import files
import os
try:
import conanos.conan.hacks.cmake
except:
if os.environ.get('EMSCRIPTEN_VERSIONS'):
raise Exception(
'Please use pip install conanos to patch conan for emscripten binding !')
class ZlibConan(ConanFile):
name = "zlib"
version = "1.2.11"
ZIP_FOLDER_NAME = "zlib-%s" % version
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False] }
default_options = "shared=False"
exports_sources = ["CMakeLists.txt"]
url = "http://github.com/conanos/zlib"
license = "Zlib"
description = "A Massively Spiffy Yet Delicately Unobtrusive Compression Library " \
"(Also Free, Not to Mention Unencumbered by Patents)"
def is_emscripten(self):
try:
return self.settings.compiler == 'emcc'
except:
return False
def config_options(self):
if self.is_emscripten():
self.options.remove("fPIC")
self.options.remove("shared")
def configure(self):
del self.settings.compiler.libcxx
if self.is_emscripten():
del self.settings.os
del self.settings.arch
def source(self):
z_name = "zlib-%s.tar.gz" % self.version
tools.download("https://zlib.net/zlib-%s.tar.gz" %
self.version, z_name)
tools.unzip(z_name)
os.unlink(z_name)
files.rmdir("%s/contrib" % self.ZIP_FOLDER_NAME)
if not tools.os_info.is_windows:
self.run("chmod +x ./%s/configure" % self.ZIP_FOLDER_NAME)
def build(self):
with tools.chdir(os.path.join(self.source_folder, self.ZIP_FOLDER_NAME)):
for filename in ['zconf.h', 'zconf.h.cmakein', 'zconf.h.in']:
tools.replace_in_file(filename,
'#ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */',
'#if defined(HAVE_UNISTD_H) && (1-HAVE_UNISTD_H-1 != 0)')
tools.replace_in_file(filename,
'#ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */',
'#if defined(HAVE_STDARG_H) && (1-HAVE_STDARG_H-1 != 0)')
if self.is_emscripten():
tools.replace_in_file('CMakeLists.txt',
'add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})',
'#iadd_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})')
tools.replace_in_file('CMakeLists.txt',
'set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z)',
'set_target_properties(zlib PROPERTIES OUTPUT_NAME z)')
tools.replace_in_file('CMakeLists.txt',
'install(TARGETS zlib zlibstatic',
'install(TARGETS zlib ')
files.mkdir("_build")
with tools.chdir("_build"):
if not tools.os_info.is_windows and not self.is_emscripten():
env_build = AutoToolsBuildEnvironment(self)
if self.settings.arch in ["x86", "x86_64"] and self.settings.compiler in ["apple-clang", "clang", "gcc"]:
env_build.flags.append('-mstackrealign')
env_build.fpic = True
if self.settings.os == "Macos":
old_str = '-install_name $libdir/$SHAREDLIBM'
new_str = '-install_name $SHAREDLIBM'
tools.replace_in_file("../configure", old_str, new_str)
if self.settings.os == "Windows": # Cross building to Linux
tools.replace_in_file(
"../configure", 'LDSHAREDLIBC="${LDSHAREDLIBC--lc}"', 'LDSHAREDLIBC=""')
# Zlib configure doesnt allow this parameters
if self.settings.os == "iOS":
tools.replace_in_file(
"../gzguts.h", '#ifdef _LARGEFILE64_SOURCE', '#include <unistd.h>\n\n#ifdef _LARGEFILE64_SOURCE')
if self.settings.os == "Windows" and tools.os_info.is_linux:
# Let our profile to declare what is needed.
tools.replace_in_file(
"../win32/Makefile.gcc", 'LDFLAGS = $(LOC)', '')
tools.replace_in_file(
"../win32/Makefile.gcc", 'AS = $(CC)', '')
tools.replace_in_file(
"../win32/Makefile.gcc", 'AR = $(PREFIX)ar', '')
tools.replace_in_file(
"../win32/Makefile.gcc", 'CC = $(PREFIX)gcc', '')
tools.replace_in_file(
"../win32/Makefile.gcc", 'RC = $(PREFIX)windres', '')
self.run("cd .. && make -f win32/Makefile.gcc")
else:
_args = ["--prefix=%s/build"%(os.getcwd())]
if not self.options.shared:
_args.extend(['--static'])
env_build.configure(
"../", build=False, host=False, target=False, args=_args)
env_build.make()
env_build.install()
else:
cmake = CMake(self)
cmake.configure(build_dir=".")
cmake.build(build_dir=".")
def package(self):
self.output.warn("local cache: %s" % self.in_local_cache)
self.output.warn("develop: %s" % self.develop)
# Extract the License/s from the header to a file
with tools.chdir(os.path.join(self.source_folder, self.ZIP_FOLDER_NAME)):
tmp = tools.load("zlib.h")
license_contents = tmp[2:tmp.find("*/", 1)]
tools.save("LICENSE", license_contents)
# Copy the license files
self.copy("LICENSE", src=self.ZIP_FOLDER_NAME, dst=".")
if not tools.os_info.is_linux:
# Copy pc file
self.copy("*.pc", dst="", keep_path=False)
# Copying zlib.h, zutil.h, zconf.h
self.copy("*.h", "include", "%s" %
self.ZIP_FOLDER_NAME, keep_path=False)
self.copy("*.h", "include", "%s" % "_build", keep_path=False)
# Copying static and dynamic libs
build_dir = os.path.join(self.ZIP_FOLDER_NAME, "_build")
lib_path = os.path.join(self.package_folder, "lib")
suffix = "d" if self.settings.build_type == "Debug" else ""
if self.is_emscripten():
self.copy(pattern="*.so*", dst="lib",
src=build_dir, keep_path=False)
return
if self.settings.os == "Windows":
if self.options.shared:
build_dir = os.path.join(self.ZIP_FOLDER_NAME, "_build")
self.copy(pattern="*.dll", dst="bin",
src=build_dir, keep_path=False)
build_dir = os.path.join(self.ZIP_FOLDER_NAME, "_build/lib")
self.copy(pattern="*zlibd.lib", dst="lib",
src=build_dir, keep_path=False)
self.copy(pattern="*zlib.lib", dst="lib",
src=build_dir, keep_path=False)
self.copy(pattern="*zlib.dll.a", dst="lib",
src=build_dir, keep_path=False)
if tools.os_info.is_linux:
self.copy(pattern="*libz.dll.a", dst="lib",
src=self.ZIP_FOLDER_NAME)
if self.settings.compiler == "Visual Studio":
current_lib = os.path.join(lib_path, "zlib%s.lib" % suffix)
os.rename(current_lib, os.path.join(lib_path, "zlib.lib"))
else:
build_dir = os.path.join(self.ZIP_FOLDER_NAME, "_build/lib")
if self.settings.os == "Windows":
if tools.os_info.is_windows:
# MinGW
self.copy(pattern="libzlibstaticd.a",
dst="lib", src=build_dir, keep_path=False)
self.copy(pattern="libzlibstatic.a", dst="lib",
src=build_dir, keep_path=False)
# Visual Studio
self.copy(pattern="zlibstaticd.lib", dst="lib",
src=build_dir, keep_path=False)
self.copy(pattern="zlibstatic.lib", dst="lib",
src=build_dir, keep_path=False)
if tools.os_info.is_linux:
self.copy(pattern="libz.a", dst="lib",
src=self.ZIP_FOLDER_NAME, keep_path=False)
if self.settings.compiler == "Visual Studio":
current_lib = os.path.join(
lib_path, "zlibstatic%s.lib" % suffix)
os.rename(current_lib, os.path.join(lib_path, "zlib.lib"))
elif self.settings.compiler == "gcc":
if not tools.os_info.is_linux:
current_lib = os.path.join(lib_path, "libzlibstatic.a")
os.rename(current_lib, os.path.join(
lib_path, "libzlib.a"))
elif tools.os_info.is_linux:
if self.options.shared:
os.remove('%s/_build/build/lib/libz.a'%(self.ZIP_FOLDER_NAME))
self.copy("*", src="%s/_build/build"%(self.ZIP_FOLDER_NAME))
else:
if self.options.shared:
if self.settings.os == "Macos":
self.copy(pattern="*.dylib", dst="lib",
src=build_dir, keep_path=False)
else:
self.copy(pattern="*.so*", dst="lib",
src=build_dir, keep_path=False)
else:
self.copy(pattern="*.a", dst="lib",
src=build_dir, keep_path=False)
def package_info(self):
if self.is_emscripten():
self.cpp_info.libs = ['z']
return
if self.settings.os == "Windows" and not tools.os_info.is_linux:
self.cpp_info.libs = ['zlib']
else:
self.cpp_info.libs = ['z']