This repository has been archived by the owner on Sep 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconanfile.py
126 lines (112 loc) · 5.65 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
# -*- coding: utf-8 -*-
from conans import ConanFile, AutoToolsBuildEnvironment, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os
class LibpqConan(ConanFile):
name = "libpq"
version = "11.5"
description = "The library used by all the standard PostgreSQL tools."
topics = ("conan", "libpq", "postgresql", "database", "db")
url = "/~https://github.com/bincrafters/conan-libpq"
homepage = "https://www.postgresql.org/docs/current/static/libpq.html"
author = "Bincrafters <bincrafters@gmail.com>"
license = "PostgreSQL"
exports = ["LICENSE.md"]
exports_sources = ["CMakeLists.txt"]
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_zlib": [True, False],
"with_openssl": [True, False],
"disable_rpath": [True, False]}
default_options = {'shared': False, 'fPIC': True, 'with_zlib': True, 'with_openssl': False, 'disable_rpath': False}
generators = "cmake"
_autotools = None
@property
def _source_subfolder(self):
return "source_subfolder"
@property
def _is_clang8_x86(self):
return self.settings.os == "Linux" and \
self.settings.compiler == "clang" and \
self.settings.compiler.version == "8" and \
self.settings.arch == "x86"
def config_options(self):
if self.settings.os == 'Windows':
del self.options.fPIC
def configure(self):
del self.settings.compiler.libcxx
if self.settings.os == 'Windows' and self.options.shared:
raise ConanInvalidConfiguration("libpq can not be built as shared library on Windows")
def requirements(self):
if self.options.with_zlib:
self.requires.add("zlib/1.2.11@conan/stable")
if self.options.with_openssl:
self.requires.add("OpenSSL/1.0.2s@conan/stable")
def source(self):
source_url = "https://ftp.postgresql.org/pub/source"
sha256 = "f639af0f8c3f1e470e41c8108cbdaea5836b2738cadd422135aa2a0febc8ae78"
tools.get("{0}/v{1}/postgresql-{2}.tar.gz".format(source_url, self.version, self.version), sha256=sha256)
extracted_dir = "postgresql-" + self.version
os.rename(extracted_dir, self._source_subfolder)
def _configure_autotools(self):
if not self._autotools:
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
args = ['--without-readline']
args.append('--with-zlib' if self.options.with_zlib else '--without-zlib')
args.append('--with-openssl' if self.options.with_openssl else '--without-openssl')
if self.options.disable_rpath:
args.append('--disable-rpath')
if self._is_clang8_x86:
self._autotools.flags.append("-msse2")
with tools.chdir(self._source_subfolder):
self._autotools.configure(args=args)
return self._autotools
def _configure_cmake(self):
cmake = CMake(self)
cmake.configure()
return cmake
def build(self):
if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
cmake = self._configure_cmake()
cmake.definitions["USE_OPENSSL"] = self.options.with_openssl
cmake.definitions["USE_ZLIB"] = self.options.with_zlib
cmake.build()
else:
autotools = self._configure_autotools()
with tools.chdir(os.path.join(self._source_subfolder, "src", "backend")):
autotools.make(target="generated-headers")
with tools.chdir(os.path.join(self._source_subfolder, "src", "common")):
autotools.make()
with tools.chdir(os.path.join(self._source_subfolder, "src", "include")):
autotools.make()
with tools.chdir(os.path.join(self._source_subfolder, "src", "interfaces", "libpq")):
autotools.make()
with tools.chdir(os.path.join(self._source_subfolder, "src", "bin", "pg_config")):
autotools.make()
def package(self):
self.copy(pattern="COPYRIGHT", dst="licenses", src=self._source_subfolder)
if self.settings.os == "Windows" and self.settings.compiler == "Visual Studio":
cmake = self._configure_cmake()
cmake.install()
else:
autotools = self._configure_autotools()
with tools.chdir(os.path.join(self._source_subfolder, "src", "common")):
autotools.install()
with tools.chdir(os.path.join(self._source_subfolder, "src", "include")):
autotools.install()
with tools.chdir(os.path.join(self._source_subfolder, "src", "interfaces", "libpq")):
autotools.install()
with tools.chdir(os.path.join(self._source_subfolder, "src", "bin", "pg_config")):
autotools.install()
tools.rmdir(os.path.join(self.package_folder, "include", "postgresql", "server"))
self.copy(pattern="*.h", dst=os.path.join("include", "catalog"), src=os.path.join(self._source_subfolder, "src", "include", "catalog"))
self.copy(pattern="*.h", dst=os.path.join("include", "catalog"), src=os.path.join(self._source_subfolder, "src", "backend", "catalog"))
def package_info(self):
self.env_info.PostgreSQL_ROOT = self.package_folder
self.cpp_info.libs = tools.collect_libs(self)
if self.settings.os == "Linux":
self.cpp_info.libs.append("pthread")
elif self.settings.os == "Windows":
self.cpp_info.libs.extend(["ws2_32", "secur32", "advapi32", "shell32", "crypt32"])