forked from bitprim/bitprim-conan-zlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
137 lines (120 loc) · 6.06 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
#
# Copyright (c) 2017 Bitprim developers (see AUTHORS)
#
# This file is part of Bitprim.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from conans import ConanFile, tools, CMake, AutoToolsBuildEnvironment
from conans.util import files
from conans import __version__ as conan_version
import os
class ZlibConan(ConanFile):
name = "zlib"
version = "1.2.8"
ZIP_FOLDER_NAME = "zlib-%s" % version
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False]}
default_options = "shared=False"
exports = ["CMakeLists.txt"]
url = "http://github.com/bitprim/bitprim-conan-zlib"
license = "http://www.zlib.net/zlib_license.html"
description = "A Massively Spiffy Yet Delicately Unobtrusive Compression Library " \
"(Also Free, Not to Mention Unencumbered by Patents)"
build_policy = "missing"
def configure(self):
del self.settings.compiler.libcxx
def source(self):
zip_name = "zlib-%s.tar.gz" % self.version
tools.download("https://zlib.net/fossils/%s" % (zip_name), zip_name)
tools.unzip(zip_name)
os.unlink(zip_name)
files.rmdir("%s/contrib" % self.ZIP_FOLDER_NAME)
if self.settings.os != "Windows":
self.run("chmod +x ./%s/configure" % self.ZIP_FOLDER_NAME)
def build(self):
with tools.chdir(self.ZIP_FOLDER_NAME):
if not tools.OSInfo().is_windows:
env_build = AutoToolsBuildEnvironment(self)
if self.settings.arch == "x86" or self.settings.arch == "x86_64":
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)
# Zlib configure doesnt allow this parameters (in 1.2.8)
env_build.configure("./", build=False, host=False, target=False)
env_build.make()
else:
files.mkdir("_build")
with tools.chdir("_build"):
cmake = CMake(self)
cmake.configure(build_dir=".")
cmake.build(build_dir=".")
def package(self):
# Extract the License/s from the header to a file
with tools.chdir(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=".")
# 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
if tools.os_info.is_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)
else:
build_dir = os.path.join(self.ZIP_FOLDER_NAME, "_build/lib")
# 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)
lib_path = os.path.join(self.package_folder, "lib")
suffix = "d" if self.settings.build_type == "Debug" else ""
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%s.lib" % suffix))
elif self.settings.compiler == "gcc":
current_lib = os.path.join(lib_path, "libzlibstatic.a")
os.rename(current_lib, os.path.join(lib_path, "libzlib.a"))
else:
build_dir = os.path.join(self.ZIP_FOLDER_NAME)
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.settings.os == "Windows":
self.cpp_info.libs = ['zlib']
if self.settings.build_type == "Debug" and self.settings.compiler == "Visual Studio":
self.cpp_info.libs[0] += "d"
else:
self.cpp_info.libs = ['z']