Debian Codegraph @

LspCpp/third_party/ixwebsocket/CMakeLists.txt

raw
1 #
2 # Author: Benjamin Sergeant
3 # Copyright (c) 2018 Machine Zone, Inc. All rights reserved.
4 #
5
6 cmake_minimum_required(VERSION 3.4.1...3.17.2)
7 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake;${CMAKE_MODULE_PATH}")
8
9 project(ixwebsocket LANGUAGES C CXX VERSION 11.4.6)
10
11 set (CMAKE_CXX_STANDARD 11)
12 set (CXX_STANDARD_REQUIRED ON)
13 set (CMAKE_CXX_EXTENSIONS OFF)
14 set (CMAKE_EXPORT_COMPILE_COMMANDS yes)
15
16 option (BUILD_DEMO OFF)
17
18 if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
19 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
20 endif()
21
22 if (UNIX)
23 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
24 endif()
25
26 if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
27 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wshorten-64-to-32")
28 endif()
29
30 set( IXWEBSOCKET_SOURCES
31 ixwebsocket/IXBench.cpp
32 ixwebsocket/IXCancellationRequest.cpp
33 ixwebsocket/IXConnectionState.cpp
34 ixwebsocket/IXDNSLookup.cpp
35 ixwebsocket/IXExponentialBackoff.cpp
36 ixwebsocket/IXGetFreePort.cpp
37 ixwebsocket/IXGzipCodec.cpp
38 ixwebsocket/IXHttp.cpp
39 ixwebsocket/IXHttpClient.cpp
40 ixwebsocket/IXHttpServer.cpp
41 ixwebsocket/IXNetSystem.cpp
42 ixwebsocket/IXSelectInterrupt.cpp
43 ixwebsocket/IXSelectInterruptFactory.cpp
44 ixwebsocket/IXSelectInterruptPipe.cpp
45 ixwebsocket/IXSelectInterruptEvent.cpp
46 ixwebsocket/IXSetThreadName.cpp
47 ixwebsocket/IXSocket.cpp
48 ixwebsocket/IXSocketConnect.cpp
49 ixwebsocket/IXSocketFactory.cpp
50 ixwebsocket/IXSocketServer.cpp
51 ixwebsocket/IXSocketTLSOptions.cpp
52 ixwebsocket/IXStrCaseCompare.cpp
53 ixwebsocket/IXUdpSocket.cpp
54 ixwebsocket/IXUrlParser.cpp
55 ixwebsocket/IXUuid.cpp
56 ixwebsocket/IXUserAgent.cpp
57 ixwebsocket/IXWebSocket.cpp
58 ixwebsocket/IXWebSocketCloseConstants.cpp
59 ixwebsocket/IXWebSocketHandshake.cpp
60 ixwebsocket/IXWebSocketHttpHeaders.cpp
61 ixwebsocket/IXWebSocketPerMessageDeflate.cpp
62 ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp
63 ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp
64 ixwebsocket/IXWebSocketProxyServer.cpp
65 ixwebsocket/IXWebSocketServer.cpp
66 ixwebsocket/IXWebSocketTransport.cpp
67 )
68
69 set( IXWEBSOCKET_HEADERS
70 ixwebsocket/IXBase64.h
71 ixwebsocket/IXBench.h
72 ixwebsocket/IXCancellationRequest.h
73 ixwebsocket/IXConnectionState.h
74 ixwebsocket/IXDNSLookup.h
75 ixwebsocket/IXExponentialBackoff.h
76 ixwebsocket/IXGetFreePort.h
77 ixwebsocket/IXGzipCodec.h
78 ixwebsocket/IXHttp.h
79 ixwebsocket/IXHttpClient.h
80 ixwebsocket/IXHttpServer.h
81 ixwebsocket/IXNetSystem.h
82 ixwebsocket/IXProgressCallback.h
83 ixwebsocket/IXSelectInterrupt.h
84 ixwebsocket/IXSelectInterruptFactory.h
85 ixwebsocket/IXSelectInterruptPipe.h
86 ixwebsocket/IXSelectInterruptEvent.h
87 ixwebsocket/IXSetThreadName.h
88 ixwebsocket/IXSocket.h
89 ixwebsocket/IXSocketConnect.h
90 ixwebsocket/IXSocketFactory.h
91 ixwebsocket/IXSocketServer.h
92 ixwebsocket/IXSocketTLSOptions.h
93 ixwebsocket/IXStrCaseCompare.h
94 ixwebsocket/IXUdpSocket.h
95 ixwebsocket/IXUniquePtr.h
96 ixwebsocket/IXUrlParser.h
97 ixwebsocket/IXUuid.h
98 ixwebsocket/IXUtf8Validator.h
99 ixwebsocket/IXUserAgent.h
100 ixwebsocket/IXWebSocket.h
101 ixwebsocket/IXWebSocketCloseConstants.h
102 ixwebsocket/IXWebSocketCloseInfo.h
103 ixwebsocket/IXWebSocketErrorInfo.h
104 ixwebsocket/IXWebSocketHandshake.h
105 ixwebsocket/IXWebSocketHandshakeKeyGen.h
106 ixwebsocket/IXWebSocketHttpHeaders.h
107 ixwebsocket/IXWebSocketInitResult.h
108 ixwebsocket/IXWebSocketMessage.h
109 ixwebsocket/IXWebSocketMessageType.h
110 ixwebsocket/IXWebSocketOpenInfo.h
111 ixwebsocket/IXWebSocketPerMessageDeflate.h
112 ixwebsocket/IXWebSocketPerMessageDeflateCodec.h
113 ixwebsocket/IXWebSocketPerMessageDeflateOptions.h
114 ixwebsocket/IXWebSocketProxyServer.h
115 ixwebsocket/IXWebSocketSendData.h
116 ixwebsocket/IXWebSocketSendInfo.h
117 ixwebsocket/IXWebSocketServer.h
118 ixwebsocket/IXWebSocketTransport.h
119 ixwebsocket/IXWebSocketVersion.h
120 )
121
122 option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" OFF)
123 option(USE_TLS "Enable TLS support" FALSE)
124
125 if (USE_TLS)
126 # default to securetranport on Apple if nothing is configured
127 if (APPLE)
128 if (NOT USE_MBED_TLS AND NOT USE_OPEN_SSL) # unless we want something else
129 set(USE_SECURE_TRANSPORT ON)
130 endif()
131 # default to mbedtls on windows if nothing is configured
132 elseif (WIN32)
133 if (NOT USE_OPEN_SSL) # unless we want something else
134 set(USE_MBED_TLS ON)
135 endif()
136 else() # default to OpenSSL on all other platforms
137 if (NOT USE_MBED_TLS) # Unless mbedtls is requested
138 set(USE_OPEN_SSL ON)
139 set(requires "openssl")
140 endif()
141 endif()
142
143 if (USE_MBED_TLS)
144 list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketMbedTLS.h)
145 list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketMbedTLS.cpp)
146 elseif (USE_SECURE_TRANSPORT)
147 list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketAppleSSL.h)
148 list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketAppleSSL.cpp)
149 elseif (USE_OPEN_SSL)
150 list( APPEND IXWEBSOCKET_HEADERS ixwebsocket/IXSocketOpenSSL.h)
151 list( APPEND IXWEBSOCKET_SOURCES ixwebsocket/IXSocketOpenSSL.cpp)
152 else()
153 message(FATAL_ERROR "TLS Configuration error: unknown backend")
154 endif()
155 endif()
156
157 if(BUILD_SHARED_LIBS)
158 # Building shared library
159
160 if(MSVC)
161 # Workaround for some projects
162 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
163 endif()
164
165 add_library( ixwebsocket SHARED
166 ${IXWEBSOCKET_SOURCES}
167 ${IXWEBSOCKET_HEADERS}
168 )
169
170 # Set library version
171 set_target_properties(ixwebsocket PROPERTIES VERSION ${PROJECT_VERSION})
172 else()
173 # Static library
174 add_library( ixwebsocket
175 ${IXWEBSOCKET_SOURCES}
176 ${IXWEBSOCKET_HEADERS}
177 )
178 endif()
179
180 if (USE_TLS)
181 target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_TLS)
182 if (USE_MBED_TLS)
183 target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_MBED_TLS)
184 elseif (USE_OPEN_SSL)
185 target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_OPEN_SSL)
186 elseif (USE_SECURE_TRANSPORT)
187 target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_SECURE_TRANSPORT)
188 else()
189 message(FATAL_ERROR "TLS Configuration error: unknown backend")
190 endif()
191 endif()
192
193 if (USE_TLS)
194 if (USE_OPEN_SSL)
195 message(STATUS "TLS configured to use openssl")
196
197 # Help finding Homebrew's OpenSSL on macOS
198 if (APPLE)
199 set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/opt/openssl/lib)
200 set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /usr/local/opt/openssl/include)
201
202 # This is for MacPort OpenSSL 1.0
203 # set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /opt/local/lib/openssl-1.0)
204 # set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} /opt/local/include/openssl-1.0)
205 endif()
206
207 # This OPENSSL_FOUND check is to help find a cmake manually configured OpenSSL
208 if (NOT OPENSSL_FOUND)
209 find_package(OpenSSL REQUIRED)
210 endif()
211 message(STATUS "OpenSSL: " ${OPENSSL_VERSION})
212
213 add_definitions(${OPENSSL_DEFINITIONS})
214 target_include_directories(ixwebsocket PUBLIC $<BUILD_INTERFACE:${OPENSSL_INCLUDE_DIR}>)
215 target_link_libraries(ixwebsocket PRIVATE ${OPENSSL_LIBRARIES})
216 elseif (USE_MBED_TLS)
217 message(STATUS "TLS configured to use mbedtls")
218
219 # This MBEDTLS_FOUND check is to help find a cmake manually configured MbedTLS
220 if (NOT MBEDTLS_FOUND)
221 find_package(MbedTLS REQUIRED)
222
223 if (MBEDTLS_VERSION_GREATER_THAN_3)
224 target_compile_definitions(ixwebsocket PRIVATE IXWEBSOCKET_USE_MBED_TLS_MIN_VERSION_3)
225 endif()
226
227 endif()
228 target_include_directories(ixwebsocket PUBLIC $<BUILD_INTERFACE:${MBEDTLS_INCLUDE_DIRS}>)
229 target_link_libraries(ixwebsocket PRIVATE ${MBEDTLS_LIBRARIES})
230 elseif (USE_SECURE_TRANSPORT)
231 message(STATUS "TLS configured to use secure transport")
232 target_link_libraries(ixwebsocket PRIVATE "-framework Foundation" "-framework Security")
233 endif()
234 endif()
235
236 option(USE_ZLIB "Enable zlib support" TRUE)
237
238 if (USE_ZLIB)
239 find_package(ZLIB REQUIRED)
240 target_link_libraries(ixwebsocket PRIVATE ZLIB::ZLIB)
241
242 target_compile_definitions(ixwebsocket PUBLIC IXWEBSOCKET_USE_ZLIB)
243 endif()
244
245 if (WIN32)
246 target_link_libraries(ixwebsocket PRIVATE wsock32 ws2_32 shlwapi)
247 target_compile_definitions(ixwebsocket PRIVATE _CRT_SECURE_NO_WARNINGS)
248
249 if (USE_TLS)
250 target_link_libraries(ixwebsocket PRIVATE Crypt32)
251 endif()
252 endif()
253
254 if (UNIX AND NOT APPLE)
255 set(THREADS_PREFER_PTHREAD_FLAG TRUE)
256 find_package(Threads)
257 target_link_libraries(ixwebsocket PRIVATE Threads::Threads)
258 endif()
259
260
261 set( IXWEBSOCKET_INCLUDE_DIRS
262 ${CMAKE_CURRENT_SOURCE_DIR}
263 )
264
265 if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
266 # Build with Multiple Processes
267 target_compile_options(ixwebsocket PRIVATE /MP)
268 endif()
269
270 include(GNUInstallDirs)
271
272 target_include_directories(ixwebsocket PUBLIC
273 $<BUILD_INTERFACE:${IXWEBSOCKET_INCLUDE_DIRS}/>
274 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/ixwebsocket>
275 )
276
277 set_target_properties(ixwebsocket PROPERTIES PUBLIC_HEADER "${IXWEBSOCKET_HEADERS}")
278
279 add_library(ixwebsocket::ixwebsocket ALIAS ixwebsocket)
280
281 option(IXWEBSOCKET_INSTALL "Install IXWebSocket" TRUE)
282
283 if (IXWEBSOCKET_INSTALL)
284 install(TARGETS ixwebsocket
285 EXPORT ixwebsocket
286 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
287 PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ixwebsocket/
288 )
289
290 configure_file("${CMAKE_CURRENT_LIST_DIR}/ixwebsocket-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket-config.cmake" @ONLY)
291 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket-config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/ixwebsocket")
292
293 set(prefix ${CMAKE_INSTALL_PREFIX})
294 configure_file("${CMAKE_CURRENT_LIST_DIR}/ixwebsocket.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket.pc" @ONLY)
295 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ixwebsocket.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
296
297 install(EXPORT ixwebsocket
298 FILE ixwebsocket-targets.cmake
299 NAMESPACE ixwebsocket::
300 DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ixwebsocket
301 )
302 endif()
303
304 if (USE_WS OR USE_TEST)
305 include(FetchContent)
306 FetchContent_Declare(spdlog
307 GIT_REPOSITORY "https://github.com/gabime/spdlog"
308 GIT_TAG "v1.8.0"
309 GIT_SHALLOW 1)
310
311 FetchContent_MakeAvailable(spdlog)
312
313 if (USE_WS)
314 add_subdirectory(ws)
315 endif()
316 if (USE_TEST)
317 enable_testing()
318 add_subdirectory(test)
319 endif()
320 endif()
321
322 if (BUILD_DEMO)
323 add_executable(demo main.cpp)
324 target_link_libraries(demo ixwebsocket)
325 endif()