forked from bincrafters/conan-libiconv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conanfile.py
129 lines (109 loc) · 4.97 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from conans import ConanFile, tools, AutoToolsBuildEnvironment
import os
class LibiconvConan(ConanFile):
name = "libiconv"
version = "1.15"
description = "Convert text to and from Unicode"
url = "https://github.com/bincrafters/conan-libiconv"
homepage = "https://www.gnu.org/software/libiconv/"
author = "Bincrafters <bincrafters@gmail.com>"
license = "LGPL-2.1"
exports = ["LICENSE.md"]
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = "shared=False", "fPIC=True"
archive_name = "{0}-{1}".format(name, version)
short_paths = True
@property
def is_mingw(self):
return self.settings.os == 'Windows' and self.settings.compiler == 'gcc'
@property
def is_msvc(self):
return self.settings.compiler == 'Visual Studio'
def configure(self):
del self.settings.compiler.libcxx
def config_options(self):
if self.settings.os == 'Windows':
del self.options.fPIC
def source(self):
source_url = "https://ftp.gnu.org/gnu/libiconv"
tools.get("{0}/{1}.tar.gz".format(source_url, self.archive_name))
def build_autotools(self):
prefix = os.path.abspath(self.package_folder)
win_bash = False
rc = None
host = None
build = None
if self.is_mingw or self.is_msvc:
prefix = prefix.replace('\\', '/')
win_bash = True
build = False
if self.settings.arch == "x86":
host = "i686-w64-mingw32"
rc = "windres --target=pe-i386"
elif self.settings.arch == "x86_64":
host = "x86_64-w64-mingw32"
rc = "windres --target=pe-x86-64"
env_build = AutoToolsBuildEnvironment(self, win_bash=win_bash)
if self.settings.os != "Windows":
env_build.fpic = self.options.fPIC
configure_args = ['--prefix=%s' % prefix]
if self.options.shared:
configure_args.extend(['--disable-static', '--enable-shared'])
else:
configure_args.extend(['--enable-static', '--disable-shared'])
env_vars = {}
if self.is_mingw:
configure_args.extend(['CPPFLAGS=-I%s/include' % prefix,
'LDFLAGS=-L%s/lib' % prefix,
'RANLIB=:'])
if self.is_msvc:
runtime = str(self.settings.compiler.runtime)
configure_args.extend(['CC=$PWD/build-aux/compile cl -nologo',
'CFLAGS=-%s' % runtime,
'CXX=$PWD/build-aux/compile cl -nologo',
'CXXFLAGS=-%s' % runtime,
'CPPFLAGS=-D_WIN32_WINNT=0x0600 -I%s/include' % prefix,
'LDFLAGS=-L%s/lib' % prefix,
'LD=link',
'NM=dumpbin -symbols',
'STRIP=:',
'AR=$PWD/build-aux/ar-lib lib',
'RANLIB=:'])
env_vars['win32_target'] = '_WIN32_WINNT_VISTA'
with tools.chdir(self.archive_name):
tools.run_in_windows_bash(self, 'chmod +x build-aux/ar-lib build-aux/compile')
if rc:
configure_args.extend(['RC=%s' % rc, 'WINDRES=%s' % rc])
with tools.chdir(self.archive_name):
with tools.environment_append(env_vars):
env_build.configure(args=configure_args, host=host, build=build)
env_build.make()
env_build.make(args=["install"])
def build(self):
if self.settings.os == "Windows":
if tools.os_info.detect_windows_subsystem() not in ("cygwin", "msys2"):
raise Exception("This recipe needs a Windows Subsystem to be compiled. "
"You can specify a build_require to:"
" 'msys2_installer/latest@bincrafters/stable' or"
" 'cygwin_installer/2.9.0@bincrafters/stable' or"
" put in the PATH your own installation")
if self.is_msvc:
with tools.vcvars(self.settings):
self.build_autotools()
elif self.is_mingw:
self.build_autotools()
else:
raise Exception("unsupported build")
else:
self.build_autotools()
def package(self):
self.copy(os.path.join(self.archive_name, "COPYING.LIB"), dst="licenses", ignore_case=True, keep_path=False)
def package_info(self):
if self.settings.os == "Windows" and self.options.shared:
self.cpp_info.libs = ['iconv.dll.lib']
else:
self.cpp_info.libs = ['iconv']
self.env_info.path.append(os.path.join(self.package_folder, "bin"))