-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconanfile.py
142 lines (118 loc) · 6.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shutil
from conans import ConanFile, tools, CMake
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 LibpngConan(ConanFile):
name = "libpng"
version = "1.6.34"
description = "libpng is the official PNG file format reference library."
url = "http://github.com/bincrafters/conan-libpng"
homepage = "http://www.libpng.org"
license = "http://www.libpng.org/pub/png/src/libpng-LICENSE.txt"
exports = ["LICENSE.md"]
exports_sources = ["CMakeLists.txt"]
generators = "cmake"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = "shared=True", "fPIC=True"
source_subfolder = "source_subfolder"
def is_emscripten(self):
try:
return self.settings.compiler == 'emcc'
except:
return False
def requirements(self):
self.requires.add("zlib/1.2.11@conanos/dev")
def config_options(self):
if self.settings.os == "Windows":
self.options.remove("fPIC")
def configure(self):
del self.settings.compiler.libcxx
if self.is_emscripten():
del self.settings.os
del self.settings.arch
self.options.remove("fPIC")
self.options.remove("shared")
# use shared zlib for dynamic lib
if not self.is_emscripten():
if self.options.shared:
self.options['zlib'].shared = True
def source(self):
base_url = "https://sourceforge.net/projects/libpng/files/libpng16/"
tools.get("%s/%s/libpng-%s.tar.gz" %
(base_url, self.version, self.version))
#tools.get("%s/older-releases/%s/libpng-%s.tar.gz" % (base_url, self.version, self.version))
os.rename("libpng-" + self.version, self.source_subfolder)
os.rename(os.path.join(self.source_subfolder, "CMakeLists.txt"),
os.path.join(self.source_subfolder, "CMakeListsOriginal.txt"))
shutil.copy("CMakeLists.txt",
os.path.join(self.source_subfolder, "CMakeLists.txt"))
def build(self):
if not self.is_emscripten() and self.settings.os == "Windows" and self.settings.compiler == "gcc":
tools.replace_in_file("%s/CMakeListsOriginal.txt" % self.source_subfolder,
'COMMAND "${CMAKE_COMMAND}" -E copy_if_different $<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE}',
'COMMAND "${CMAKE_COMMAND}" -E copy_if_different $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/$<TARGET_LINKER_FILE_NAME:${S_TARGET}> $<TARGET_LINKER_FILE_DIR:${S_TARGET}>/${DEST_FILE}')
# do not use _static suffix on VS
if not self.is_emscripten() and self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
tools.replace_in_file("%s/CMakeListsOriginal.txt" % self.source_subfolder,
'OUTPUT_NAME "${PNG_LIB_NAME}_static',
'OUTPUT_NAME "${PNG_LIB_NAME}')
if self.settings.build_type == 'Debug':
tools.replace_in_file(os.path.join(self.source_subfolder, 'libpng.pc.in'),
'-lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@',
'-lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@d')
if not self.is_emscripten() and 'arm' in self.settings.arch and self.settings.os == "Linux":
tools.replace_in_file(os.path.join(self.source_subfolder, 'CMakeListsOriginal.txt'),
'PATHS /usr/lib /usr/local/lib',
'PATHS /usr/lib /usr/local/lib /usr/arm-linux-gnueabihf/lib /usr/arm-linux-gnueabi/lib ')
if self.is_emscripten():
tools.replace_in_file(os.path.join(self.source_subfolder, 'CMakeListsOriginal.txt'),
'symbol_prefix()',
'#symbol_prefix()')
tools.replace_in_file(os.path.join(self.source_subfolder, 'CMakeListsOriginal.txt'),
'if(NOT M_LIBRARY)',
'set(M_LIBRARY "")\n if(NOT M_LIBRARY)')
cmake = CMake(self)
cmake.definitions['CMAKE_INSTALL_LIBDIR'] = 'lib'
cmake.definitions['CMAKE_INSTALL_BINDIR'] = 'bin'
cmake.definitions['CMAKE_INSTALL_INCLUDEDIR'] = 'include'
cmake.definitions["PNG_TESTS"] = "OFF"
if self.is_emscripten():
cmake.definitions["PNG_SHARED"] = "ON"
cmake.definitions["PNG_STATIC"] = "OFF"
else:
cmake.definitions["PNG_SHARED"] = self.options.shared
cmake.definitions["PNG_STATIC"] = not self.options.shared
cmake.definitions["PNG_DEBUG"] = "OFF" if self.settings.build_type == "Release" else "ON"
cmake.configure(source_folder=self.source_subfolder)
cmake.build()
cmake.install()
def package(self):
self.copy("LICENSE", src=self.source_subfolder,
dst="licenses", ignore_case=True, keep_path=False)
shutil.rmtree(os.path.join(self.package_folder,
'share', 'man'), ignore_errors=True)
def package_info(self):
if self.is_emscripten():
self.cpp_info.libs = [
"png16"] if self.settings.build_type == "Release" else ["png16d"]
return
if self.settings.os == "Windows":
if self.settings.compiler == "gcc":
self.cpp_info.libs = ["png"]
else:
self.cpp_info.libs = ['libpng16']
else:
self.cpp_info.libs = ["png16"]
if self.settings.os == "Linux":
self.cpp_info.libs.append("m")
# use 'd' suffix everywhere except mingw
if self.settings.build_type == "Debug" and not (self.settings.os == "Windows" and self.settings.compiler == "gcc"):
self.cpp_info.libs[0] += "d"