-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathCMakeLists.txt
296 lines (276 loc) · 10.7 KB
/
CMakeLists.txt
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
cmake_policy(SET CMP0022 NEW)
file(GLOB HEADERS_CPPREST "../include/cpprest/*.h" "../include/cpprest/*.hpp" "../include/cpprest/*.dat")
file(GLOB HEADERS_PPLX "../include/pplx/*.h" "../include/pplx/*.hpp")
file(GLOB HEADERS_DETAILS "../include/cpprest/details/*.h" "../include/cpprest/details/*.hpp" "../include/cpprest/details/*.dat" "../include/pplx/*.hpp" "../include/pplx/*.dat")
source_group("Header Files\\cpprest" FILES ${HEADERS_CPPREST})
source_group("Header Files\\pplx" FILES ${HEADERS_PPLX})
source_group("Header Files\\cpprest\\details" FILES ${HEADERS_DETAILS})
file(GLOB HEADER_PPLX_THREADPOOL "../include/pplx/threadpool.h")
list(REMOVE_ITEM HEADERS_PPLX ${HEADER_PPLX_THREADPOOL})
set(SOURCES
${HEADERS_CPPREST}
${HEADERS_PPLX}
${HEADERS_DETAILS}
pch/stdafx.h
http/client/http_client.cpp
http/client/http_client_impl.h
http/client/http_client_msg.cpp
http/common/connection_pool_helpers.h
http/common/http_compression.cpp
http/common/http_helpers.cpp
http/common/http_msg.cpp
http/common/internal_http_helpers.h
http/listener/http_listener.cpp
http/listener/http_listener_msg.cpp
http/listener/http_server_api.cpp
http/listener/http_server_impl.h
http/oauth/oauth1.cpp
http/oauth/oauth2.cpp
json/json.cpp
json/json_parsing.cpp
json/json_serialization.cpp
uri/uri.cpp
uri/uri_builder.cpp
utilities/asyncrt_utils.cpp
utilities/base64.cpp
utilities/web_utilities.cpp
)
add_library(cpprest ${SOURCES})
target_include_directories(cpprest
PUBLIC
$<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
PRIVATE
pch
)
## Sub-components
# Websockets component
if(CPPREST_WEBSOCKETS_IMPL STREQUAL "none")
target_compile_definitions(cpprest PUBLIC -DCPPREST_EXCLUDE_WEBSOCKETS=1)
elseif(CPPREST_WEBSOCKETS_IMPL STREQUAL "winrt")
target_sources(cpprest PRIVATE
websockets/client/ws_msg.cpp
websockets/client/ws_client.cpp
websockets/client/ws_client_impl.h
websockets/client/ws_client_winrt.cpp
)
elseif(CPPREST_WEBSOCKETS_IMPL STREQUAL "wspp")
target_sources(cpprest PRIVATE
websockets/client/ws_msg.cpp
websockets/client/ws_client.cpp
websockets/client/ws_client_impl.h
websockets/client/ws_client_wspp.cpp
)
cpprest_find_websocketpp()
target_link_libraries(cpprest PRIVATE cpprestsdk_websocketpp_internal)
cpprest_find_boost()
cpprest_find_openssl()
target_link_libraries(cpprest PUBLIC cpprestsdk_boost_internal cpprestsdk_openssl_internal)
else()
message(FATAL_ERROR "Invalid implementation")
endif()
# Compression component
if(CPPREST_EXCLUDE_COMPRESSION)
if(NOT CPPREST_EXCLUDE_BROTLI)
message(FATAL_ERROR "Use of Brotli requires compression to be enabled")
endif()
target_compile_definitions(cpprest PRIVATE -DCPPREST_EXCLUDE_COMPRESSION=1)
else()
cpprest_find_zlib()
target_link_libraries(cpprest PRIVATE cpprestsdk_zlib_internal)
if(CPPREST_EXCLUDE_BROTLI)
target_compile_definitions(cpprest PRIVATE -DCPPREST_EXCLUDE_BROTLI=1)
else()
cpprest_find_brotli()
endif()
endif()
# PPLX component
if(CPPREST_PPLX_IMPL STREQUAL "apple")
find_library(COREFOUNDATION CoreFoundation "/")
find_library(SECURITY Security "/")
target_link_libraries(cpprest PRIVATE ${COREFOUNDATION} ${SECURITY})
target_sources(cpprest PRIVATE pplx/pplxapple.cpp pplx/pplx.cpp pplx/threadpool.cpp ../include/pplx/threadpool.h)
if(CPPREST_INSTALL_HEADERS)
install(FILES ../include/pplx/threadpool.h DESTINATION include/pplx)
endif()
elseif(CPPREST_PPLX_IMPL STREQUAL "linux")
target_sources(cpprest PRIVATE pplx/pplxlinux.cpp pplx/pplx.cpp pplx/threadpool.cpp ../include/pplx/threadpool.h)
if(CPPREST_INSTALL_HEADERS)
install(FILES ../include/pplx/threadpool.h DESTINATION include/pplx)
endif()
elseif(CPPREST_PPLX_IMPL STREQUAL "win")
target_sources(cpprest PRIVATE pplx/pplxwin.cpp)
if(CPPREST_WEBSOCKETS_IMPL STREQUAL "wspp")
target_sources(cpprest PRIVATE pplx/threadpool.cpp ../include/pplx/threadpool.h)
if(CPPREST_INSTALL_HEADERS)
install(FILES ../include/pplx/threadpool.h DESTINATION include/pplx)
endif()
endif()
elseif(CPPREST_PPLX_IMPL STREQUAL "winpplx")
target_compile_definitions(cpprest PUBLIC -DCPPREST_FORCE_PPLX=1)
target_sources(cpprest PRIVATE pplx/pplxwin.cpp pplx/pplx.cpp pplx/threadpool.cpp ../include/pplx/threadpool.h)
if(CPPREST_INSTALL_HEADERS)
install(FILES ../include/pplx/threadpool.h DESTINATION include/pplx)
endif()
elseif(CPPREST_PPLX_IMPL STREQUAL "winrt")
target_sources(cpprest PRIVATE pplx/pplxwin.cpp)
else()
message(FATAL_ERROR "Invalid implementation")
endif()
# Http client component
if(CPPREST_HTTP_CLIENT_IMPL STREQUAL "asio")
cpprest_find_boost()
cpprest_find_openssl()
target_compile_definitions(cpprest PUBLIC -DCPPREST_FORCE_HTTP_CLIENT_ASIO)
target_sources(cpprest PRIVATE http/client/http_client_asio.cpp http/client/x509_cert_utilities.cpp)
target_link_libraries(cpprest PUBLIC cpprestsdk_boost_internal cpprestsdk_openssl_internal)
elseif(CPPREST_HTTP_CLIENT_IMPL STREQUAL "winhttppal")
cpprest_find_boost()
cpprest_find_openssl()
cpprest_find_winhttppal()
target_compile_definitions(cpprest PUBLIC -DCPPREST_FORCE_HTTP_CLIENT_WINHTTPPAL)
target_sources(cpprest PRIVATE http/client/http_client_winhttp.cpp http/client/x509_cert_utilities.cpp)
target_link_libraries(cpprest PUBLIC cpprestsdk_boost_internal cpprestsdk_openssl_internal cpprestsdk_winhttppal_internal)
elseif(CPPREST_HTTP_CLIENT_IMPL STREQUAL "winhttp")
target_link_libraries(cpprest PRIVATE
Winhttp.lib
)
target_sources(cpprest PRIVATE http/client/http_client_winhttp.cpp)
if(CPPREST_WEBSOCKETS_IMPL STREQUAL "wspp")
target_sources(cpprest PRIVATE http/client/x509_cert_utilities.cpp)
endif()
elseif(CPPREST_HTTP_CLIENT_IMPL STREQUAL "winrt")
target_sources(cpprest PRIVATE http/client/http_client_winrt.cpp)
else()
message(FATAL_ERROR "Invalid implementation")
endif()
# fileio streams component
if(CPPREST_FILEIO_IMPL STREQUAL "win32")
target_sources(cpprest PRIVATE streams/fileio_win32.cpp)
elseif(CPPREST_FILEIO_IMPL STREQUAL "winrt")
target_sources(cpprest PRIVATE streams/fileio_winrt.cpp)
elseif(CPPREST_FILEIO_IMPL STREQUAL "posix")
target_sources(cpprest PRIVATE streams/fileio_posix.cpp)
else()
message(FATAL_ERROR "Invalid implementation")
endif()
# http listener component
if(CPPREST_HTTP_LISTENER_IMPL STREQUAL "asio")
cpprest_find_boost()
cpprest_find_openssl()
target_compile_definitions(cpprest PUBLIC -DCPPREST_FORCE_HTTP_LISTENER_ASIO)
target_sources(cpprest PRIVATE http/listener/http_server_asio.cpp)
target_link_libraries(cpprest PUBLIC cpprestsdk_boost_internal cpprestsdk_openssl_internal)
elseif(CPPREST_HTTP_LISTENER_IMPL STREQUAL "httpsys")
target_sources(cpprest PRIVATE
http/listener/http_server_httpsys.cpp
http/listener/http_server_httpsys.h
)
target_link_libraries(cpprest PRIVATE
httpapi.lib
)
elseif(CPPREST_HTTP_LISTENER_IMPL STREQUAL "none")
else()
message(FATAL_ERROR "Invalid implementation")
endif()
configure_pch(cpprest stdafx.h pch/stdafx.cpp /Zm120)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(WERROR)
target_compile_options(cpprest PRIVATE -Werror)
endif()
target_compile_options(cpprest PRIVATE -pedantic ${WARNINGS})
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
if(WERROR)
target_compile_options(cpprest PRIVATE /WX ${WARNINGS})
endif()
else()
message(FATAL_ERROR "Unknown compiler")
endif()
if(WIN32)
if (BUILD_SHARED_LIBS)
target_compile_definitions(cpprest PRIVATE -D_ASYNCRT_EXPORT -D_PPLX_EXPORT -D_USRDLL)
else()
target_compile_definitions(cpprest PUBLIC -D_NO_ASYNCRTIMP -D_NO_PPLXIMP)
endif()
elseif(ANDROID)
target_link_libraries(cpprest PRIVATE ${ANDROID_STL_FLAGS})
endif()
if (WIN32 AND NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
target_link_libraries(cpprest PRIVATE
bcrypt.lib
crypt32.lib
)
elseif(WINDOWS_STORE)
if(NOT CMAKE_GENERATOR MATCHES "Visual Studio .*")
target_compile_definitions(cpprest PRIVATE -DWINAPI_FAMILY=WINAPI_FAMILY_PC_APP)
get_target_property(LINK_FLAGS cpprest LINK_FLAGS)
if(NOT LINK_FLAGS)
set(LINK_FLAGS "")
endif()
set(LINK_FLAGS "${LINK_FLAGS} /APPCONTAINER")
set_target_properties(cpprest PROPERTIES LINK_FLAGS "${LINK_FLAGS}")
endif()
endif()
set_target_properties(cpprest PROPERTIES OUTPUT_NAME "cpprest${CPPREST_ABI_TAG}")
if(WIN32)
elseif(ANDROID)
# Do not use SOVERSION on android. It is completely unsupported (and causes problems).
# Perhaps revisit in the future? (NDK r9d, 8/7/14)
else()
set_target_properties(cpprest PROPERTIES
SOVERSION ${CPPREST_VERSION_MAJOR}.${CPPREST_VERSION_MINOR})
endif()
if(CPPREST_INSTALL_HEADERS)
install(FILES ${HEADERS_CPPREST} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpprest)
install(FILES ${HEADERS_PPLX} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/pplx)
install(FILES ${HEADERS_DETAILS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cpprest/details)
endif()
if(CPPREST_INSTALL)
set(CPPREST_USES_BOOST OFF)
set(CPPREST_USES_ZLIB OFF)
set(CPPREST_USES_BROTLI OFF)
set(CPPREST_USES_OPENSSL OFF)
set(CPPREST_USES_WINHTTPPAL OFF)
set(CPPREST_TARGETS cpprest)
if(TARGET cpprestsdk_boost_internal)
list(APPEND CPPREST_TARGETS cpprestsdk_boost_internal)
set(CPPREST_USES_BOOST ON)
endif()
if(TARGET cpprestsdk_zlib_internal)
list(APPEND CPPREST_TARGETS cpprestsdk_zlib_internal)
set(CPPREST_USES_ZLIB ON)
endif()
if(TARGET cpprestsdk_brotli_internal)
list(APPEND CPPREST_TARGETS cpprestsdk_brotli_internal)
set(CPPREST_USES_BROTLI ON)
endif()
if(TARGET cpprestsdk_openssl_internal)
list(APPEND CPPREST_TARGETS cpprestsdk_openssl_internal)
set(CPPREST_USES_OPENSSL ON)
endif()
if(TARGET cpprestsdk_winhttppal_internal)
list(APPEND CPPREST_TARGETS cpprestsdk_winhttppal_internal)
set(CPPREST_USES_WINHTTPPAL ON)
endif()
if(TARGET cpprestsdk_websocketpp_internal)
list(APPEND CPPREST_TARGETS cpprestsdk_websocketpp_internal)
endif()
install(
TARGETS ${CPPREST_TARGETS}
EXPORT cpprestsdk-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
configure_file(../cmake/cpprestsdk-config.in.cmake "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config.cmake" @ONLY)
configure_file(../cmake/cpprestsdk-config-version.in.cmake "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config-version.cmake" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cpprestsdk-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CPPREST_EXPORT_DIR}
)
install(
EXPORT cpprestsdk-targets
FILE cpprestsdk-targets.cmake
NAMESPACE cpprestsdk::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CPPREST_EXPORT_DIR}
)
endif()