-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
conanfile.py
144 lines (128 loc) · 6.57 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
from conans import ConanFile, CMake, tools
import os
class CppRestSDKConan(ConanFile):
name = "cpprestsdk"
description = "A project for cloud-based client-server communication in native code using a modern asynchronous " \
"C++ API design"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/Microsoft/cpprestsdk"
topics = ("conan", "cpprestsdk", "rest", "client", "http", "https")
license = "MIT"
exports_sources = ["CMakeLists.txt", "patches/**"]
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_websockets": [True, False],
"with_compression": [True, False],
"pplx_impl": ["win", "winpplx"],
"http_client_impl": ["winhttp", "asio"],
"http_listener_impl": ["httpsys", "asio"]
}
default_options = {
"shared": False,
"fPIC": True,
"with_websockets": True,
"with_compression": True,
"pplx_impl": "win",
"http_client_impl": "winhttp",
"http_listener_impl": "httpsys"
}
_cmake = None
@property
def _source_subfolder(self):
return "source_subfolder"
@property
def _build_subfolder(self):
return "build_subfolder"
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
else:
del self.options.pplx_impl
del self.options.http_client_impl
del self.options.http_listener_impl
def configure(self):
if self.options.shared:
del self.options.fPIC
def requirements(self):
self.requires("boost/1.76.0")
self.requires("openssl/1.1.1k")
if self.options.with_compression:
self.requires("zlib/1.2.11")
if self.options.with_websockets:
self.requires("websocketpp/0.8.2")
def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self, set_cmake_flags=True)
self._cmake.definitions["BUILD_TESTS"] = False
self._cmake.definitions["BUILD_SAMPLES"] = False
self._cmake.definitions["WERROR"] = False
self._cmake.definitions["CPPREST_EXCLUDE_WEBSOCKETS"] = not self.options.with_websockets
self._cmake.definitions["CPPREST_EXCLUDE_COMPRESSION"] = not self.options.with_compression
if self.options.get_safe("pplx_impl"):
self._cmake.definitions["CPPREST_PPLX_IMPL"] = self.options.pplx_impl
if self.options.get_safe("http_client_impl"):
self._cmake.definitions["CPPREST_HTTP_CLIENT_IMPL"] = self.options.http_client_impl
if self.options.get_safe("http_listener_impl"):
self._cmake.definitions["CPPREST_HTTP_LISTENER_IMPL"] = self.options.http_listener_impl
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
def _patch_clang_libcxx(self):
if self.settings.compiler == 'clang' and str(self.settings.compiler.libcxx) in ['libstdc++', 'libstdc++11']:
tools.replace_in_file(os.path.join(self._source_subfolder, 'Release', 'CMakeLists.txt'),
'libc++', 'libstdc++')
def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, {}):
tools.patch(**patch)
self._patch_clang_libcxx()
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy("license.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "cpprestsdk"))
def package_info(self):
# cpprestsdk_boost_internal
self.cpp_info.components["cpprestsdk_boost_internal"].includedirs = []
self.cpp_info.components["cpprestsdk_boost_internal"].requires = ["boost::boost"]
# cpprestsdk_openssl_internal
self.cpp_info.components["cpprestsdk_openssl_internal"].includedirs = []
self.cpp_info.components["cpprestsdk_openssl_internal"].requires = ["openssl::openssl"]
# cpprest
self.cpp_info.components["cpprest"].libs = tools.collect_libs(self)
self.cpp_info.components["cpprest"].requires = ["cpprestsdk_boost_internal", "cpprestsdk_openssl_internal"]
if self.settings.os == "Linux":
self.cpp_info.components["cpprest"].system_libs.append("pthread")
elif self.settings.os == "Windows":
if self.options.get_safe("http_client_impl") == "winhttp":
self.cpp_info.components["cpprest"].system_libs.append("winhttp")
if self.options.get_safe("http_listener_impl") == "httpsys":
self.cpp_info.components["cpprest"].system_libs.append("httpapi")
self.cpp_info.components["cpprest"].system_libs.append("bcrypt")
if self.options.get_safe("pplx_impl") == "winpplx":
self.cpp_info.components["cpprest"].defines.append("CPPREST_FORCE_PPLX=1")
if self.options.get_safe("http_client_impl") == "asio":
self.cpp_info.components["cpprest"].defines.append("CPPREST_FORCE_HTTP_CLIENT_ASIO")
if self.options.get_safe("http_listener_impl") == "asio":
self.cpp_info.components["cpprest"].defines.append("CPPREST_FORCE_HTTP_LISTENER_ASIO")
elif self.settings.os == "Macos":
self.cpp_info.components["cpprest"].frameworks.extend(["CoreFoundation", "Security"])
if not self.options.shared:
self.cpp_info.components["cpprest"].defines.extend(["_NO_ASYNCRTIMP", "_NO_PPLXIMP"])
# cpprestsdk_zlib_internal
if self.options.with_compression:
self.cpp_info.components["cpprestsdk_zlib_internal"].includedirs = []
self.cpp_info.components["cpprestsdk_zlib_internal"].requires = ["zlib::zlib"]
self.cpp_info.components["cpprest"].requires.append("cpprestsdk_zlib_internal")
# cpprestsdk_websocketpp_internal
if self.options.with_websockets:
self.cpp_info.components["cpprestsdk_websocketpp_internal"].includedirs = []
self.cpp_info.components["cpprestsdk_websocketpp_internal"].requires = ["websocketpp::websocketpp"]
self.cpp_info.components["cpprest"].requires.append("cpprestsdk_websocketpp_internal")