This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
conanfile.py
187 lines (170 loc) · 9.49 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
from __future__ import print_function
from conans import ConanFile, CMake, tools
import os
class CppRestSDKConan(ConanFile):
name = "cpprestsdk"
version = "2.10.15"
description = "A project for cloud-based client-server communication in native code using a modern asynchronous " \
"C++ API design"
topics = ("conan", "cpprestsdk", "rest", "client", "http")
url = "https://github.com/bincrafters/conan-cpprestsdk"
homepage = "https://github.com/Microsoft/cpprestsdk"
license = "MIT"
exports_sources = ["CMakeLists.txt"]
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"exclude_websockets": [True, False],
"exclude_compression": [True, False],
"fPIC": [True, False]
}
default_options = {
"shared": False,
"exclude_websockets": False,
"fPIC": True,
"exclude_compression": False
}
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
root = "%s-%s" % (name, version)
short_paths = True
def configure(self):
if self.settings.compiler == 'Visual Studio':
del self.options.fPIC
def requirements(self):
self.requires.add("openssl/1.1.1f")
if not self.options.exclude_compression:
self.requires.add("zlib/1.2.11")
if not self.options.exclude_websockets:
self.requires.add("websocketpp/0.8.1")
self.requires.add("boost/1.72.0")
def source(self):
sha256 = "1c027a53457e87b0b3a475e5c8045b94400c475898c8bd51b0fbd218b99a7f7b"
tools.get("{0}/archive/v{1}.tar.gz".format(self.homepage, self.version), sha256=sha256)
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
def _configure_cmake(self):
if self.settings.os == "iOS":
with open('toolchain.cmake', 'w') as toolchain_cmake:
if self.settings.arch == "armv8":
arch = "arm64"
sdk = "iphoneos"
elif self.settings.arch == "x86_64":
arch = "x86_64"
sdk = "iphonesimulator"
sysroot = tools.XCRun(self.settings).sdk_path
toolchain_cmake.write('set(CMAKE_C_COMPILER /usr/bin/clang CACHE STRING "" FORCE)\n')
toolchain_cmake.write('set(CMAKE_CXX_COMPILER /usr/bin/clang++ CACHE STRING "" FORCE)\n')
toolchain_cmake.write('set(CMAKE_C_COMPILER_WORKS YES)\n')
toolchain_cmake.write('set(CMAKE_CXX_COMPILER_WORKS YES)\n')
toolchain_cmake.write('set(CMAKE_XCODE_EFFECTIVE_PLATFORMS "-%s" CACHE STRING "" FORCE)\n' % sdk)
toolchain_cmake.write('set(CMAKE_OSX_ARCHITECTURES "%s" CACHE STRING "" FORCE)\n' % arch)
toolchain_cmake.write('set(CMAKE_OSX_SYSROOT "%s" CACHE STRING "" FORCE)\n' % sysroot)
os.environ['CONAN_CMAKE_TOOLCHAIN_FILE'] = os.path.join(os.getcwd(), 'toolchain.cmake')
cmake = CMake(self, set_cmake_flags=True)
cmake.definitions["BUILD_TESTS"] = False
cmake.definitions["BUILD_SAMPLES"] = False
cmake.definitions["WERROR"] = False
cmake.definitions["CPPREST_EXCLUDE_WEBSOCKETS"] = self.options.exclude_websockets
cmake.definitions["CPPREST_EXCLUDE_COMPRESSION"] = self.options.exclude_compression
cmake.definitions["CPPREST_VERSION"] = self.version
cmake.definitions["OPENSSL_ROOT_DIR"] = self.deps_cpp_info['openssl'].rootpath
cmake.definitions["OPENSSL_USE_STATIC_LIBS"] = not self.options['openssl'].shared
cmake.definitions["BOOST_ROOT"] = self.deps_cpp_info["boost"].rootpath
cmake.definitions["BOOST_INCLUDEDIR"] = self.deps_cpp_info["boost"].include_paths[0]
cmake.definitions["BOOST_LIBRARYDIR"] = self.deps_cpp_info["boost"].lib_paths[0]
cmake.definitions["Boost_NO_SYSTEM_PATHS"] = True
cmake.definitions["Boost_ADDITIONAL_VERSIONS"] = "1.69.0"
cmake.definitions["Boost_USE_DEBUG_LIBS"] = self.settings.build_type == "Debug"
cmake.definitions["Boost_USE_RELEASE_LIBS"] = self.settings.build_type != "Debug"
cmake.definitions["Boost_USE_STATIC_LIBS"] = not self.options["boost"].shared
if self.settings.get_safe("compiler.runtime"):
cmake.definitions["OPENSSL_MSVC_STATIC_RT"] = 'MT' in str(self.settings.compiler.runtime)
cmake.definitions["Boost_USE_STATIC_RUNTIME"] = 'MT' in str(self.settings.compiler.runtime)
cmake.definitions["Boost_USE_DEBUG_RUNTIME"] = 'd' in str(self.settings.compiler.runtime)
if self.settings.os == "iOS":
cmake.definitions["IOS"] = True
elif self.settings.os == "Android":
cmake.definitions["ANDROID"] = True
cmake.definitions["CONAN_LIBCXX"] = ''
cmake.configure(build_folder=self._build_subfolder)
return cmake
def _patch(self):
cpprest_find_websocketpp = """
function(cpprest_find_websocketpp)
if(NOT TARGET cpprestsdk_websocketpp_internal)
add_library(cpprestsdk_websocketpp_internal INTERFACE)
target_include_directories(cpprestsdk_websocketpp_internal INTERFACE "${CONAN_INCLUDE_DIRS_WEBSOCKETPP}")
target_link_libraries(cpprestsdk_websocketpp_internal INTERFACE "${CONAN_LIBS_WEBSOCKETPP}")
endif()
endfunction()
"""
cpprest_find_openssl = """
function(cpprest_find_openssl)
if(NOT TARGET cpprestsdk_openssl_internal)
add_library(cpprestsdk_openssl_internal INTERFACE)
target_include_directories(cpprestsdk_openssl_internal INTERFACE "${CONAN_INCLUDE_DIRS_OPENSSL}")
target_link_libraries(cpprestsdk_openssl_internal INTERFACE "${CONAN_LIBS_OPENSSL}")
endif()
endfunction()
"""
tools.save(os.path.join(self._source_subfolder, "Release", "cmake", "cpprest_find_websocketpp.cmake"),
cpprest_find_websocketpp)
tools.save(os.path.join(self._source_subfolder, "Release", "cmake", "cpprest_find_openssl.cmake"),
cpprest_find_openssl)
tools.replace_in_file(os.path.join(self._source_subfolder, 'Release', 'CMakeLists.txt'), "-Wconversion", "")
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++')
if self.settings.os == 'Android':
tools.replace_in_file(os.path.join(self._source_subfolder, 'Release', 'src', 'pch', 'stdafx.h'),
'#include "boost/config/stdlib/libstdcpp3.hpp"',
'//#include "boost/config/stdlib/libstdcpp3.hpp"')
# https://github.com/Microsoft/cpprestsdk/issues/372#issuecomment-386798723
tools.replace_in_file(os.path.join(self._source_subfolder, 'Release', 'src', 'http', 'client',
'http_client_asio.cpp'),
'm_timer.expires_from_now(m_duration)',
'm_timer.expires_from_now(std::chrono::microseconds(m_duration.count()))')
def build(self):
self._patch()
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
self.copy("license.txt", dst="license", src=self._source_subfolder)
self.copy(pattern="*", dst="include", src=os.path.join(self._source_subfolder, "Release", "include"))
self.copy(pattern="*.dll", dst="bin", src="bin", keep_path=False)
self.copy(pattern="*.lib", dst="lib", src="lib", keep_path=False)
self.copy(pattern="*.a", dst="lib", src="lib", keep_path=False)
self.copy(pattern="*.so*", dst="lib", src="lib", keep_path=False)
self.copy(pattern="*.dylib", dst="lib", src="lib", keep_path=False)
def package_info(self):
if self.settings.compiler == "Visual Studio":
debug_suffix = 'd' if self.settings.build_type == 'Debug' else ''
toolset = {'12': '120',
'14': '140',
'15': '141',
'16': '142'}.get(str(self.settings.compiler.version))
version_tokens = self.version.split(".")
versioned_name = "cpprest%s_%s_%s%s" % (toolset, version_tokens[0], version_tokens[1], debug_suffix)
# CppRestSDK uses different library name depends on CMAKE_VS_PLATFORM_TOOLSET
if not os.path.isfile(os.path.join(self.package_folder, 'lib', '%s.lib' % versioned_name)):
versioned_name = "cpprest_%s_%s%s" % (version_tokens[0], version_tokens[1], debug_suffix)
lib_name = versioned_name
else:
lib_name = 'cpprest'
self.cpp_info.libs.append(lib_name)
if self.settings.os == "Linux":
self.cpp_info.libs.append("pthread")
elif self.settings.os == "Windows":
self.cpp_info.libs.extend(["winhttp", "httpapi", "bcrypt"])
elif self.settings.os == "Macos":
self.cpp_info.exelinkflags.append("-framework CoreFoundation")
self.cpp_info.exelinkflags.append("-framework Security")
self.cpp_info.sharedlinkflags.append("-framework CoreFoundation")
self.cpp_info.sharedlinkflags.append("-framework Security")
if not self.options.shared:
self.cpp_info.defines.append("_NO_ASYNCRTIMP")