private.h: rename to contain dir
[platform/upstream/libwebsockets.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.9)
2
3 # General Advice
4 #
5 # For selecting between DEBUG / RELEASE, use -DCMAKE_BUILD_TYPE=DEBUG or =RELEASE
6 #   debug builds include source level debug info and extra logging
7
8 set(LWS_WITH_BUNDLED_ZLIB_DEFAULT OFF)
9 if(WIN32)
10         set(LWS_WITH_BUNDLED_ZLIB_DEFAULT ON)
11 endif()
12
13 set(LWS_ROLE_RAW 1)
14 set(LWS_WITH_POLL 1)
15
16 #
17 # Select features recommended for PC distro packaging
18 #
19 option(LWS_WITH_DISTRO_RECOMMENDED "Enable features recommended for distro packaging" OFF)
20 option(LWS_FOR_GITOHASHI "Enable features recommended for use with gitohashi" OFF)
21
22 #
23 # Major individual features
24 #
25 option(LWS_WITH_NETWORK "Compile with network-related code" ON)
26 option(LWS_ROLE_H1 "Compile with support for http/1 (needed for ws)" ON)
27 option(LWS_ROLE_WS "Compile with support for websockets" ON)
28 option(LWS_ROLE_DBUS "Compile with support for DBUS" OFF)
29 option(LWS_ROLE_RAW_PROXY "Raw packet proxy" OFF)
30 option(LWS_WITH_HTTP2 "Compile with server support for HTTP/2" ON)
31 option(LWS_WITH_LWSWS "Libwebsockets Webserver" OFF)
32 option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out/err) APIs" OFF)
33 option(LWS_IPV6 "Compile with support for ipv6" OFF)
34 option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket" OFF)
35 option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions" OFF)
36 option(LWS_WITH_HTTP_PROXY "Support for HTTP proxying" OFF)
37 option(LWS_WITH_ZIP_FOPS "Support serving pre-zipped files" OFF)
38 option(LWS_WITH_SOCKS5 "Allow use of SOCKS5 proxy on client connections" OFF)
39 option(LWS_WITH_GENERIC_SESSIONS "With the Generic Sessions plugin" OFF)
40 option(LWS_WITH_PEER_LIMITS "Track peers and restrict resources a single peer can allocate" OFF)
41 option(LWS_WITH_ACCESS_LOG "Support generating Apache-compatible access logs" OFF)
42 option(LWS_WITH_RANGES "Support http ranges (RFC7233)" OFF)
43 option(LWS_WITH_SERVER_STATUS "Support json + jscript server monitoring" OFF)
44 option(LWS_WITH_THREADPOOL "Managed worker thread pool support (relies on pthreads)" OFF)
45 option(LWS_WITH_HTTP_STREAM_COMPRESSION "Support HTTP stream compression" OFF)
46 option(LWS_WITH_HTTP_BROTLI "Also offer brotli http stream compression (requires LWS_WITH_HTTP_STREAM_COMPRESSION)" OFF)
47 option(LWS_WITH_ACME "Enable support for ACME automatic cert acquisition + maintenance (letsencrypt etc)" OFF)
48 option(LWS_WITH_HUBBUB "Enable libhubbub rewriting support" OFF)
49 option(LWS_WITH_FTS "Full Text Search support" OFF)
50 #
51 # TLS library options... all except mbedTLS are basically OpenSSL variants.
52 #
53 option(LWS_WITH_SSL "Include SSL support (defaults to OpenSSL or similar, mbedTLS if LWS_WITH_MBEDTLS is set)" ON)
54 option(LWS_WITH_MBEDTLS "Use mbedTLS (>=2.0) replacement for OpenSSL. When setting this, you also may need to specify LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS" OFF)
55 option(LWS_WITH_BORINGSSL "Use BoringSSL replacement for OpenSSL" OFF)
56 option(LWS_WITH_CYASSL "Use CyaSSL replacement for OpenSSL. When setting this, you also need to specify LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS" OFF)
57 option(LWS_WITH_WOLFSSL "Use wolfSSL replacement for OpenSSL. When setting this, you also need to specify LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS" OFF)
58 option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of the OS-installed CA root certs" ON)
59 #
60 # Event library options (may select multiple, or none for default poll()
61 #
62 option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
63 option(LWS_WITH_LIBUV "Compile with support for libuv" OFF)
64 option(LWS_WITH_LIBEVENT "Compile with support for libevent" OFF)
65 #
66 # Static / Dynamic build options
67 #
68 option(LWS_WITH_STATIC "Build the static version of the library" ON)
69 option(LWS_WITH_SHARED "Build the shared version of the library" ON)
70 option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF)
71 option(LWS_STATIC_PIC "Build the static version of the library with position-independent code" OFF)
72 #
73 # Specific platforms
74 #
75 option(LWS_WITH_ESP32 "Build for ESP32" OFF)
76 option(LWS_WITH_ESP32_HELPER "Build ESP32 helper" OFF)
77 option(LWS_PLAT_OPTEE "Build for OPTEE" OFF)
78 #
79 # Client / Server / Test Apps build control
80 #
81 option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF)
82 option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF)
83 option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
84 option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF)
85 option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF)
86 option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF)
87 option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
88 #
89 # Extensions (permessage-deflate)
90 #
91 option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" ON)
92 #
93 # Helpers + misc
94 #
95 option(LWS_WITHOUT_BUILTIN_GETIFADDRS "Don't use the BSD getifaddrs implementation from libwebsockets if it is missing (this will result in a compilation error) ... The default is to assume that your libc provides it. On some systems such as uclibc it doesn't exist." OFF)
96 option(LWS_FALLBACK_GETHOSTBYNAME "Also try to do dns resolution using gethostbyname if getaddrinfo fails" OFF)
97 option(LWS_WITHOUT_BUILTIN_SHA1 "Don't build the lws sha-1 (eg, because openssl will provide it" OFF)
98 option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF)
99 option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON)
100 option(LWS_SSL_SERVER_WITH_ECDH_CERT "Include SSL server use ECDH certificate" OFF)
101 option(LWS_WITH_LEJP "With the Lightweight JSON Parser" ON)
102 option(LWS_WITH_SQLITE3 "Require SQLITE3 support" OFF)
103 option(LWS_WITH_STRUCT_JSON "Generic struct serialization to and from JSON" ON)
104 option(LWS_WITH_STRUCT_SQLITE3 "Generic struct serialization to and from SQLITE3" OFF)
105 option(LWS_WITH_SMTP "Provide SMTP support" OFF)
106 if (WIN32 OR LWS_WITH_ESP32)
107 option(LWS_WITH_DIR "Directory scanning api support" OFF)
108 option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF)
109 else()
110 option(LWS_WITH_DIR "Directory scanning api support" ON)
111 option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" ON)
112 endif()
113 option(LWS_WITH_NO_LOGS "Disable all logging from being compiled in" OFF)
114 option(LWS_AVOID_SIGPIPE_IGN "Android 7+ reportedly needs this" OFF)
115 option(LWS_WITH_STATS "Keep statistics of lws internal operations" OFF)
116 option(LWS_WITH_JOSE "JSON Web Signature / Encryption / Keys (RFC7515/6/) API" OFF)
117 option(LWS_WITH_GENCRYPTO "Enable support for Generic Crypto apis independent of TLS backend" OFF)
118 option(LWS_WITH_SELFTESTS "Selftests run at context creation" OFF)
119 option(LWS_WITH_GCOV "Build with gcc gcov coverage instrumentation" OFF)
120 option(LWS_WITH_EXPORT_LWSTARGETS "Export libwebsockets CMake targets.  Disable if they conflict with an outer cmake project." ON)
121 option(LWS_REPRODUCIBLE "Build libwebsockets reproducible. It removes the build user and hostname from the build" ON)
122 option(LWS_WITH_MINIMAL_EXAMPLES "Also build the normally standalone minimal examples, for QA" OFF)
123 option(LWS_WITH_LWSAC "lwsac Chunk Allocation api" ON)
124 option(LWS_WITH_CUSTOM_HEADERS "Store and allow querying custom HTTP headers (H1 only)" ON)
125 option(LWS_WITH_DISKCACHE "Hashed cache directory with lazy LRU deletion to size limit" OFF)
126 option(LWS_WITH_ASAN "Build with gcc runtime sanitizer options enabled (needs libasan)" OFF)
127 option(LWS_WITH_DIR "Directory scanning api support" OFF)
128 option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF)
129 option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" OFF)
130 option(LWS_WITH_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_WITH_BUNDLED_ZLIB_DEFAULT})
131 option(LWS_WITH_MINIZ "Use miniz instead of zlib" OFF)
132 option(LWS_WITH_DEPRECATED_LWS_DLL "Migrate to lws_dll2 instead ASAP" OFF)
133 option(LWS_WITH_SEQUENCER "lws_seq_t support" ON)
134 option(LWS_WITH_EXTERNAL_POLL "Support external POLL integration using callback messages (not recommended)" OFF)
135 option(LWS_WITH_LWS_DSH "Support lws_dsh_t Disordered Shared Heap" OFF)
136 #
137 # to use miniz, enable both LWS_WITH_ZLIB and LWS_WITH_MINIZ
138 #
139 # End of user settings
140 #
141
142 # Workaround for ESP-IDF
143 # Detect ESP_PLATFORM environment flag, if exist, set LWS_WITH_ESP32.
144 # Otherwise the user may not be able to run configuration ESP-IDF in the first time.
145 if(ESP_PLATFORM)
146         message(STATUS "ESP-IDF enabled")
147         set(LWS_WITH_ESP32 ON)
148 else()
149         set(LWS_WITH_ESP32_HELPER OFF)
150 endif()
151
152 if (WIN32 OR LWS_WITH_ESP32)
153         message(STATUS "No LWS_WITH_DIR and LWS_WITH_DIR")
154         set(LWS_WITH_DIR OFF)
155         set(LWS_WITH_LEJP_CONF OFF)
156         message("LWS_WITH_DIR ${LWS_WITH_DIR}")
157 else()
158         message(STATUS "Compiled with LWS_WITH_DIR and LWS_WITH_DIR")
159         set(LWS_WITH_DIR ON)
160         set(LWS_WITH_LEJP_CONF ON)
161 endif()
162
163 if (LWS_FOR_GITOHASHI)
164         set(LWS_WITH_THREADPOOL 1)
165         set(LWS_WITH_HTTP2 1)
166         set(LWS_UNIX_SOCK 1)
167         set(LWS_WITH_HTTP_PROXY 1)
168         set(LWS_WITH_FTS 1)
169         set(LWS_WITH_DISKCACHE 1)
170         set(LWS_WITH_LWSAC 1)
171         set(LWS_WITH_LEJP_CONF 1)
172 endif()
173
174 if(LWS_WITH_DISTRO_RECOMMENDED)
175         set(LWS_WITH_HTTP2 1)
176         set(LWS_WITH_LWSWS 1)
177         set(LWS_WITH_CGI 1)
178         set(LWS_IPV6 1)
179         set(LWS_WITH_ZIP_FOPS 1)
180         set(LWS_WITH_SOCKS5 1)
181         set(LWS_WITH_RANGES 1)
182         set(LWS_WITH_ACME 1)
183         set(LWS_WITH_SERVER_STATUS 1)
184         set(LWS_WITH_LIBUV 1)
185         set(LWS_WITH_LIBEV 1)
186         # libev + libevent cannot coexist at build-time
187         set(LWS_WITH_LIBEVENT 0)
188         set(LWS_WITHOUT_EXTENSIONS 0)
189         set(LWS_ROLE_DBUS 1)
190         set(LWS_WITH_FTS 1)
191         set(LWS_WITH_THREADPOOL 1)
192         set(LWS_UNIX_SOCK 1)
193         set(LWS_WITH_HTTP_PROXY 1)
194         set(LWS_WITH_DISKCACHE 1)
195         set(LWS_WITH_LWSAC 1)
196         set(LWS_WITH_LEJP_CONF 1)
197         set(LWS_WITH_PLUGINS 1)
198         set(LWS_ROLE_RAW_PROXY 1)
199         set(LWS_WITH_GENCRYPTO 1)
200         set(LWS_WITH_JOSE 1)
201 endif()
202
203 if (NOT LWS_WITH_NETWORK)
204         set(LWS_ROLE_H1 0)
205         set(LWS_ROLE_WS 0)
206         set(LWS_ROLE_RAW 0)
207         set(LWS_WITHOUT_EXTENSIONS 1)
208         set(LWS_WITHOUT_SERVER 1)
209         set(LWS_WITHOUT_CLIENT 1)
210         set(LWS_WITH_HTTP2 0)
211         set(LWS_WITH_SOCKS5 0)
212         set(LWS_UNIX_SOCK 0)
213         set(LWS_WITH_HTTP_PROXY 0)
214         set(LWS_WITH_PLUGINS 0)
215         set(LWS_WITH_LWSWS 0)
216         set(LWS_WITH_CGI 0)
217         set(LWS_ROLE_RAW_PROXY 0)
218         set(LWS_WITH_PEER_LIMITS 0)
219         set(LWS_WITH_GENERIC_SESSIONS 0)
220         set(LWS_WITH_HTTP_STREAM_COMPRESSION 0)
221         set(LWS_WITH_HTTP_BROTLI 0)
222         set(LWS_WITH_POLL 0)
223         set(LWS_WITH_SEQUENCER 0)
224         set(LWS_ROLE_DBUS 0)
225         set(LWS_WITH_LWS_DSH 0)
226 endif()
227
228 if (LWS_WITH_STRUCT_SQLITE3)
229         set(LWS_WITH_SQLITE3 1)
230 endif()
231
232 # do you care about this?  Then send me a patch where it disables it on travis
233 # but allows it on APPLE
234 if (APPLE)
235         set(LWS_ROLE_DBUS 0)
236 endif()
237
238 if(NOT DEFINED CMAKE_BUILD_TYPE)
239         set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
240 endif()
241
242 # microsoft... that's why you can't have nice things
243
244 if (WIN32 OR LWS_WITH_ESP32)
245         set(LWS_UNIX_SOCK 0)
246 endif()
247
248 if (LWS_WITH_ESP32)
249         set(LWS_WITH_LWSAC 0)
250         set(LWS_WITH_FTS 0)
251 endif()
252
253 project(libwebsockets C)
254
255 set(PACKAGE "libwebsockets")
256 set(CPACK_PACKAGE_NAME "${PACKAGE}")
257 set(CPACK_PACKAGE_VERSION_MAJOR "3")
258 set(CPACK_PACKAGE_VERSION_MINOR "2")
259 set(CPACK_PACKAGE_VERSION_PATCH "0")
260 set(CPACK_PACKAGE_RELEASE 1)
261 set(CPACK_GENERATOR "RPM")
262 set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
263 set(CPACK_PACKAGE_VENDOR "andy@warmcat.com")
264 set(CPACK_PACKAGE_CONTACT "andy@warmcat.com")
265 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}")
266 set(SOVERSION "15")
267 if(NOT CPACK_GENERATOR)
268     if(UNIX)
269         set(CPACK_GENERATOR "TGZ")
270     else()
271         set(CPACK_GENERATOR "ZIP")
272     endif()
273 endif()
274 set(CPACK_SOURCE_GENERATOR "TGZ")
275 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
276 set(VERSION "${CPACK_PACKAGE_VERSION}")
277
278 set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION})
279 set(LWS_LIBRARY_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR})
280 set(LWS_LIBRARY_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR})
281 set(LWS_LIBRARY_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH})
282
283 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
284
285
286 message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
287
288 if(WIN32)
289         configure_file(${CMAKE_CURRENT_SOURCE_DIR}/win32port/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc @ONLY)
290         set(RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc)
291 endif()
292
293 # Try to find the current Git hash.
294 find_package(Git)
295 if(GIT_EXECUTABLE)
296         execute_process(
297                 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
298                 COMMAND "${GIT_EXECUTABLE}" describe --tags
299                 OUTPUT_VARIABLE GIT_HASH
300                 OUTPUT_STRIP_TRAILING_WHITESPACE
301                 )
302         set(LWS_BUILD_HASH ${GIT_HASH})
303
304         # append the build user and hostname
305         if(NOT LWS_REPRODUCIBLE)
306                 execute_process(
307                         WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
308                         COMMAND "whoami"
309                         OUTPUT_VARIABLE GIT_USER
310                         OUTPUT_STRIP_TRAILING_WHITESPACE
311                         )
312                 execute_process(
313                         WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
314                         COMMAND "hostname"
315                         OUTPUT_VARIABLE GIT_HOST
316                         OUTPUT_STRIP_TRAILING_WHITESPACE
317                         )
318                 string(REGEX REPLACE "([^\\])[\\]([^\\])" "\\1\\\\\\\\\\2" GIT_USER ${GIT_USER})
319                 set(LWS_BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH})
320         endif()
321
322         message("Git commit hash: ${LWS_BUILD_HASH}")
323 endif()
324
325 # translate old functionality enables to set up ROLE enables so nothing changes
326 if (LWS_WITH_HTTP2 AND LWS_WITHOUT_SERVER)
327         set(LWS_WITH_HTTP2 0)
328         message("HTTP2 disabled due to LWS_WITHOUT_SERVER")
329 endif()
330
331 if (LWS_WITH_HTTP2)
332         set(LWS_ROLE_H2 1)
333 endif()
334 if (LWS_WITH_CGI)
335         set(LWS_ROLE_CGI 1)
336 endif()
337
338 if (NOT LWS_ROLE_WS)
339         set(LWS_WITHOUT_EXTENSIONS 1)
340 endif()
341
342 if (LWS_WITH_MBEDTLS)
343         include_directories(lib/tls/mbedtls/wrapper/include)
344 endif()
345
346 include_directories(include plugins lib/core lib/core-net lib/event-libs include/abstract lib/tls lib/roles lib/event-libs/libuv lib/event-libs/poll lib/event-libs/libevent lib/event-libs/libev lib/jose/jwe lib/jose/jws lib/jose lib/misc lib/roles/http lib/roles/http/compression lib/roles/h1 lib/roles/h2 lib/roles/ws lib/roles/cgi lib/roles/dbus lib/roles/raw-proxy)
347
348 if (LWS_WITH_ESP32)
349         include_directories(lib/plat/esp32)
350 else()
351         if (WIN32)
352                 include_directories(lib/plat/windows)
353         else()
354                 if (LWS_WITH_OPTEE)
355                         include_directories(lib/plat/optee)
356                 else()
357                         include_directories(lib/plat/unix)
358                 endif()
359         endif()
360 endif()
361
362
363 if (LWS_WITH_LWSWS)
364  message(STATUS "LWS_WITH_LWSWS --> Enabling LWS_WITH_PLUGINS and LWS_WITH_LIBUV")
365  set(LWS_WITH_PLUGINS 1)
366  set(LWS_WITH_LIBUV 1)
367  set(LWS_WITH_ACCESS_LOG 1)
368  set(LWS_WITH_SERVER_STATUS 1)
369  set(LWS_WITH_LEJP 1)
370  set(LWS_WITH_LEJP_CONF 1)
371  set(LWS_WITH_PEER_LIMITS 1)
372  set(LWS_ROLE_RAW_PROXY 1)
373 endif()
374
375 # sshd plugin
376 if (LWS_WITH_PLUGINS)
377  set(LWS_WITH_GENCRYPTO 1)
378 endif()
379
380 if (LWS_ROLE_RAW_PROXY)
381  set (LWS_WITHOUT_CLIENT 0)
382  set (LWS_WITHOUT_SERVER 0)
383 endif()
384
385 if (LWS_WITH_ACME)
386  set (LWS_WITHOUT_CLIENT 0)
387  set (LWS_WITHOUT_SERVER 0)
388  set (LWS_WITH_JOSE 1)
389 endif()
390
391 if (LWS_WITH_JOSE)
392  set(LWS_WITH_LEJP 1)
393  set(LWS_WITH_GENCRYPTO 1)
394 endif()
395
396 if (LWS_WITH_PLUGINS AND NOT LWS_WITH_LIBUV)
397 message(STATUS "LWS_WITH_PLUGINS --> Enabling LWS_WITH_LIBUV")
398  set(LWS_WITH_LIBUV 1)
399 endif()
400
401 if (LWS_WITH_PLUGINS OR LWS_WITH_CGI)
402         # sshd plugin
403  set(LWS_WITH_GENCRYPTO 1)
404 endif()
405
406 if (LWS_WITH_GENERIC_SESSIONS)
407  set(LWS_WITH_SQLITE3 1)
408  set(LWS_WITH_SMTP 1)
409  set(LWS_WITH_STRUCT_SQLITE3 1)
410 endif()
411
412 if (LWS_WITH_ESP32)
413  set(LWS_WITH_SHARED OFF)
414  set(LWS_WITH_MBEDTLS ON)
415   # set(LWS_WITHOUT_CLIENT ON)
416  set(LWS_WITHOUT_TESTAPPS ON)
417  set(LWS_WITHOUT_EXTENSIONS ON)
418  set(LWS_WITH_PLUGINS OFF)
419  set(LWS_WITH_RANGES ON)
420  # this implies no pthreads in the lib
421  set(LWS_MAX_SMP 1)
422  set(LWS_HAVE_MALLOC 1)
423  set(LWS_HAVE_REALLOC 1)
424  set(LWS_HAVE_GETIFADDRS 1)
425  set(LWS_WITH_ZIP_FOPS 1)
426  set(LWS_WITH_CUSTOM_HEADERS 0)
427 endif()
428
429
430 if (WIN32)
431 set(LWS_MAX_SMP 1)
432 set(LWS_WITH_THREADPOOL 0)
433 endif()
434
435 if (LWS_WITHOUT_SERVER)
436 set(LWS_WITH_LWSWS OFF)
437 endif()
438
439 if (LWS_WITH_LEJP_CONF)
440         set(LWS_WITH_DIR 1)
441 endif()
442
443 # confirm H1 relationships
444
445 if (NOT LWS_ROLE_H1 AND LWS_ROLE_H2)
446         message(FATAL_ERROR "H2 requires LWS_ROLE_H1")
447 endif()
448
449 if (NOT LWS_ROLE_H1 AND LWS_ROLE_WS)
450         message(FATAL_ERROR "WS requires LWS_ROLE_H1")
451 endif()
452
453 if (NOT LWS_ROLE_H1 AND LWS_ROLE_CGI)
454         message(FATAL_ERROR "CGI requires LWS_ROLE_H1")
455 endif()
456
457 # confirm HTTP relationships
458
459 if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_HTTP_PROXY)
460         message(FATAL_ERROR "LWS_WITH_LWSWS requires LWS_ROLE_H1")
461 endif()
462
463 if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_HTTP_PROXY)
464         message(FATAL_ERROR "LWS_WITH_HTTP_PROXY requires LWS_ROLE_H1")
465 endif()
466
467 if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_RANGES)
468         message(FATAL_ERROR "LWS_WITH_RANGES requires LWS_ROLE_H1")
469 endif()
470
471 if (NOT LWS_ROLE_H1 AND NOT LWS_ROLE_H2 AND LWS_WITH_ACCESS_LOG)
472         message(FATAL_ERROR "LWS_WITH_ACCESS_LOG requires LWS_ROLE_H1")
473 endif()
474
475
476 if (LWS_WITH_HTTP_PROXY AND (LWS_WITHOUT_CLIENT OR LWS_WITHOUT_SERVER))
477         message("You have to enable both client and server for http proxy")
478         set(LWS_WITH_HTTP_PROXY 0)
479 endif()
480
481 # Allow the user to override installation directories.
482 set(LWS_INSTALL_LIB_DIR       lib CACHE PATH "Installation directory for libraries")
483 set(LWS_INSTALL_BIN_DIR       bin CACHE PATH "Installation directory for executables")
484 set(LWS_INSTALL_INCLUDE_DIR   include CACHE PATH "Installation directory for header files")
485 set(LWS_INSTALL_EXAMPLES_DIR  bin CACHE PATH "Installation directory for example files")
486
487 # Allow the user to use the old CyaSSL options/library in stead of wolfSSL
488 if (LWS_WITH_CYASSL AND LWS_WITH_WOLFSSL)
489         message(FATAL_ERROR "LWS_WITH_CYASSL and LWS_WITH_WOLFSSL are mutually exclusive!")
490 endif()
491 if (LWS_WITH_CYASSL)
492         # Copy CyaSSL options to the wolfSSL options
493         set(LWS_WITH_WOLFSSL ${LWS_WITH_CYASSL} CACHE BOOL "Use wolfSSL/CyaSSL instead of OpenSSL" FORCE)
494         set(LWS_WOLFSSL_LIBRARIES ${LWS_CYASSL_LIBRARIES} CACHE PATH "Path to wolfSSL/CyaSSL libraries" FORCE)
495         set(LWS_WOLFSSL_INCLUDE_DIRS ${LWS_CYASSL_INCLUDE_DIRS} CACHE PATH "Path to wolfSSL/CyaSSL header files" FORCE)
496 endif()
497
498 if (NOT (LWS_WITH_STATIC OR LWS_WITH_SHARED))
499         message(FATAL_ERROR "Makes no sense to compile with neither static nor shared libraries.")
500 endif()
501
502 if (NOT LWS_WITHOUT_EXTENSIONS OR LWS_WITH_ZIP_FOPS)
503         set(LWS_WITH_ZLIB 1)
504 endif()
505
506 # if you gave LWS_WITH_MINIZ, point to MINIZ here if not found
507 # automatically
508
509 set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib/miniz library")
510 set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib/miniz include directory")
511 set(LWS_OPENSSL_LIBRARIES CACHE PATH "Path to the OpenSSL library")
512 set(LWS_OPENSSL_INCLUDE_DIRS CACHE PATH "Path to the OpenSSL include directory")
513 set(LWS_WOLFSSL_LIBRARIES CACHE PATH "Path to the wolfSSL library")
514 set(LWS_WOLFSSL_INCLUDE_DIRS CACHE PATH "Path to the wolfSSL include directory")
515 set(LWS_LIBEV_LIBRARIES CACHE PATH "Path to the libev library")
516 set(LWS_LIBEV_INCLUDE_DIRS CACHE PATH "Path to the libev include directory")
517 set(LWS_LIBUV_LIBRARIES CACHE PATH "Path to the libuv library")
518 set(LWS_LIBUV_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory")
519 set(LWS_SQLITE3_LIBRARIES CACHE PATH "Path to the sqlite3 library")
520 set(LWS_SQLITE3_INCLUDE_DIRS CACHE PATH "Path to the sqlite3 include directory")
521 set(LWS_LIBEVENT_INCLUDE_DIRS CACHE PATH "Path to the libevent include directory")
522 set(LWS_LIBEVENT_LIBRARIES CACHE PATH "Path to the libevent library")
523
524
525 if (NOT LWS_WITH_SSL)
526         set(LWS_WITHOUT_BUILTIN_SHA1 OFF)
527 endif()
528
529 if (LWS_WITH_BORINGSSL)
530         # boringssl deprecated EVP_PKEY
531         set (LWS_WITH_GENHASH OFF)
532 endif()
533
534 if (LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL AND NOT LWS_WITH_MBEDTLS)
535         if ("${LWS_OPENSSL_LIBRARIES}" STREQUAL "" OR "${LWS_OPENSSL_INCLUDE_DIRS}" STREQUAL "")
536         else()
537                 if (NOT LWS_WITH_ESP32)
538                         set(OPENSSL_LIBRARIES ${LWS_OPENSSL_LIBRARIES})
539                 endif()
540                 set(OPENSSL_INCLUDE_DIRS ${LWS_OPENSSL_INCLUDE_DIRS})
541                 set(OPENSSL_FOUND 1)
542         endif()
543 endif()
544
545 if (LWS_WITH_SSL AND LWS_WITH_WOLFSSL)
546         if ("${LWS_WOLFSSL_LIBRARIES}" STREQUAL "" OR "${LWS_WOLFSSL_INCLUDE_DIRS}" STREQUAL "")
547                 if (NOT WOLFSSL_FOUND)
548                         if (LWS_WITH_CYASSL)
549                                 message(FATAL_ERROR "You must set LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS when LWS_WITH_CYASSL is turned on.")
550                         else()
551                                 message(FATAL_ERROR "You must set LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS when LWS_WITH_WOLFSSL is turned on.")
552                         endif()
553                 endif()
554         else()
555                 set(WOLFSSL_LIBRARIES ${LWS_WOLFSSL_LIBRARIES})
556                 set(WOLFSSL_INCLUDE_DIRS ${LWS_WOLFSSL_INCLUDE_DIRS})
557                 set(WOLFSSL_FOUND 1)
558         endif()
559         set(USE_WOLFSSL 1)
560         set(LWS_WITH_TLS 1)
561         if (LWS_WITH_CYASSL)
562                 set(USE_OLD_CYASSL 1)
563         endif()
564 endif()
565
566 if (LWS_WITH_SSL AND LWS_WITH_MBEDTLS)
567         if ("${LWS_MBEDTLS_LIBRARIES}" STREQUAL "" OR "${LWS_MBEDTLS_INCLUDE_DIRS}" STREQUAL "" AND NOT LWS_WITH_ESP32)
568
569                 find_path(LWS_MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h)
570
571                 find_library(MBEDTLS_LIBRARY mbedtls)
572                 find_library(MBEDX509_LIBRARY mbedx509)
573                 find_library(MBEDCRYPTO_LIBRARY mbedcrypto)
574
575                 set(LWS_MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}")
576
577                 include(FindPackageHandleStandardArgs)
578                 find_package_handle_standard_args(MBEDTLS DEFAULT_MSG
579                         LWS_MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)
580
581                 mark_as_advanced(LWS_MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)
582
583                 if ("${LWS_MBEDTLS_LIBRARIES}" STREQUAL "" OR "${LWS_MBEDTLS_INCLUDE_DIRS}" STREQUAL "")
584                         message(FATAL_ERROR "You must set LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS when LWS_WITH_MBEDTLS is turned on.")
585                 endif()
586         endif()
587         set(MBEDTLS_LIBRARIES ${LWS_MBEDTLS_LIBRARIES})
588         set(MBEDTLS_INCLUDE_DIRS ${LWS_MBEDTLS_INCLUDE_DIRS})
589         set(MBEDTLS_FOUND 1)
590         set(USE_MBEDTLS 1)
591 endif()
592
593 if (LWS_WITH_HTTP_STREAM_COMPRESSION)
594         set(LWS_WITH_ZLIB 1)
595 endif()
596
597 if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB)
598         if ("${LWS_ZLIB_LIBRARIES}" STREQUAL "" OR "${LWS_ZLIB_INCLUDE_DIRS}" STREQUAL "")
599         else()
600                 set(ZLIB_LIBRARIES ${LWS_ZLIB_LIBRARIES})
601                 set(ZLIB_INCLUDE_DIRS ${LWS_ZLIB_INCLUDE_DIRS})
602                 set(ZLIB_FOUND 1)
603         endif()
604 endif()
605
606 if (LWS_WITH_LIBEV)
607         if ("${LWS_LIBEV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEV_INCLUDE_DIRS}" STREQUAL "")
608         else()
609                 set(LIBEV_LIBRARIES ${LWS_LIBEV_LIBRARIES})
610                 set(LIBEV_INCLUDE_DIRS ${LWS_LIBEV_INCLUDE_DIRS})
611                 set(LIBEV_FOUND 1)
612         endif()
613 endif()
614
615 if (LWS_WITH_LIBUV)
616         if ("${LWS_LIBUV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBUV_INCLUDE_DIRS}" STREQUAL "")
617         else()
618                 set(LIBUV_LIBRARIES ${LWS_LIBUV_LIBRARIES})
619                 set(LIBUV_INCLUDE_DIRS ${LWS_LIBUV_INCLUDE_DIRS})
620                 set(LIBUV_FOUND 1)
621         endif()
622 endif()
623
624 if (LWS_WITH_LIBEVENT)
625         if ("${LWS_LIBEVENT_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEVENT_INCLUDE_DIRS}" STREQUAL "")
626         else()
627                 set(LIBEVENT_LIBRARIES ${LWS_LIBEVENT_LIBRARIES})
628                 set(LIBEVENT_INCLUDE_DIRS ${LWS_LIBEVENT_INCLUDE_DIRS})
629                 set(LIBEVENT_FOUND 1)
630         endif()
631 endif()
632
633 if (LWS_WITH_SQLITE3)
634         if ("${LWS_SQLITE3_LIBRARIES}" STREQUAL "" OR "${LWS_SQLITE3_INCLUDE_DIRS}" STREQUAL "")
635         else()
636                 set(SQLITE3_LIBRARIES ${LWS_SQLITE3_LIBRARIES})
637                 set(SQLITE3_INCLUDE_DIRS ${LWS_SQLITE3_INCLUDE_DIRS})
638                 set(SQLITE3_FOUND 1)
639         endif()
640 endif()
641
642
643 if (LWS_WITH_LIBEV AND LWS_WITH_LIBEVENT)
644         message(FATAL_ERROR "Sorry libev and libevent conflict with each others' namespace, you can only have one or the other")
645 endif()
646
647 # The base dir where the test-apps look for the SSL certs.
648 set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory")
649 if (WIN32)
650         set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory")
651
652         if (LWS_UNIX_SOCK)
653                 set(LWS_UNIX_SOCK OFF)
654                 message(WARNING "Windows does not support UNIX domain sockets")
655         endif()
656 else()
657         set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory")
658 endif()
659
660 # LWS_OPENSSL_SUPPORT deprecated... use LWS_WITH_TLS
661 if (LWS_WITH_SSL OR LWS_WITH_MBEDTLS)
662         set(LWS_OPENSSL_SUPPORT 1)
663         set(LWS_WITH_TLS 1)
664 endif()
665
666 if (LWS_SSL_CLIENT_USE_OS_CA_CERTS)
667         set(LWS_SSL_CLIENT_USE_OS_CA_CERTS 1)
668 endif()
669
670 if (LWS_WITH_LATENCY)
671         set(LWS_LATENCY 1)
672 endif()
673
674 if (LWS_WITHOUT_DAEMONIZE OR WIN32)
675         set(LWS_NO_DAEMONIZE 1)
676 endif()
677
678 if (LWS_WITHOUT_SERVER)
679         set(LWS_NO_SERVER 1)
680 endif()
681
682 if (LWS_WITHOUT_CLIENT)
683         set(LWS_NO_CLIENT 1)
684 endif()
685
686 if (LWS_WITH_LIBEV)
687         set(LWS_WITH_LIBEV 1)
688 endif()
689
690 if (LWS_WITH_LIBUV)
691         set(LWS_WITH_LIBUV 1)
692 endif()
693
694 if (LWS_WITH_LIBEVENT)
695         set(LWS_WITH_LIBEVENT 1)
696 endif()
697
698 if (LWS_IPV6)
699         set(LWS_WITH_IPV6 1)
700 endif()
701
702 if (LWS_UNIX_SOCK)
703     set(LWS_WITH_UNIX_SOCK 1)
704 endif()
705
706 if (LWS_WITH_HTTP2)
707         set(LWS_WITH_HTTP2 1)
708 endif()
709
710 if ("${LWS_MAX_SMP}" STREQUAL "")
711         set(LWS_MAX_SMP 1)
712 endif()
713
714 # using any abstract protocol enables LWS_WITH_ABSTRACT
715
716 if (LWS_WITH_SMTP)
717         set(LWS_WITH_ABSTRACT 1)
718 endif()
719
720
721
722 if (MINGW)
723         set(LWS_MINGW_SUPPORT 1)
724         set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}")
725         add_definitions(-DWINVER=0x0601 -D_WIN32_WINNT=0x0601)
726 endif()
727
728 if (LWS_SSL_SERVER_WITH_ECDH_CERT)
729         set(LWS_SSL_SERVER_WITH_ECDH_CERT 1)
730 endif()
731
732 include_directories("${PROJECT_BINARY_DIR}")
733
734 include(CheckCSourceCompiles)
735
736 # Check for different inline keyword versions.
737 foreach(KEYWORD "inline" "__inline__" "__inline")
738         set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}")
739         CHECK_C_SOURCE_COMPILES(
740                 "
741                 #include <stdio.h>
742                 static KEYWORD void a() {}
743                 int main(int argc, char **argv) { a(); return 0; }
744                 " LWS_HAVE_${KEYWORD})
745 endforeach()
746
747 if (NOT LWS_HAVE_inline)
748         if (LWS_HAVE___inline__)
749                 set(inline __inline__)
750         elseif(LWS_HAVE___inline)
751                 set(inline __inline)
752         endif()
753 endif()
754
755 # Put the libraries and binaries that get built into directories at the
756 # top of the build tree rather than in hard-to-find leaf directories. 
757 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
758 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
759 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
760
761 SET(LWS_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}")
762
763 # Put absolute path of dynamic libraries into the object code. Some
764 # architectures, notably Mac OS X, need this.
765 SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}")
766
767 include(CheckFunctionExists)
768 include(CheckSymbolExists)
769 include(CheckIncludeFile)
770 include(CheckIncludeFiles)
771 include(CheckLibraryExists)
772 include(CheckTypeSize)
773 include(CheckCSourceCompiles)
774
775 if (LWS_WITHOUT_BUILTIN_SHA1)
776         set(LWS_SHA1_USE_OPENSSL_NAME 1)
777 endif()
778
779 if (HAIKU)
780         set(CMAKE_REQUIRED_LIBRARIES network)
781 endif()
782
783 CHECK_C_SOURCE_COMPILES(
784         "#include <malloc.h>
785         int main(int argc, char **argv) { return malloc_trim(0); }
786         " LWS_HAVE_MALLOC_TRIM)
787 CHECK_C_SOURCE_COMPILES(
788         "#include <malloc.h>
789         int main(int argc, char **argv) { return (int)malloc_usable_size((void *)0); }
790         " LWS_HAVE_MALLOC_USABLE_SIZE)
791
792 CHECK_FUNCTION_EXISTS(fork LWS_HAVE_FORK)
793 CHECK_FUNCTION_EXISTS(getenv LWS_HAVE_GETENV)
794 CHECK_FUNCTION_EXISTS(malloc LWS_HAVE_MALLOC)
795 CHECK_FUNCTION_EXISTS(memset LWS_HAVE_MEMSET)
796 CHECK_FUNCTION_EXISTS(realloc LWS_HAVE_REALLOC)
797 CHECK_FUNCTION_EXISTS(socket LWS_HAVE_SOCKET)
798 CHECK_FUNCTION_EXISTS(strerror LWS_HAVE_STRERROR)
799 CHECK_FUNCTION_EXISTS(vfork LWS_HAVE_VFORK)
800 CHECK_FUNCTION_EXISTS(execvpe LWS_HAVE_EXECVPE)
801 CHECK_FUNCTION_EXISTS(getifaddrs LWS_HAVE_GETIFADDRS)
802 CHECK_FUNCTION_EXISTS(snprintf LWS_HAVE_SNPRINTF)
803 CHECK_FUNCTION_EXISTS(_snprintf LWS_HAVE__SNPRINTF)
804 CHECK_FUNCTION_EXISTS(_vsnprintf LWS_HAVE__VSNPRINTF)
805 CHECK_FUNCTION_EXISTS(getloadavg LWS_HAVE_GETLOADAVG)
806 CHECK_FUNCTION_EXISTS(atoll LWS_HAVE_ATOLL)
807 CHECK_FUNCTION_EXISTS(_atoi64 LWS_HAVE__ATOI64)
808 CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64)
809 CHECK_FUNCTION_EXISTS(clock_gettime LWS_HAVE_CLOCK_GETTIME)
810
811 if (NOT LWS_HAVE_GETIFADDRS)
812         if (LWS_WITHOUT_BUILTIN_GETIFADDRS)
813                 message(FATAL_ERROR "No getifaddrs was found on the system. Turn off the LWS_WITHOUT_BUILTIN_GETIFADDRS compile option to use the supplied BSD version.")
814         endif()
815         set(LWS_BUILTIN_GETIFADDRS 1)
816 endif()
817
818 CHECK_INCLUDE_FILE(dlfcn.h LWS_HAVE_DLFCN_H)
819 CHECK_INCLUDE_FILE(fcntl.h LWS_HAVE_FCNTL_H)
820 CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H)
821 CHECK_INCLUDE_FILE(memory.h LWS_HAVE_MEMORY_H)
822 CHECK_INCLUDE_FILE(netinet/in.h LWS_HAVE_NETINET_IN_H)
823 CHECK_INCLUDE_FILE(stdint.h LWS_HAVE_STDINT_H)
824 CHECK_INCLUDE_FILE(stdlib.h LWS_HAVE_STDLIB_H)
825 CHECK_INCLUDE_FILE(strings.h LWS_HAVE_STRINGS_H)
826 CHECK_INCLUDE_FILE(string.h LWS_HAVE_STRING_H)
827 CHECK_INCLUDE_FILE(sys/prctl.h LWS_HAVE_SYS_PRCTL_H)
828 CHECK_INCLUDE_FILE(sys/socket.h LWS_HAVE_SYS_SOCKET_H)
829 CHECK_INCLUDE_FILE(sys/sockio.h LWS_HAVE_SYS_SOCKIO_H)
830 CHECK_INCLUDE_FILE(sys/stat.h LWS_HAVE_SYS_STAT_H)
831 CHECK_INCLUDE_FILE(sys/types.h LWS_HAVE_SYS_TYPES_H)
832 CHECK_INCLUDE_FILE(unistd.h LWS_HAVE_UNISTD_H)
833 CHECK_INCLUDE_FILE(vfork.h LWS_HAVE_VFORK_H)
834 CHECK_INCLUDE_FILE(sys/capability.h LWS_HAVE_SYS_CAPABILITY_H)
835 CHECK_INCLUDE_FILE(malloc.h LWS_HAVE_MALLOC_H)
836 CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
837 CHECK_INCLUDE_FILE(inttypes.h LWS_HAVE_INTTYPES_H)
838
839 CHECK_LIBRARY_EXISTS(cap cap_set_flag "" LWS_HAVE_LIBCAP)
840
841 if (LWS_ROLE_DBUS)
842
843         if (NOT LWS_DBUS_LIB)
844                 set(LWS_DBUS_LIB "dbus-1")
845         endif()
846
847         CHECK_LIBRARY_EXISTS(${LWS_DBUS_LIB} dbus_connection_set_watch_functions "" LWS_HAVE_LIBDBUS)
848         if (NOT LWS_HAVE_LIBDBUS)
849                 message(FATAL_ERROR "Install dbus-devel, or libdbus-1-dev etc")
850         endif()
851
852         if (NOT LWS_DBUS_INCLUDE1)
853                 # look in fedora and debian / ubuntu place
854                 if (EXISTS "/usr/include/dbus-1.0")
855                         set(LWS_DBUS_INCLUDE1 "/usr/include/dbus-1.0")
856                 else()
857                         message(FATAL_ERROR "Set LWS_DBUS_INCLUDE1 to /usr/include/dbus-1.0 or wherever the main dbus includes are")
858                 endif()
859         endif()
860
861         if (NOT LWS_DBUS_INCLUDE2)
862                 # look in fedora... debian / ubuntu has the ARCH in the path...
863                 if (EXISTS "/usr/lib64/dbus-1.0/include")
864                         set(LWS_DBUS_INCLUDE2 "/usr/lib64/dbus-1.0/include")
865                 else()
866                         message(FATAL_ERROR "Set LWS_DBUS_INCLUDE2 to /usr/lib/ARCH-linux-gnu/dbus-1.0/include or wherever dbus-arch-deps.h is on your system")
867                 endif()
868         endif()
869
870         set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_DBUS_INCLUDE1};${LWS_DBUS_INCLUDE2})
871
872         CHECK_C_SOURCE_COMPILES("#include <dbus/dbus.h>
873         int main(void) {
874                 return 0;
875         }" LWS_DBUS_CHECK_OK)
876 endif()
877
878 if (LWS_WITH_LIBUV)
879 CHECK_INCLUDE_FILE(uv-version.h LWS_HAVE_UV_VERSION_H)
880   # libuv changed the location in 1.21.0. Retain both
881   # checks temporarily to ensure a smooth transition.
882   if (NOT LWS_HAVE_UV_VERSION_H)
883     CHECK_INCLUDE_FILE(uv/version.h LWS_HAVE_NEW_UV_VERSION_H)
884   endif()
885 endif()
886
887
888 if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB)
889         if (LWS_WITH_MINIZ)
890                 CHECK_INCLUDE_FILE(miniz.h LWS_HAVE_ZLIB_H)
891         else()
892                 CHECK_INCLUDE_FILE(zlib.h LWS_HAVE_ZLIB_H)
893         endif()
894 endif()
895
896 # TODO: These can also be tested to see whether they actually work...
897 set(LWS_HAVE_WORKING_FORK LWS_HAVE_FORK)
898 set(LWS_HAVE_WORKING_VFORK LWS_HAVE_VFORK)
899
900 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
901
902 CHECK_C_SOURCE_COMPILES("#include <stdint.h> 
903         int main(void) {
904                 intptr_t test = 1;
905                 return 0;
906         }" LWS_HAS_INTPTR_T)
907
908 set(CMAKE_REQUIRED_FLAGS "-pthread")    
909 CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE 
910         #include <pthread.h> 
911         int main(void) { 
912                 pthread_t th = 0;
913                 pthread_setname_np(th, NULL);
914                 return 0;
915         }" LWS_HAS_PTHREAD_SETNAME_NP)
916
917 CHECK_C_SOURCE_COMPILES("#include <stddef.h>
918         #include <getopt.h> 
919         int main(void) { 
920                 void *p = (void *)getopt_long;
921                 return p != NULL;
922         }" LWS_HAS_GETOPT_LONG)
923
924
925 if (NOT PID_T_SIZE)
926         set(pid_t int)
927 endif()
928
929 if (NOT SIZE_T_SIZE)
930         set(size_t "unsigned int")
931 endif()
932
933 if (NOT LWS_HAVE_MALLOC)
934         set(malloc rpl_malloc)
935 endif()
936
937 if (NOT LWS_HAVE_REALLOC)
938         set(realloc rpl_realloc)
939 endif()
940
941 if (UNIX)
942         execute_process(COMMAND uname -n OUTPUT_VARIABLE NODENAME)
943         # Need to chomp the \n at end of output.
944         string(REGEX REPLACE "[\n]+" "" NODENAME "${NODENAME}")
945
946         if( NODENAME STREQUAL "smartos" )
947                 add_definitions( "-D__smartos__" )
948                 set(SMARTOS 1)
949         endif()
950 endif()
951
952 if (MSVC)
953         # Turn off stupid microsoft security warnings.
954         add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
955 endif(MSVC)
956
957 include_directories("${PROJECT_SOURCE_DIR}/lib")
958
959 # Group headers and sources.
960 # Some IDEs use this for nicer file structure.
961 set(HDR_PRIVATE
962         lib/core/private-lib-core.h)
963
964 set(HDR_PUBLIC
965         "${PROJECT_SOURCE_DIR}/include/libwebsockets.h"
966         "${PROJECT_BINARY_DIR}/lws_config.h"
967         "${PROJECT_SOURCE_DIR}/plugins/ssh-base/include/lws-plugin-ssh.h"
968         )
969
970 set(SOURCES
971         lib/core/alloc.c
972         lib/core/buflist.c
973         lib/core/context.c
974         lib/core/lws_dll2.c
975         lib/core/libwebsockets.c
976         lib/core/logs.c
977         lib/misc/base64-decode.c
978         lib/core/vfs.c
979         lib/misc/lws-ring.c
980 )
981
982 if (LWS_WITH_DEPRECATED_LWS_DLL)
983         list(APPEND SOURCES
984                 lib/core/lws_dll.c)
985 endif()
986         
987 if (LWS_WITH_NETWORK)
988         list(APPEND SOURCES
989                 lib/core-net/dummy-callback.c
990                 lib/core-net/output.c
991                 lib/core-net/close.c
992                 lib/core-net/network.c
993                 lib/core-net/vhost.c
994                 lib/core-net/pollfd.c
995                 lib/core-net/service.c
996                 lib/core-net/sorted-usec-list.c
997                 lib/core-net/stats.c
998                 lib/core-net/wsi.c
999                 lib/core-net/wsi-timeout.c
1000                 lib/core-net/adopt.c
1001                 lib/roles/pipe/ops-pipe.c
1002         )
1003
1004         if (LWS_WITH_LWS_DSH)
1005                 list(APPEND SOURCES
1006                         lib/core-net/lws-dsh.c)
1007         endif()
1008
1009         if (LWS_WITH_SEQUENCER)
1010                 list(APPEND SOURCES
1011                         lib/core-net/sequencer.c)
1012         endif()
1013
1014         if (LWS_WITH_ABSTRACT)
1015                 list(APPEND SOURCES
1016                         lib/abstract/abstract.c
1017                 )
1018                 if (LWS_WITH_SEQUENCER)
1019                         list(APPEND SOURCES
1020                                 lib/abstract/test-sequencer.c)
1021                 endif()
1022         endif()
1023
1024         if (LWS_WITH_STATS)
1025                 list(APPEND SOURCES
1026                         lib/core-net/stats.c
1027                 )
1028         endif()
1029 endif()
1030
1031 if (LWS_WITH_DIR)
1032         list(APPEND SOURCES lib/misc/dir.c)
1033 endif()
1034         
1035 if (LWS_WITH_THREADPOOL AND UNIX AND LWS_HAVE_PTHREAD_H)
1036         list(APPEND SOURCES lib/misc/threadpool/threadpool.c)
1037 endif()
1038
1039 if (LWS_ROLE_H1 OR LWS_ROLE_H2)
1040         list(APPEND SOURCES
1041                 lib/roles/http/header.c
1042                 lib/roles/http/server/parsers.c)
1043         if (LWS_WITH_HTTP_STREAM_COMPRESSION)
1044                 list(APPEND SOURCES
1045                         lib/roles/http/compression/stream.c
1046                         lib/roles/http/compression/deflate/deflate.c)
1047                 if (LWS_WITH_HTTP_BROTLI)
1048                         list(APPEND SOURCES
1049                                 lib/roles/http/compression/brotli/brotli.c)
1050                 endif()
1051         endif()
1052 endif()
1053
1054 if (LWS_ROLE_H1)
1055         list(APPEND SOURCES
1056                 lib/roles/h1/ops-h1.c)
1057 endif()
1058
1059 if (LWS_ROLE_WS)
1060         list(APPEND SOURCES
1061                 lib/roles/ws/ops-ws.c)
1062         if (NOT LWS_WITHOUT_CLIENT)
1063                 list(APPEND SOURCES
1064                         lib/roles/ws/client-ws.c
1065                         lib/roles/ws/client-parser-ws.c)
1066         endif()
1067         if (NOT LWS_WITHOUT_SERVER)
1068                 list(APPEND SOURCES
1069                         lib/roles/ws/server-ws.c)
1070         endif()
1071 endif()
1072
1073 if (LWS_ROLE_RAW)
1074         list(APPEND SOURCES
1075                 lib/roles/raw-skt/ops-raw-skt.c
1076                 lib/roles/raw-file/ops-raw-file.c)
1077                 
1078         if (LWS_WITH_ABSTRACT)
1079                 list(APPEND SOURCES
1080                         lib/abstract/transports/raw-skt.c)
1081         endif()
1082 endif()
1083
1084 if (LWS_ROLE_RAW_PROXY)
1085         list(APPEND SOURCES
1086                 lib/roles/raw-proxy/ops-raw-proxy.c)
1087 endif()
1088
1089 if (LWS_ROLE_CGI)
1090         list(APPEND SOURCES
1091                 lib/roles/cgi/cgi-server.c
1092                 lib/roles/cgi/ops-cgi.c)
1093 endif()
1094
1095 if (LWS_ROLE_DBUS)
1096         list(APPEND SOURCES
1097                 lib/roles/dbus/dbus.c)
1098 endif()
1099
1100 if (LWS_WITH_ACCESS_LOG)
1101         list(APPEND SOURCES
1102                 lib/roles/http/server/access-log.c)
1103 endif()
1104
1105 if (LWS_WITH_PEER_LIMITS)
1106         list(APPEND SOURCES
1107                 lib/misc/peer-limits.c)
1108 endif()
1109
1110 if (LWS_WITH_LWSAC)
1111         list(APPEND SOURCES
1112                 lib/misc/lwsac/lwsac.c
1113                 lib/misc/lwsac/cached-file.c)
1114 endif()
1115
1116 if (LWS_WITH_FTS)
1117         list(APPEND SOURCES
1118                 lib/misc/fts/trie.c
1119                 lib/misc/fts/trie-fd.c)
1120 endif()
1121
1122 if (LWS_WITH_DISKCACHE)
1123         list(APPEND SOURCES
1124                 lib/misc/diskcache.c)
1125 endif()
1126
1127 if (LWS_WITH_STRUCT_JSON)
1128         list(APPEND SOURCES
1129                 lib/misc/lws-struct-lejp.c)
1130 endif()
1131
1132 if (LWS_WITH_STRUCT_SQLITE3)
1133         list(APPEND SOURCES
1134                 lib/misc/lws-struct-sqlite.c)
1135 endif()
1136
1137 if (NOT LWS_WITHOUT_CLIENT)
1138         list(APPEND SOURCES
1139                 lib/core-net/connect.c
1140                 lib/core-net/client.c
1141                 lib/roles/http/client/client-http.c
1142                 lib/roles/http/client/client-handshake.c)
1143 endif()
1144
1145 if (NOT LWS_WITHOUT_SERVER)
1146         list(APPEND SOURCES
1147                 lib/core-net/server.c
1148                 lib/roles/listen/ops-listen.c)
1149 endif()
1150
1151 if (LWS_WITH_MBEDTLS)
1152         set(LWS_WITH_SSL ON)
1153         
1154         include_directories(lib/tls/mbedtls/wrapper/include)
1155         include_directories(lib/tls/mbedtls/wrapper/include/platform)
1156         include_directories(lib/tls/mbedtls/wrapper/include/internal)
1157         include_directories(lib/tls/mbedtls/wrapper/include/openssl)
1158         
1159         if (LWS_WITH_NETWORK)
1160                 list(APPEND HDR_PRIVATE
1161                         lib/tls/mbedtls/wrapper/include/internal/ssl3.h
1162                         lib/tls/mbedtls/wrapper/include/internal/ssl_cert.h
1163                         lib/tls/mbedtls/wrapper/include/internal/ssl_code.h
1164                         lib/tls/mbedtls/wrapper/include/internal/ssl_dbg.h
1165                         lib/tls/mbedtls/wrapper/include/internal/ssl_lib.h
1166                         lib/tls/mbedtls/wrapper/include/internal/ssl_methods.h
1167                         lib/tls/mbedtls/wrapper/include/internal/ssl_pkey.h
1168                         lib/tls/mbedtls/wrapper/include/internal/ssl_stack.h
1169                         lib/tls/mbedtls/wrapper/include/internal/ssl_types.h
1170                         lib/tls/mbedtls/wrapper/include/internal/ssl_x509.h
1171                         lib/tls/mbedtls/wrapper/include/internal/tls1.h
1172                         lib/tls/mbedtls/wrapper/include/internal/x509_vfy.h)
1173         
1174                 list(APPEND HDR_PRIVATE
1175                         lib/tls/mbedtls/wrapper/include/openssl/ssl.h)
1176         
1177                 list(APPEND HDR_PRIVATE
1178                         lib/tls/mbedtls/wrapper/include/platform/ssl_pm.h
1179                         lib/tls/mbedtls/wrapper/include/platform/ssl_port.h)
1180         
1181                 list(APPEND SOURCES
1182                         lib/tls/mbedtls/wrapper/library/ssl_cert.c
1183                         lib/tls/mbedtls/wrapper/library/ssl_lib.c
1184                         lib/tls/mbedtls/wrapper/library/ssl_methods.c
1185                         lib/tls/mbedtls/wrapper/library/ssl_pkey.c
1186                         lib/tls/mbedtls/wrapper/library/ssl_stack.c
1187                         lib/tls/mbedtls/wrapper/library/ssl_x509.c)
1188         
1189                 list(APPEND SOURCES
1190                         lib/tls/mbedtls/wrapper/platform/ssl_pm.c
1191                         lib/tls/mbedtls/wrapper/platform/ssl_port.c)
1192         endif()
1193 endif()
1194
1195 if (LWS_WITH_SSL)
1196         list(APPEND SOURCES
1197                 lib/tls/tls.c
1198         )
1199         if (LWS_WITH_NETWORK)
1200                 list(APPEND SOURCES
1201                         lib/tls/tls-network.c
1202                 )
1203         endif()
1204                 
1205         if (LWS_WITH_MBEDTLS)
1206                 list(APPEND SOURCES
1207                         lib/tls/mbedtls/mbedtls-tls.c
1208                         lib/tls/mbedtls/mbedtls-x509.c
1209                 )
1210                 if (LWS_WITH_NETWORK)
1211                         list(APPEND SOURCES
1212                                 lib/tls/mbedtls/mbedtls-ssl.c
1213                         )
1214                 endif()
1215                 if (LWS_WITH_GENCRYPTO)
1216                         list(APPEND SOURCES
1217                                 lib/tls/mbedtls/lws-genhash.c
1218                                 lib/tls/mbedtls/lws-genrsa.c
1219                                 lib/tls/mbedtls/lws-genaes.c
1220                                 lib/tls/lws-genec-common.c
1221                                 lib/tls/mbedtls/lws-genec.c
1222                                 lib/tls/mbedtls/lws-gencrypto.c
1223                         )
1224                 endif()
1225         else()
1226                 list(APPEND SOURCES
1227                         lib/tls/openssl/openssl-tls.c
1228                         lib/tls/openssl/openssl-x509.c
1229                 )
1230                 if (LWS_WITH_NETWORK)
1231                         list(APPEND SOURCES
1232                                 lib/tls/openssl/openssl-ssl.c
1233                         )
1234                 endif()
1235                 if (LWS_WITH_GENCRYPTO)
1236                         list(APPEND SOURCES
1237                                 lib/tls/openssl/lws-genhash.c
1238                                 lib/tls/openssl/lws-genrsa.c
1239                                 lib/tls/openssl/lws-genaes.c
1240                                 lib/tls/lws-genec-common.c
1241                                 lib/tls/openssl/lws-genec.c
1242                                 lib/tls/openssl/lws-gencrypto.c
1243                         )
1244                 endif()
1245         endif()
1246                 
1247         if (NOT LWS_WITHOUT_SERVER)
1248                 list(APPEND SOURCES
1249                         lib/tls/tls-server.c)
1250                 if (LWS_WITH_MBEDTLS)
1251                         list(APPEND SOURCES
1252                                 lib/tls/mbedtls/mbedtls-server.c)
1253                 else()
1254                         list(APPEND SOURCES
1255                                 lib/tls/openssl/openssl-server.c)
1256                 endif()
1257         endif()
1258         if (NOT LWS_WITHOUT_CLIENT)
1259                 list(APPEND SOURCES
1260                         lib/tls/tls-client.c)
1261                 if (LWS_WITH_MBEDTLS)
1262                         list(APPEND SOURCES
1263                                 lib/tls/mbedtls/mbedtls-client.c)
1264                 else()
1265                         list(APPEND SOURCES
1266                                 lib/tls/openssl/openssl-client.c)
1267                 endif()
1268                 
1269         endif()
1270 endif()
1271
1272 if (NOT LWS_WITHOUT_BUILTIN_SHA1)
1273         list(APPEND SOURCES
1274                 lib/misc/sha-1.c)
1275 endif()
1276
1277 if (LWS_WITH_HTTP2 AND NOT LWS_WITHOUT_SERVER)
1278         list(APPEND SOURCES
1279                 lib/roles/h2/http2.c
1280                 lib/roles/h2/hpack.c
1281                 lib/roles/h2/ops-h2.c)
1282 endif()
1283 # select the active platform files
1284
1285 if (WIN32)
1286         list(APPEND SOURCES
1287                 lib/plat/windows/windows-fds.c
1288                 lib/plat/windows/windows-file.c
1289                 lib/plat/windows/windows-init.c
1290                 lib/plat/windows/windows-misc.c
1291                 lib/plat/windows/windows-pipe.c
1292                 lib/plat/windows/windows-plugins.c
1293                 lib/plat/windows/windows-service.c
1294                 lib/plat/windows/windows-sockets.c
1295                 )
1296 else()
1297
1298         if (LWS_PLAT_OPTEE)
1299                 list(APPEND SOURCES
1300                         lib/plat/optee/lws-plat-optee.c
1301                 )
1302                 if (LWS_WITH_NETWORK)
1303                         list(APPEND SOURCES
1304                                 lib/plat/optee/network.c
1305                         )
1306                 endif()
1307         else()
1308                 if (LWS_WITH_ESP32)
1309                         list(APPEND SOURCES
1310                                 lib/plat/esp32/esp32-fds.c
1311                                 lib/plat/esp32/esp32-file.c
1312                                 lib/plat/esp32/esp32-init.c
1313                                 lib/plat/esp32/esp32-misc.c
1314                                 lib/plat/esp32/esp32-pipe.c
1315                                 lib/plat/esp32/esp32-service.c
1316                                 lib/plat/esp32/esp32-sockets.c
1317                                 lib/misc/romfs.c)
1318                         if(LWS_WITH_ESP32_HELPER)
1319                                 list(APPEND SOURCES lib/plat/esp32/esp32-helpers.c)
1320                         endif()
1321                 else()
1322                         set(LWS_PLAT_UNIX 1)
1323                         list(APPEND SOURCES
1324                                 lib/plat/unix/unix-caps.c
1325                                 lib/plat/unix/unix-file.c
1326                                 lib/plat/unix/unix-misc.c
1327                                 lib/plat/unix/unix-init.c
1328                         )
1329                         if (LWS_WITH_NETWORK)
1330                                 list(APPEND SOURCES
1331                                         lib/plat/unix/unix-pipe.c
1332                                         lib/plat/unix/unix-service.c
1333                                         lib/plat/unix/unix-sockets.c
1334                                         lib/plat/unix/unix-fds.c
1335                                 )
1336                         endif()
1337                                 
1338                         if (LWS_WITH_PLUGINS AND LWS_WITH_LIBUV)
1339                                 list(APPEND SOURCES lib/plat/unix/unix-plugins.c)
1340                         endif()
1341                 endif()
1342         endif()
1343 endif()
1344
1345 if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_SERVER)
1346         list(APPEND SOURCES
1347                 lib/roles/http/server/server.c
1348                 lib/roles/http/server/lws-spa.c)
1349 endif()
1350
1351 if (LWS_ROLE_WS AND NOT LWS_WITHOUT_EXTENSIONS)
1352         list(APPEND HDR_PRIVATE
1353                 lib/roles/ws/ext/extension-permessage-deflate.h)
1354         list(APPEND SOURCES
1355                 lib/roles/ws/ext/extension.c
1356                 lib/roles/ws/ext/extension-permessage-deflate.c)
1357 endif()
1358
1359 if (LWS_WITH_HTTP_PROXY)
1360         list(APPEND SOURCES
1361                 lib/roles/http/server/rewrite.c)
1362 endif()
1363
1364 if (LWS_WITH_POLL AND LWS_WITH_NETWORK)
1365         list(APPEND SOURCES
1366                 lib/event-libs/poll/poll.c)
1367 endif()
1368
1369 if (LWS_WITH_LIBUV AND LWS_WITH_NETWORK)
1370         list(APPEND SOURCES
1371                 lib/event-libs/libuv/libuv.c)
1372 endif()
1373
1374 if (LWS_WITH_LIBEVENT AND LWS_WITH_NETWORK)
1375         list(APPEND SOURCES
1376                 lib/event-libs/libevent/libevent.c)
1377 endif()
1378
1379 if (LWS_WITH_LIBEV AND LWS_WITH_NETWORK)
1380         list(APPEND SOURCES
1381                 lib/event-libs/libev/libev.c)
1382 endif()
1383
1384 if (LWS_WITH_LEJP)
1385         list(APPEND SOURCES
1386                 lib/misc/lejp.c)
1387 endif() 
1388 if (LWS_WITH_LEJP_CONF AND LWS_WITH_NETWORK AND NOT LWS_PLAT_OPTEE)
1389                 list(APPEND SOURCES
1390                         "lib/roles/http/server/lejp-conf.c"
1391                 )
1392 endif()
1393
1394 if (LWS_WITH_ABSTRACT)
1395         list(APPEND SOURCES
1396                 lib/abstract/transports/unit-test.c)
1397 endif()
1398
1399 if (LWS_WITH_SMTP)
1400         list(APPEND SOURCES
1401                 lib/abstract/protocols/smtp/smtp.c)
1402 endif()
1403
1404 if (LWS_WITH_RANGES)
1405         list(APPEND SOURCES
1406                 lib/roles/http/server/ranges.c)
1407 endif()
1408
1409 if (LWS_WITH_ZIP_FOPS)
1410        if (LWS_WITH_ZLIB)
1411                list(APPEND SOURCES
1412                        lib/roles/http/server/fops-zip.c)
1413        else()
1414                message(FATAL_ERROR "Pre-zipped file support (LWS_WITH_ZIP_FOPS) requires ZLIB (LWS_WITH_ZLIB)")
1415        endif()
1416 endif()
1417
1418 if (LWS_WITH_JOSE)
1419         list(APPEND SOURCES
1420                 lib/jose/jwk/jwk.c
1421                 lib/jose/jws/jose.c
1422                 lib/jose/jws/jws.c
1423                 lib/jose/jwe/jwe.c
1424                 lib/jose/jwe/enc/aescbc.c
1425                 lib/jose/jwe/enc/aesgcm.c
1426                 lib/jose/jwe/enc/aeskw.c
1427                 lib/jose/jwe/jwe-rsa-aescbc.c
1428                 lib/jose/jwe/jwe-rsa-aesgcm.c
1429                 lib/jose/jwe/jwe-ecdh-es-aeskw.c
1430                 )
1431 endif()
1432
1433 if (LWS_WITH_JOSE OR LWS_WITH_GENCRYPTO)
1434         list(APPEND SOURCES
1435                 lib/tls/lws-gencrypto-common.c)
1436 endif()
1437
1438 # Add helper files for Windows.
1439 if (WIN32)
1440         set(WIN32_HELPERS_PATH win32port/win32helpers)
1441         include_directories(${WIN32_HELPERS_PATH})
1442
1443                 if (WIN32)
1444                         list(APPEND SOURCES
1445                                 ${WIN32_HELPERS_PATH}/gettimeofday.c
1446                         )
1447
1448                         list(APPEND HDR_PRIVATE
1449                                 ${WIN32_HELPERS_PATH}/gettimeofday.h
1450                         )
1451                 endif(WIN32)
1452
1453 else()
1454         # Unix.
1455         if (NOT LWS_WITHOUT_DAEMONIZE)
1456                 list(APPEND SOURCES
1457                         lib/misc/daemonize.c)
1458         endif()
1459 endif()
1460
1461 if (UNIX)
1462         if (NOT LWS_HAVE_GETIFADDRS)
1463                 list(APPEND HDR_PRIVATE lib/misc/getifaddrs.h)
1464                 list(APPEND SOURCES lib/misc/getifaddrs.c)
1465         endif()
1466 endif()
1467
1468 if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
1469         set(COMPILER_IS_CLANG ON)
1470 endif()
1471
1472 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG)
1473     include (CheckCCompilerFlag)
1474     CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY)
1475     if (LWS_HAVE_VISIBILITY)
1476                 set(VISIBILITY_FLAG -fvisibility=hidden)
1477     endif()
1478     if (LWS_WITH_GCOV)
1479             set (GCOV_FLAGS "-fprofile-arcs -ftest-coverage ")
1480     endif()
1481
1482         if (LWS_WITH_ASAN)
1483                 set (ASAN_FLAGS "-fsanitize=address -fsanitize=undefined -fsanitize-address-use-after-scope -fsanitize-undefined-trap-on-error")
1484                 if (NOT COMPILER_IS_CLANG)
1485                         set (ASAN_FLAGS "${ASAN_FLAGS} -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak")
1486                 endif()
1487                 message("Enabling ASAN")
1488         endif()
1489
1490         check_c_compiler_flag("-Wignored-qualifiers" LWS_GCC_HAS_IGNORED_QUALIFIERS)
1491         check_c_compiler_flag("-Wtype-limits" LWS_GCC_HAS_TYPE_LIMITS)
1492
1493         if (LWS_GCC_HAS_IGNORED_QUALIFIERS)
1494                 set(CMAKE_C_FLAGS "-Wignored-qualifiers ${CMAKE_C_FLAGS}" )
1495         endif()
1496
1497         if (LWS_GCC_HAS_TYPE_LIMITS)
1498                 set(CMAKE_C_FLAGS "-Wtype-limits ${CMAKE_C_FLAGS}" )
1499         endif()
1500
1501     if (UNIX AND NOT LWS_WITH_ESP32)
1502             set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wuninitialized -Werror ${VISIBILITY_FLAG} -Wundef ${GCOV_FLAGS} ${CMAKE_C_FLAGS} ${ASAN_FLAGS}" )
1503     else()
1504             set(CMAKE_C_FLAGS "-Wall -Wsign-compare -Wuninitialized -Werror ${VISIBILITY_FLAG} ${GCOV_FLAGS} ${CMAKE_C_FLAGS}" )
1505     endif()
1506 endif ()
1507
1508 if (LWS_PLAT_OPTEE)
1509         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --sysroot ../../../../lib/libutils/isoc/include -I../../../../lib/libutils/isoc/include -I../../../../lib/libutils/ext/include" )
1510 endif()
1511
1512 if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS)
1513         if (UNIX AND LWS_HAVE_PTHREAD_H)
1514         # jeez clang understands -pthread but dies if he sees it at link time!
1515         # http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang
1516         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
1517     endif()
1518 endif()
1519
1520 if (COMPILER_IS_CLANG)
1521
1522         # otherwise osx blows a bunch of openssl deprecated api errors
1523         set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" )
1524         if (UNIX AND LWS_HAVE_PTHREAD_H)
1525                 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
1526         endif()
1527 endif()
1528
1529 source_group("Headers Private"  FILES ${HDR_PRIVATE})
1530 source_group("Headers Public"   FILES ${HDR_PUBLIC})
1531 source_group("Sources"          FILES ${SOURCES})
1532 source_group("Resources"        FILES ${RESOURCES})
1533
1534 #
1535 # Create the lib.
1536 #
1537 set(LWS_LIBRARIES)
1538
1539 if (LWS_WITH_STATIC)
1540     if (LWS_STATIC_PIC)
1541         set(CMAKE_POSITION_INDEPENDENT_CODE ON)
1542     endif()
1543         add_library(websockets STATIC
1544                                 ${HDR_PRIVATE}
1545                                 ${HDR_PUBLIC}
1546                                 ${SOURCES})
1547         list(APPEND LWS_LIBRARIES websockets)
1548
1549         if (WIN32)
1550                 # Windows uses the same .lib ending for static libraries and shared
1551                 # library linker files, so rename the static library.
1552                 set_target_properties(websockets
1553                         PROPERTIES
1554                         OUTPUT_NAME websockets_static)
1555         endif()
1556         add_custom_command(
1557                       TARGET websockets
1558                       COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets.h
1559                                                          ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets.h
1560         )
1561
1562         add_custom_command(
1563                       TARGET websockets
1564                       COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets/
1565                                                                         ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets
1566         )
1567
1568         add_custom_command(
1569                       TARGET websockets
1570                       COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/lws_config.h
1571                                                          ${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h
1572         )
1573
1574 endif()
1575
1576 if (LWS_WITH_SHARED)
1577         add_library(websockets_shared SHARED
1578                                 ${HDR_PRIVATE}
1579                                 ${HDR_PUBLIC}
1580                                 ${SOURCES}
1581                                 ${RESOURCES})
1582         list(APPEND LWS_LIBRARIES websockets_shared)
1583
1584         # We want the shared lib to be named "libwebsockets"
1585         # not "libwebsocket_shared".
1586         set_target_properties(websockets_shared
1587                 PROPERTIES
1588                 OUTPUT_NAME websockets)
1589
1590         if (WIN32)
1591                 # Compile as DLL (export function declarations)
1592                 set_property(
1593                         TARGET websockets_shared
1594                         PROPERTY COMPILE_DEFINITIONS
1595                         LWS_DLL
1596                         LWS_INTERNAL)
1597         endif()
1598
1599         if (APPLE)
1600                 set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES)
1601         endif()
1602
1603         add_custom_command(
1604                       TARGET websockets_shared
1605                       COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets.h
1606                                                          ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets.h
1607         )
1608
1609         add_custom_command(
1610                       TARGET websockets
1611                       COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets
1612                                                                         ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets
1613         )
1614
1615         add_custom_command(
1616                       TARGET websockets_shared
1617                       COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/lws_config.h
1618                                                          ${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h
1619         )
1620
1621
1622 endif()
1623
1624 # Set the so version of the lib.
1625 # Equivalent to LDFLAGS=-version-info x:x:x
1626 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG)
1627         foreach(lib ${LWS_LIBRARIES})
1628                 set_target_properties(${lib}
1629                         PROPERTIES
1630                         SOVERSION ${SOVERSION})
1631         endforeach()
1632 endif()
1633
1634 set(LIB_LIST)
1635
1636 #
1637 # Find libraries.
1638 #
1639
1640 #
1641 # ZLIB (needed for deflate extension and if LWS_WITH_HTTP_STREAM_COMPRESSION)
1642 #
1643 if (LWS_WITH_ZLIB)
1644         if (LWS_WITH_BUNDLED_ZLIB)
1645                 if (WIN32)
1646                         set(WIN32_ZLIB_PATH "win32port/zlib")
1647                         set(ZLIB_SRCS
1648                                 ${WIN32_ZLIB_PATH}/adler32.c
1649                                 ${WIN32_ZLIB_PATH}/compress.c
1650                                 ${WIN32_ZLIB_PATH}/crc32.c
1651                                 ${WIN32_ZLIB_PATH}/deflate.c
1652                                 ${WIN32_ZLIB_PATH}/gzlib.c
1653                                 ${WIN32_ZLIB_PATH}/gzread.c
1654                                 ${WIN32_ZLIB_PATH}/gzwrite.c
1655                                 ${WIN32_ZLIB_PATH}/infback.c
1656                                 ${WIN32_ZLIB_PATH}/inffast.c
1657                                 ${WIN32_ZLIB_PATH}/inflate.c
1658                                 ${WIN32_ZLIB_PATH}/inftrees.c
1659                                 ${WIN32_ZLIB_PATH}/trees.c
1660                                 ${WIN32_ZLIB_PATH}/uncompr.c
1661                                 ${WIN32_ZLIB_PATH}/zutil.c)
1662                         add_library(zlib_internal STATIC ${ZLIB_SRCS})
1663                         set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
1664                         get_property(ZLIB_LIBRARIES TARGET zlib_internal PROPERTY LOCATION)
1665                         set(ZLIB_FOUND 1)
1666                         # Make sure zlib_internal is compiled before the libs.
1667                         foreach (lib ${LWS_LIBRARIES})
1668                                 add_dependencies(${lib} zlib_internal)
1669                         endforeach()
1670                 else()
1671                         message(FATAL_ERROR "Don't have bundled zlib for that platform")
1672                 endif()
1673         elseif (NOT ZLIB_FOUND)
1674                 if (LWS_WITH_MINIZ)
1675                         find_package(Miniz REQUIRED)
1676                         set(ZLIB_INCLUDE_DIRS ${MINIZ_INCLUDE_DIRS})
1677                         set(ZLIB_LIBRARIES ${MINIZ_LIBRARIES})
1678                 else()
1679                         find_package(ZLIB REQUIRED)
1680                 endif()
1681         endif()
1682         message("zlib/miniz include dirs: ${ZLIB_INCLUDE_DIRS}")
1683         message("zlib/miniz libraries: ${ZLIB_LIBRARIES}")
1684         include_directories(${ZLIB_INCLUDE_DIRS})
1685         list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
1686 endif()
1687
1688 if (LWS_WITH_HTTP_BROTLI)
1689         list(APPEND LIB_LIST brotlienc brotlidec brotlidec)
1690 endif()
1691
1692 #
1693 # OpenSSL
1694 #
1695 if (LWS_WITH_SSL)
1696         message("Compiling with SSL support")
1697         set(chose_ssl 0)
1698         if (LWS_WITH_WOLFSSL)
1699                 # Use wolfSSL as OpenSSL replacement.
1700                 # TODO: Add a find_package command for this also.
1701                 message("wolfSSL include dir: ${WOLFSSL_INCLUDE_DIRS}")
1702                 message("wolfSSL libraries: ${WOLFSSL_LIBRARIES}")
1703
1704                 # Additional to the root directory we need to include
1705                 # the wolfssl/ subdirectory which contains the OpenSSL
1706                 # compatibility layer headers.
1707
1708                 if (LWS_WITH_CYASSL)
1709                         foreach(inc ${WOLFSSL_INCLUDE_DIRS})
1710                                 include_directories("${inc}" "${inc}/cyassl")
1711                         endforeach()
1712                 else()
1713                         foreach(inc ${WOLFSSL_INCLUDE_DIRS})
1714                                 include_directories("${inc}" "${inc}/wolfssl")
1715                         endforeach()
1716                 endif()
1717
1718                 list(APPEND LIB_LIST "${WOLFSSL_LIBRARIES}")
1719                 set(chose_ssl 1)
1720         endif()
1721
1722         if (LWS_WITH_MBEDTLS)
1723                 message("MBEDTLS include dir: ${MBEDTLS_INCLUDE_DIRS}")
1724                 message("MBEDTLS libraries: ${MBEDTLS_LIBRARIES}")
1725
1726                 foreach(inc ${MBEDTLS_INCLUDE_DIRS})
1727                         include_directories("${inc}" "${inc}/mbedtls")
1728                 endforeach()
1729
1730                 list(APPEND LIB_LIST "${MBEDTLS_LIBRARIES}")
1731                 set(chose_ssl 1)
1732         endif()
1733
1734         if (NOT chose_ssl)
1735                 if (NOT OPENSSL_FOUND AND NOT LWS_WITH_BORINGSSL)
1736                         # TODO: Add support for STATIC also.
1737                 if (NOT LWS_WITH_ESP32)
1738                         find_package(OpenSSL REQUIRED)
1739                 endif()
1740                         set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}")
1741                 endif()
1742
1743                 message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}")
1744                 if (NOT LWS_WITH_ESP32)
1745                         message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
1746                 endif()
1747
1748                 include_directories("${OPENSSL_INCLUDE_DIRS}")
1749                 if (NOT LWS_WITH_ESP32)
1750                         list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
1751                 endif()
1752
1753         if (NOT LWS_WITH_MBEDTLS)
1754                 # older (0.98) Openssl lacks this
1755                 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
1756                 check_include_file(openssl/ecdh.h LWS_HAVE_OPENSSL_ECDH_H)
1757
1758                 if (LWS_SSL_SERVER_WITH_ECDH_CERT AND NOT LWS_HAVE_OPENSSL_ECDH_H)
1759                         message(FATAL_ERROR "Missing openssl/ecdh.h, so cannot use LWS_SSL_SERVER_WITH_ECDH_CERT")
1760                 endif()
1761         else()
1762                 unset(LWS_HAVE_OPENSSL_ECDH_H)
1763         endif(NOT LWS_WITH_MBEDTLS)
1764         endif()
1765
1766 endif(LWS_WITH_SSL)
1767
1768 if (LWS_WITH_LIBEV)
1769         if (NOT LIBEV_FOUND)
1770                 find_path(LIBEV_INCLUDE_DIRS NAMES ev.h)
1771                 find_library(LIBEV_LIBRARIES NAMES ev)
1772                 if(LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES)
1773                         set(LIBEV_FOUND 1)
1774                 endif()
1775         endif()
1776         message("libev include dir: ${LIBEV_INCLUDE_DIRS}")
1777         message("libev libraries: ${LIBEV_LIBRARIES}")
1778         include_directories("${LIBEV_INCLUDE_DIRS}")
1779         list(APPEND LIB_LIST ${LIBEV_LIBRARIES})
1780 endif(LWS_WITH_LIBEV)
1781
1782 if (LWS_WITH_LIBUV)
1783         if (NOT LIBUV_FOUND)
1784                 find_path(LIBUV_INCLUDE_DIRS NAMES uv.h)
1785                 find_library(LIBUV_LIBRARIES NAMES uv)
1786                 if(LIBUV_INCLUDE_DIRS AND LIBUV_LIBRARIES)
1787                         set(LIBUV_FOUND 1)
1788                 endif()
1789         endif()
1790         message("libuv include dir: ${LIBUV_INCLUDE_DIRS}")
1791         message("libuv libraries: ${LIBUV_LIBRARIES}")
1792         include_directories("${LIBUV_INCLUDE_DIRS}")
1793         list(APPEND LIB_LIST ${LIBUV_LIBRARIES})
1794 endif()
1795
1796 if (LWS_WITH_LIBEVENT)
1797         if (NOT LIBEVENT_FOUND)
1798                 find_path(LIBEVENT_INCLUDE_DIRS NAMES event2/event.h)
1799                 find_library(LIBEVENT_LIBRARIES NAMES event)
1800                 if(LIBEVENT_INCLUDE_DIRS AND LIBEVENT_LIBRARIES)
1801                         set(LIBEVENT_FOUND 1)
1802                 endif()
1803         endif()
1804         message("libevent include dir: ${LIBEVENT_INCLUDE_DIRS}")
1805         message("libevent libraries: ${LIBEVENT_LIBRARIES}")
1806         include_directories("${LIBEVENT_INCLUDE_DIRS}")
1807         list(APPEND LIB_LIST ${LIBEVENT_LIBRARIES})
1808 endif(LWS_WITH_LIBEVENT)
1809
1810 if (LWS_WITH_SQLITE3)
1811         if (NOT SQLITE3_FOUND)
1812                 find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h)
1813                 find_library(SQLITE3_LIBRARIES NAMES sqlite3)
1814                 if(SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
1815                         set(SQLITE3_FOUND 1)
1816                 endif()
1817         endif()
1818         message("sqlite3 include dir: ${SQLITE3_INCLUDE_DIRS}")
1819         message("sqlite3 libraries: ${SQLITE3_LIBRARIES}")
1820         include_directories("${SQLITE3_INCLUDE_DIRS}")
1821         list(APPEND LIB_LIST ${SQLITE3_LIBRARIES})
1822 endif()
1823
1824
1825 if (LWS_WITH_HUBBUB)
1826         find_library(LIBHUBBUB_LIBRARIES NAMES hubbub)
1827         list(APPEND LIB_LIST ${LIBHUBBUB_LIBRARIES} )
1828 endif()
1829
1830 if (LWS_ROLE_DBUS)
1831         message("dbus include dir 1: ${LWS_DBUS_INCLUDE1}")
1832         message("dbus include dir 2: ${LWS_DBUS_INCLUDE2}")
1833         include_directories("${LWS_DBUS_INCLUDE1}")
1834         include_directories("${LWS_DBUS_INCLUDE2}")
1835         list(APPEND LIB_LIST ${LWS_DBUS_LIB})
1836 endif()
1837
1838 #
1839 # Platform specific libs.
1840 #
1841 if (WINCE)
1842         list(APPEND LIB_LIST ws2.lib)
1843 elseif (WIN32)
1844         list(APPEND LIB_LIST ws2_32.lib userenv.lib psapi.lib iphlpapi.lib)
1845 endif()
1846
1847 if (${CMAKE_SYSTEM_NAME} MATCHES "QNX")
1848         list(APPEND LIB_LIST socket)
1849 endif()
1850
1851 if (UNIX)
1852         list(APPEND LIB_LIST m)
1853 endif()
1854
1855 if(SMARTOS)
1856         list(APPEND LIB_LIST socket)
1857 endif()
1858
1859 if (HAIKU)
1860         list(APPEND LIB_LIST network)
1861 endif()
1862
1863 if (LWS_HAVE_LIBCAP)
1864         list(APPEND LIB_LIST cap )
1865 endif()
1866
1867 # Setup the linking for all libs.
1868 foreach (lib ${LWS_LIBRARIES})
1869         target_link_libraries(${lib} ${LIB_LIST})
1870 endforeach()
1871
1872 set (temp ${CMAKE_REQUIRED_LIBRARIES})
1873 set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST})
1874
1875 if (LWS_WITH_ZLIB)
1876         if (LWS_WITH_BUNDLED_ZLIB)
1877                 if (WIN32)
1878                         # it's trying to delete internal zlib entry
1879                         LIST(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0 )
1880                 endif()
1881         endif()
1882 endif()
1883
1884 CHECK_FUNCTION_EXISTS(SSL_CTX_set1_param LWS_HAVE_SSL_CTX_set1_param)
1885 CHECK_FUNCTION_EXISTS(SSL_set_info_callback LWS_HAVE_SSL_SET_INFO_CALLBACK)
1886 CHECK_FUNCTION_EXISTS(X509_VERIFY_PARAM_set1_host LWS_HAVE_X509_VERIFY_PARAM_set1_host)
1887 CHECK_FUNCTION_EXISTS(RSA_set0_key LWS_HAVE_RSA_SET0_KEY)
1888 CHECK_FUNCTION_EXISTS(X509_get_key_usage LWS_HAVE_X509_get_key_usage)
1889 CHECK_FUNCTION_EXISTS(EVP_PKEY_new_raw_private_key LWS_HAVE_SSL_CTX_EVP_PKEY_new_raw_private_key)
1890 CHECK_FUNCTION_EXISTS(SSL_CTX_get0_certificate LWS_HAVE_SSL_CTX_get0_certificate)
1891 CHECK_FUNCTION_EXISTS(SSL_get0_alpn_selected LWS_HAVE_SSL_get0_alpn_selected)
1892 CHECK_FUNCTION_EXISTS(SSL_set_alpn_protos LWS_HAVE_SSL_set_alpn_protos)
1893 CHECK_FUNCTION_EXISTS(EVP_aes_128_cfb8 LWS_HAVE_EVP_aes_128_cfb8)
1894 CHECK_FUNCTION_EXISTS(EVP_aes_128_cfb128 LWS_HAVE_EVP_aes_128_cfb128)
1895 CHECK_FUNCTION_EXISTS(EVP_aes_192_cfb8 LWS_HAVE_EVP_aes_192_cfb8)
1896 CHECK_FUNCTION_EXISTS(EVP_aes_192_cfb128 LWS_HAVE_EVP_aes_192_cfb128)
1897 CHECK_FUNCTION_EXISTS(EVP_aes_256_cfb8 LWS_HAVE_EVP_aes_256_cfb8)
1898 CHECK_FUNCTION_EXISTS(EVP_aes_256_cfb128 LWS_HAVE_EVP_aes_256_cfb128)
1899 CHECK_FUNCTION_EXISTS(EVP_aes_128_xts LWS_HAVE_EVP_aes_128_xts)
1900 CHECK_FUNCTION_EXISTS(RSA_verify_pss_mgf1 LWS_HAVE_RSA_verify_pss_mgf1)
1901 CHECK_FUNCTION_EXISTS(HMAC_CTX_new LWS_HAVE_HMAC_CTX_new)
1902 CHECK_FUNCTION_EXISTS(SSL_CTX_set_ciphersuites LWS_HAVE_SSL_CTX_set_ciphersuites)
1903 if (LWS_WITH_SSL AND NOT LWS_WITH_MBEDTLS)
1904  if (UNIX)
1905  set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
1906  endif()
1907 CHECK_C_SOURCE_COMPILES("#include <openssl/ssl.h>\nint main(void) { STACK_OF(X509) *c = NULL; SSL_CTX *ctx = NULL; return (int)SSL_CTX_get_extra_chain_certs_only(ctx, &c); }\n" LWS_HAVE_SSL_EXTRA_CHAIN_CERTS)
1908 CHECK_C_SOURCE_COMPILES("#include <openssl/ssl.h>\nint main(void) { EVP_MD_CTX *md_ctx = NULL; EVP_MD_CTX_free(md_ctx); return 0; }\n" LWS_HAVE_EVP_MD_CTX_free)
1909 CHECK_FUNCTION_EXISTS(ECDSA_SIG_set0 LWS_HAVE_ECDSA_SIG_set0)
1910 CHECK_FUNCTION_EXISTS(BN_bn2binpad LWS_HAVE_BN_bn2binpad)
1911 CHECK_FUNCTION_EXISTS(EVP_aes_128_wrap LWS_HAVE_EVP_aes_128_wrap)
1912 CHECK_FUNCTION_EXISTS(EC_POINT_get_affine_coordinates LWS_HAVE_EC_POINT_get_affine_coordinates)
1913 endif()
1914 if (LWS_WITH_MBEDTLS)
1915         set(LWS_HAVE_TLS_CLIENT_METHOD 1)
1916         if (NOT LWS_WITH_ESP32)
1917                 # not supported in esp-idf openssl wrapper yet, but is in our version
1918                 set(LWS_HAVE_X509_VERIFY_PARAM_set1_host 1)
1919         endif()
1920
1921         CHECK_FUNCTION_EXISTS(mbedtls_ssl_conf_alpn_protocols LWS_HAVE_mbedtls_ssl_conf_alpn_protocols)
1922         CHECK_FUNCTION_EXISTS(mbedtls_ssl_get_alpn_protocol LWS_HAVE_mbedtls_ssl_get_alpn_protocol)
1923         CHECK_FUNCTION_EXISTS(mbedtls_ssl_conf_sni LWS_HAVE_mbedtls_ssl_conf_sni)
1924         CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_ca_chain LWS_HAVE_mbedtls_ssl_set_hs_ca_chain)
1925         CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_own_cert LWS_HAVE_mbedtls_ssl_set_hs_own_cert)
1926         CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_authmode LWS_HAVE_mbedtls_ssl_set_hs_authmode)
1927         CHECK_FUNCTION_EXISTS(mbedtls_net_init LWS_HAVE_mbedtls_net_init)
1928
1929 else()
1930 CHECK_FUNCTION_EXISTS(TLS_client_method LWS_HAVE_TLS_CLIENT_METHOD)
1931 CHECK_FUNCTION_EXISTS(TLSv1_2_client_method LWS_HAVE_TLSV1_2_CLIENT_METHOD)
1932 endif()
1933
1934 # ideally we want to use pipe2()
1935
1936 CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE\n#include <unistd.h>\nint main(void) {int fd[2];\n return pipe2(fd, 0);\n}\n" LWS_HAVE_PIPE2)
1937
1938 # tcp keepalive needs this on linux to work practically... but it only exists
1939 # after kernel 2.6.37
1940
1941 CHECK_C_SOURCE_COMPILES("#include <netinet/tcp.h>\nint main(void) { return TCP_USER_TIMEOUT; }\n" LWS_HAVE_TCP_USER_TIMEOUT)
1942
1943 set(CMAKE_REQUIRED_LIBRARIES ${temp})
1944 # Generate the lws_config.h that includes all the public compilation settings.
1945 configure_file(
1946        "${PROJECT_SOURCE_DIR}/cmake/lws_config.h.in"
1947        "${PROJECT_BINARY_DIR}/lws_config.h")
1948
1949 # Generate the lws_config.h that includes all the private compilation settings.
1950 configure_file(
1951        "${PROJECT_SOURCE_DIR}/cmake/lws_config_private.h.in"
1952        "${PROJECT_BINARY_DIR}/lws_config_private.h")
1953
1954 # Generate self-signed SSL certs for the test-server.
1955
1956 if (LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL)
1957         message("Searching for OpenSSL executable and dlls")
1958         find_package(OpenSSLbins)
1959         message("OpenSSL executable: ${OPENSSL_EXECUTABLE}")
1960         if (OPENSSL_EXECUTABLE MATCHES "^$")
1961                 set(OPENSSL_EXECUTABLE openssl)
1962         endif()
1963         if (NOT OPENSSL_EXECUTABLE)
1964                 set(OPENSSL_EXECUTABLE openssl)
1965         endif()
1966
1967 endif()
1968
1969 set(GENCERTS 0)
1970
1971 if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_TESTAPPS)
1972         set(GENCERTS 1)
1973 endif()
1974 if (LWS_WITH_ESP32)
1975         set(GENCERTS 1)
1976 endif()
1977 message(" GENCERTS = ${GENCERTS}")
1978 if (GENCERTS)
1979         message("Generating SSL Certificates for the test-server...")
1980
1981         set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem")
1982         set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem")
1983
1984         if (WIN32)
1985                 if (MINGW)
1986                         message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -subj \"/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost\" -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
1987                         execute_process(
1988                                 COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -subj "/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost" -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1989                                 RESULT_VARIABLE OPENSSL_RETURN_CODE)
1990                 else()
1991                         file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt"
1992                                 "GB\n"
1993                                 "Erewhon\n"
1994                                 "All around\n"
1995                                 "libwebsockets-test\n"
1996                                 "localhost\n"
1997                                 "none@invalid.org\n\n"
1998                                 )
1999
2000                         # The "type" command is a bit picky with paths.
2001                         file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
2002                         message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
2003                         message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
2004
2005                         execute_process(
2006                                 COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
2007                                 COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
2008                                 RESULT_VARIABLE OPENSSL_RETURN_CODE
2009                                 OUTPUT_QUIET ERROR_QUIET)
2010
2011                         message("\n")
2012                 endif()
2013
2014                 if (OPENSSL_RETURN_CODE)
2015                         message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
2016                 else()
2017                         message("SUCCSESFULLY generated SSL certificate")
2018                 endif()
2019         else()
2020                 # Unix.
2021                 execute_process(
2022                         COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n"
2023                         COMMAND "${OPENSSL_EXECUTABLE}"
2024                                 req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
2025                         RESULT_VARIABLE OPENSSL_RETURN_CODE
2026                         #               OUTPUT_QUIET ERROR_QUIET
2027                         )
2028
2029                 if (OPENSSL_RETURN_CODE)
2030                         message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
2031                 else()
2032                         message("SUCCESSFULLY generated SSL certificate")
2033                 endif()
2034         endif()
2035
2036         list(APPEND TEST_SERVER_DATA 
2037                 "${TEST_SERVER_SSL_KEY}"
2038                 "${TEST_SERVER_SSL_CERT}")
2039 endif()
2040
2041
2042
2043
2044 #
2045 # Test applications
2046 #
2047 set(TEST_APP_LIST)
2048 if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS)
2049         #
2050         # Helper function for adding a test app.
2051         #
2052         macro(create_test_app TEST_NAME MAIN_SRC S2 S3 S4 S5 S6)
2053
2054                 set(TEST_SRCS ${MAIN_SRC})
2055                 set(TEST_HDR)
2056                 if ("${S2}" STREQUAL "")
2057                 else()
2058                         list(APPEND TEST_SRCS ${S2})
2059                 endif()
2060                 if ("${S3}" STREQUAL "")
2061                 else()
2062                         list(APPEND TEST_SRCS ${S3})
2063                 endif()
2064                 if ("${S4}" STREQUAL "")
2065                 else()
2066                         list(APPEND TEST_SRCS ${S4})
2067                 endif()
2068                 if ("${S5}" STREQUAL "")
2069                 else()
2070                         list(APPEND TEST_SRCS ${S5})
2071                 endif()
2072                 if ("${S6}" STREQUAL "")
2073                 else()
2074                         list(APPEND TEST_SRCS ${S6})
2075                 endif()
2076                 if (WIN32)
2077                         list(APPEND TEST_SRCS
2078                                 ${WIN32_HELPERS_PATH}/getopt.c
2079                                 ${WIN32_HELPERS_PATH}/getopt_long.c
2080                                 ${WIN32_HELPERS_PATH}/gettimeofday.c
2081                         )
2082
2083                         list(APPEND TEST_HDR
2084                                 ${WIN32_HELPERS_PATH}/getopt.h
2085                                 ${WIN32_HELPERS_PATH}/gettimeofday.h
2086                         )
2087                 endif(WIN32)
2088
2089                 source_group("Headers Private"   FILES ${TEST_HDR})
2090                 source_group("Sources"   FILES ${TEST_SRCS})
2091                 add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
2092
2093                 if (LWS_LINK_TESTAPPS_DYNAMIC)
2094                         if (NOT LWS_WITH_SHARED)
2095                                 message(FATAL_ERROR "Build of the shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.")
2096                         endif()
2097                         target_link_libraries(${TEST_NAME} websockets_shared)
2098                         add_dependencies(${TEST_NAME} websockets_shared)
2099                 else()
2100                         if (NOT LWS_WITH_STATIC)
2101                                 message(FATAL_ERROR "Build of the static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.")
2102                         endif()
2103                         target_link_libraries(${TEST_NAME} websockets)
2104                         add_dependencies(${TEST_NAME} websockets)
2105                         if (UNIX AND LWS_WITH_SSL AND NOT LWS_WITH_MBEDTLS)
2106                                 target_link_libraries(${TEST_NAME} dl)
2107                         endif()
2108                 endif()
2109
2110                 if (LWS_WITH_HTTP_STREAM_COMPRESSION)
2111                         target_link_libraries(${TEST_NAME} z)
2112                 endif()
2113
2114                 # Set test app specific defines.
2115                 set_property(TARGET ${TEST_NAME}
2116                                         PROPERTY COMPILE_DEFINITIONS
2117                                                 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
2118                                         )
2119
2120                 # Prefix the binary names with libwebsockets.
2121                 set_target_properties(${TEST_NAME}
2122                         PROPERTIES
2123                         OUTPUT_NAME libwebsockets-${TEST_NAME})
2124
2125                 # Add to the list of tests.
2126                 list(APPEND TEST_APP_LIST ${TEST_NAME})
2127         endmacro()
2128
2129         if (UNIX AND LWS_WITH_PLUGINS)
2130                 set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
2131                 if(NOT((${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") OR (${CMAKE_SYSTEM_NAME} MATCHES "QNX")))
2132                         target_link_libraries(websockets dl)
2133                 endif()
2134         endif()
2135
2136         if (LWS_WITH_LIBEV)
2137                 # libev generates a big mess of warnings with gcc, maintainer claims gcc to blame
2138                 set_source_files_properties( lib/event-libs/libev/libev.c PROPERTIES COMPILE_FLAGS "-Wno-error" )
2139         endif()
2140
2141
2142         if (NOT LWS_WITHOUT_SERVER)
2143                 #
2144                 # test-server
2145                 #
2146                 if (NOT LWS_WITHOUT_TEST_SERVER)
2147                         create_test_app(test-server "test-apps/test-server.c"
2148                                 ""
2149                                 ""
2150                                 ""
2151                                 ""
2152                                 "")
2153
2154                         if (LWS_WITH_CGI)
2155                         create_test_app(test-sshd "test-apps/test-sshd.c"
2156                                 ""
2157                                 ""
2158                                 ""
2159                                 ""
2160                                 "")
2161                         target_include_directories(test-sshd PRIVATE "${PROJECT_SOURCE_DIR}/plugins/ssh-base/include")
2162
2163                         endif()
2164
2165                 endif()
2166
2167                 #
2168                 # test-server-extpoll
2169                 #
2170                 if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL AND NOT WIN32)
2171                         create_test_app(test-server-extpoll
2172                                 "test-apps/test-server.c"
2173                                 ""
2174                                 ""
2175                                 ""
2176                                 ""
2177                                 "")
2178                         # Set defines for this executable only.
2179                         set_property(
2180                                 TARGET test-server-extpoll
2181                                 PROPERTY COMPILE_DEFINITIONS 
2182                                         EXTERNAL_POLL 
2183                                         INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
2184                                 )
2185
2186                         # We need to link against winsock code.
2187                         if (WIN32)
2188                                 target_link_libraries(test-server-extpoll ws2_32.lib)
2189                         endif(WIN32)
2190                 endif()
2191
2192                 if (LWS_WITH_LEJP)
2193                         create_test_app(
2194                                 test-lejp
2195                                 "test-apps/test-lejp.c"
2196                                 ""
2197                                 ""
2198                                 ""
2199                                 ""
2200                                 "")
2201                 endif()
2202
2203                 # Data files for running the test server.
2204                 list(APPEND TEST_SERVER_DATA
2205                         "${PROJECT_SOURCE_DIR}/test-apps/favicon.ico"
2206                         "${PROJECT_SOURCE_DIR}/test-apps/leaf.jpg"
2207                         "${PROJECT_SOURCE_DIR}/test-apps/candide.zip"
2208                         "${PROJECT_SOURCE_DIR}/test-apps/libwebsockets.org-logo.svg"
2209                         "${PROJECT_SOURCE_DIR}/test-apps/http2.png"
2210                         "${PROJECT_SOURCE_DIR}/test-apps/wss-over-h2.png"
2211                         "${PROJECT_SOURCE_DIR}/test-apps/lws-common.js"
2212                         "${PROJECT_SOURCE_DIR}/test-apps/test.html"
2213                         "${PROJECT_SOURCE_DIR}/test-apps/test.css"
2214                         "${PROJECT_SOURCE_DIR}/test-apps/test.js")
2215
2216                 add_custom_command(TARGET test-server
2217                                                 POST_BUILD 
2218                                                 COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server")
2219
2220                 # Copy the file needed to run the server so that the test apps can
2221                 # reach them from their default output location
2222                 foreach (TEST_FILE ${TEST_SERVER_DATA})
2223                         if (EXISTS ${TEST_FILE})
2224                                 add_custom_command(TARGET test-server
2225                                                         POST_BUILD 
2226                                                         COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM)
2227                         endif()
2228                 endforeach()
2229         endif(NOT LWS_WITHOUT_SERVER)
2230
2231         if (NOT LWS_WITHOUT_CLIENT)
2232                 #
2233                 # test-client
2234                 #
2235                 if (NOT LWS_WITHOUT_TEST_CLIENT)
2236                         create_test_app(test-client "test-apps/test-client.c" "" "" "" "" "")
2237                 endif()
2238
2239         endif(NOT LWS_WITHOUT_CLIENT)
2240         
2241         
2242         if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
2243                 macro(create_plugin PLUGIN_NAME PLUGIN_INCLUDE MAIN_SRC S2 S3)
2244
2245                 set(PLUGIN_SRCS ${MAIN_SRC})
2246
2247                 if ("${S2}" STREQUAL "")
2248                 else()
2249                         list(APPEND PLUGIN_SRCS ${S2})
2250                 endif()
2251                 if ("${S3}" STREQUAL "")
2252                 else()
2253                         list(APPEND PLUGIN_SRCS ${S3})
2254                 endif()
2255
2256                 if (WIN32)
2257                         list(APPEND PLUGIN_SRCS
2258                                 ${WIN32_HELPERS_PATH}/getopt.c
2259                                 ${WIN32_HELPERS_PATH}/getopt_long.c
2260                                 ${WIN32_HELPERS_PATH}/gettimeofday.c
2261                         )
2262
2263                         list(APPEND PLUGIN_HDR
2264                                 ${WIN32_HELPERS_PATH}/getopt.h
2265                                 ${WIN32_HELPERS_PATH}/gettimeofday.h
2266                         )
2267                 endif(WIN32)
2268
2269                 source_group("Headers Private"   FILES ${PLUGIN_HDR})
2270                 source_group("Sources"   FILES ${PLUGIN_SRCS})
2271                 add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR})
2272                 
2273                 target_link_libraries(${PLUGIN_NAME} websockets_shared)
2274                 add_dependencies(${PLUGIN_NAME} websockets_shared)
2275                 include_directories(${PLUGIN_INCLUDE})
2276
2277                 # Set test app specific defines.
2278                 set_property(TARGET ${PLUGIN_NAME}
2279                              PROPERTY COMPILE_DEFINITIONS
2280                              INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
2281                 )
2282
2283                 SET_TARGET_PROPERTIES(${PLUGIN_NAME}
2284                                PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS})
2285
2286 #               set_target_properties(${PLUGIN_NAME}
2287 #                       PROPERTIES
2288 #                       OUTPUT_NAME ${PLUGIN_NAME})
2289
2290                 list(APPEND PLUGINS_LIST ${PLUGIN_NAME})
2291
2292                 endmacro()
2293                 
2294 if (LWS_ROLE_WS)
2295                 create_plugin(protocol_dumb_increment ""
2296                               "plugins/protocol_dumb_increment.c" "" "")
2297                 create_plugin(protocol_lws_mirror ""
2298                               "plugins/protocol_lws_mirror.c" "" "")
2299                 create_plugin(protocol_lws_status ""
2300                               "plugins/protocol_lws_status.c" "" "")
2301                 create_plugin(protocol_lws_table_dirlisting ""
2302                               "plugins/generic-table/protocol_table_dirlisting.c" "" "")
2303                 if (NOT WIN32)
2304                         create_plugin(protocol_lws_raw_test ""
2305                               "plugins/protocol_lws_raw_test.c" "" "")
2306
2307                         create_plugin(protocol_deaddrop ""
2308                               "plugins/deaddrop/protocol_lws_deaddrop.c" "" "")
2309
2310                 endif()
2311
2312 if (LWS_WITH_SERVER_STATUS)
2313                 create_plugin(protocol_lws_server_status ""
2314                               "plugins/protocol_lws_server_status.c" "" "")
2315 endif()
2316
2317 if (NOT LWS_WITHOUT_CLIENT)
2318                 create_plugin(protocol_client_loopback_test ""
2319                               "plugins/protocol_client_loopback_test.c" "" "")
2320 endif()
2321
2322 endif()
2323
2324                 create_plugin(protocol_post_demo ""
2325                               "plugins/protocol_post_demo.c" "" "")
2326
2327 if (LWS_ROLE_RAW_PROXY)
2328                 create_plugin(protocol_lws_raw_proxy ""
2329                               "plugins/raw-proxy/protocol_lws_raw_proxy.c" "" "")
2330 endif()
2331
2332 if (LWS_WITH_FTS)
2333                 create_plugin(protocol_fulltext_demo ""
2334                               "plugins/protocol_fulltext_demo.c" "" "")
2335 endif()
2336
2337
2338 if (LWS_WITH_SSL)
2339                 create_plugin(protocol_lws_ssh_base "plugins/ssh-base/include"
2340                               "plugins/ssh-base/sshd.c;plugins/ssh-base/telnet.c;plugins/ssh-base/kex-25519.c" "plugins/ssh-base/crypto/chacha.c;plugins/ssh-base/crypto/ed25519.c;plugins/ssh-base/crypto/fe25519.c;plugins/ssh-base/crypto/ge25519.c;plugins/ssh-base/crypto/poly1305.c;plugins/ssh-base/crypto/sc25519.c;plugins/ssh-base/crypto/smult_curve25519_ref.c" "")
2341                 create_plugin(protocol_lws_sshd_demo "plugins/ssh-base/include" "plugins/protocol_lws_sshd_demo.c" "" "")
2342
2343                 include_directories("${PROJECT_SOURCE_DIR}/plugins/ssh-base/include")
2344 endif()
2345
2346
2347
2348 if (LWS_WITH_ACME)
2349                 create_plugin(protocol_lws_acme_client ""
2350                               "plugins/acme-client/protocol_lws_acme_client.c" "" "")
2351 endif()
2352
2353 if (LWS_WITH_GENERIC_SESSIONS AND LWS_ROLE_WS)
2354         create_plugin(protocol_generic_sessions ""
2355                       "plugins/generic-sessions/protocol_generic_sessions.c"
2356                       "plugins/generic-sessions/utils.c"
2357                       "plugins/generic-sessions/handlers.c")
2358
2359         if (WIN32)
2360                 target_link_libraries(protocol_generic_sessions ${LWS_SQLITE3_LIBRARIES})
2361         else()
2362                 target_link_libraries(protocol_generic_sessions sqlite3 )
2363         endif(WIN32)
2364
2365                 create_plugin(protocol_lws_messageboard ""
2366                               "plugins/generic-sessions/protocol_lws_messageboard.c" "" "")
2367         if (WIN32)
2368                 target_link_libraries(protocol_lws_messageboard ${LWS_SQLITE3_LIBRARIES})
2369         else()
2370                 target_link_libraries(protocol_lws_messageboard sqlite3 )
2371         endif(WIN32)
2372
2373 endif(LWS_WITH_GENERIC_SESSIONS AND LWS_ROLE_WS)
2374
2375
2376         endif(LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
2377
2378         #
2379         # Copy OpenSSL dlls to the output directory on Windows.
2380         # (Otherwise we'll get an error when trying to run)
2381         #
2382         if (WIN32 AND LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL)
2383                 if(OPENSSL_BIN_FOUND)
2384                         message("OpenSSL dlls found:")
2385                         message("  Libeay: ${LIBEAY_BIN}")
2386                         message("  SSLeay: ${SSLEAY_BIN}")
2387
2388                         foreach(TARGET_BIN ${TEST_APP_LIST})
2389                                 add_custom_command(TARGET ${TARGET_BIN}
2390                                         POST_BUILD
2391                                         COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
2392                                 add_custom_command(TARGET ${TARGET_BIN}
2393                                         POST_BUILD
2394                                         COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
2395
2396                                 #
2397                                 # Win32: if we are using libuv, also need to copy it in the output dir
2398                                 #
2399                                 if (WIN32 AND LWS_WITH_LIBUV)
2400                                         STRING(REPLACE ".lib" ".dll" LIBUV_BIN ${LIBUV_LIBRARIES})
2401                                         add_custom_command(TARGET ${TARGET_BIN}
2402                                                 POST_BUILD
2403                                                 COMMAND "${CMAKE_COMMAND}" -E copy "${LIBUV_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
2404                                 endif()
2405                         endforeach()
2406                 endif()
2407         endif()
2408 endif((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS)
2409
2410 if (LWS_WITH_LWSWS)
2411                 list(APPEND LWSWS_SRCS
2412                         "lwsws/main.c"
2413                 )
2414
2415                 if (WIN32)
2416                         list(APPEND LWSWS_SRCS
2417                                 ${WIN32_HELPERS_PATH}/getopt.c
2418                                 ${WIN32_HELPERS_PATH}/getopt_long.c
2419                                 ${WIN32_HELPERS_PATH}/gettimeofday.c
2420                         )
2421
2422                         list(APPEND LWSWS_HDR
2423                                 ${WIN32_HELPERS_PATH}/getopt.h
2424                                 ${WIN32_HELPERS_PATH}/gettimeofday.h
2425                         )
2426                 endif(WIN32)
2427
2428                 source_group("Headers Private"   FILES ${LWSWS_HDR})
2429                 source_group("Sources"   FILES ${LWSWS_SRCS})
2430                 add_executable("lwsws" ${LWSWS_SRCS} ${LWSWS_HDR})
2431
2432                 target_link_libraries("lwsws" websockets_shared)
2433                 add_dependencies("lwsws" websockets_shared)
2434
2435                 # Set test app specific defines.
2436                 set_property(TARGET "lwsws"
2437                              PROPERTY COMPILE_DEFINITIONS
2438                              INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
2439                 )
2440 endif (LWS_WITH_LWSWS)
2441
2442 if (UNIX)
2443
2444 # Generate and install pkgconfig.
2445 # (This is not indented, because the tabs will be part of the output)
2446 file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc"
2447 "prefix=\"${CMAKE_INSTALL_PREFIX}\"
2448 exec_prefix=\${prefix}
2449 libdir=\${exec_prefix}/lib${LIB_SUFFIX}
2450 includedir=\${prefix}/include
2451
2452 Name: libwebsockets
2453 Description: Websockets server and client library
2454 Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
2455 Requires: openssl1.1
2456
2457 Libs: -L\${libdir} -lwebsockets
2458 Cflags: -I\${includedir}"
2459 )
2460
2461         install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc"
2462                 DESTINATION lib${LIB_SUFFIX}/pkgconfig)
2463
2464 file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets_static.pc"
2465 "prefix=\"${CMAKE_INSTALL_PREFIX}\"
2466 exec_prefix=\${prefix}
2467 libdir=\${exec_prefix}/lib${LIB_SUFFIX}
2468 includedir=\${prefix}/include
2469
2470 Name: libwebsockets_static
2471 Description: Websockets server and client static library
2472 Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
2473 Requires: openssl1.1
2474
2475 Libs: -L\${libdir} -lwebsockets_static
2476 Libs.private:
2477 Cflags: -I\${includedir}"
2478 )
2479
2480         install(FILES "${PROJECT_BINARY_DIR}/libwebsockets_static.pc"
2481                 DESTINATION lib${LIB_SUFFIX}/pkgconfig)
2482
2483
2484 endif(UNIX)
2485
2486 #
2487 # Installation preparations.
2488 #
2489
2490 if(WIN32 AND NOT CYGWIN)
2491   set(DEF_INSTALL_CMAKE_DIR cmake)
2492 else()
2493   set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets)
2494 endif()
2495
2496 set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
2497
2498 # Export targets (This is used for other CMake projects to easily find the libraries and include files).
2499 if (LWS_WITH_EXPORT_LWSTARGETS)
2500     export(TARGETS ${LWS_LIBRARIES}
2501             FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
2502 endif()
2503
2504 export(PACKAGE libwebsockets)
2505
2506 # Generate the config file for the build-tree.
2507 set(LWS__INCLUDE_DIRS 
2508     "${PROJECT_SOURCE_DIR}/lib"
2509     "${PROJECT_BINARY_DIR}")
2510 set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories")
2511 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
2512                 ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake 
2513                 @ONLY)
2514
2515 # Generate the config file for the installation tree.
2516 get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE)
2517 get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE)
2518 file(RELATIVE_PATH 
2519     REL_INCLUDE_DIR 
2520     "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}"
2521     "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir.
2522
2523 # Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in, 
2524 # we escape it here so it's evaluated when it is included instead
2525 # so that the include dirs are given relative to where the 
2526 # config file is located.
2527 set(LWS__INCLUDE_DIRS 
2528     "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}") 
2529 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
2530                 ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake 
2531                 @ONLY)
2532
2533 # Generate version info for both build-tree and install-tree.
2534 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in
2535                 ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake 
2536                 @ONLY)
2537
2538                         set_target_properties(${LWS_LIBRARIES}
2539                                         PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
2540
2541 #
2542 # Installation.
2543 #
2544
2545 install(DIRECTORY include/libwebsockets
2546         DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev_headers)
2547
2548 # Install libs and headers.
2549 install(TARGETS ${LWS_LIBRARIES}
2550                 EXPORT LibwebsocketsTargets
2551                 LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
2552                 ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
2553                 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT libraries # Windows DLLs
2554                 PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
2555                 
2556 set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
2557 set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files")
2558
2559 # Install test apps.
2560 if (NOT LWS_WITHOUT_TESTAPPS)
2561         install(TARGETS ${TEST_APP_LIST}
2562                         RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR}
2563                         COMPONENT examples)
2564         set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files")
2565 endif()
2566
2567 # lwsws
2568 if (LWS_WITH_LWSWS)
2569         install(TARGETS lwsws
2570                 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT lwsws )
2571 endif()
2572
2573 # Programs shared files used by the test-server.
2574 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_SERVER)
2575         install(FILES ${TEST_SERVER_DATA}
2576                         DESTINATION share/libwebsockets-test-server
2577                 COMPONENT examples)
2578
2579                 install(FILES "${PROJECT_SOURCE_DIR}/test-apps/private/index.html"
2580                         DESTINATION share/libwebsockets-test-server/private
2581                         COMPONENT examples)
2582 if (LWS_WITH_CGI)
2583         set(CGI_TEST_SCRIPT "${PROJECT_SOURCE_DIR}/test-apps/lws-cgi-test.sh")
2584         install(FILES ${CGI_TEST_SCRIPT}
2585                         PERMISSIONS  OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
2586                         DESTINATION share/libwebsockets-test-server
2587                         COMPONENT examples)
2588         endif()
2589 endif()
2590
2591
2592 if (NOT LWS_WITHOUT_TEST_SERVER AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_TESTAPPS)
2593         install(FILES test-apps/lws-ssh-test-keys;test-apps/lws-ssh-test-keys.pub
2594                 DESTINATION share/libwebsockets-test-server
2595                 COMPONENT examples)
2596 endif()
2597
2598 # plugins
2599
2600 if (LWS_WITH_PLUGINS)
2601         install(TARGETS ${PLUGINS_LIST}
2602                 PERMISSIONS  OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
2603                 DESTINATION share/libwebsockets-test-server/plugins
2604                 COMPONENT plugins)
2605
2606         if (NOT WIN32)
2607                 install(FILES plugins/deaddrop/assets/index.html;plugins/deaddrop/assets/deaddrop.js;plugins/deaddrop/assets/deaddrop.css;plugins/deaddrop/assets/drop.svg
2608                         DESTINATION share/libwebsockets-test-server/deaddrop
2609                         COMPONENT plugins)
2610         endif()
2611
2612
2613 if (LWS_WITH_SERVER_STATUS)
2614         install(FILES plugins/server-status.html;plugins/server-status.js;plugins/server-status.css;plugins/lwsws-logo.png
2615                 DESTINATION share/libwebsockets-test-server/server-status
2616                         COMPONENT examples)
2617 endif()
2618 if (LWS_WITH_GENERIC_SESSIONS)
2619         install(FILES
2620                       plugins/generic-sessions/assets/lwsgs-logo.png
2621                       plugins/generic-sessions/assets/seats.jpg
2622                       plugins/generic-sessions/assets/failed-login.html
2623                       plugins/generic-sessions/assets/lwsgs.js
2624                       plugins/generic-sessions/assets/lwsgs.css
2625                       plugins/generic-sessions/assets/post-register-fail.html
2626                       plugins/generic-sessions/assets/post-register-ok.html
2627                       plugins/generic-sessions/assets/post-verify-ok.html
2628                       plugins/generic-sessions/assets/post-verify-fail.html
2629                       plugins/generic-sessions/assets/sent-forgot-ok.html
2630                       plugins/generic-sessions/assets/sent-forgot-fail.html
2631                       plugins/generic-sessions/assets/post-forgot-ok.html
2632                       plugins/generic-sessions/assets/post-forgot-fail.html
2633                       plugins/generic-sessions/assets/index.html
2634                 DESTINATION share/libwebsockets-test-server/generic-sessions
2635                         COMPONENT examples)
2636         install(FILES plugins/generic-sessions/assets/successful-login.html 
2637                 DESTINATION share/libwebsockets-test-server/generic-sessions/needauth
2638                         COMPONENT examples)
2639         install(FILES plugins/generic-sessions/assets/admin-login.html
2640                 DESTINATION share/libwebsockets-test-server/generic-sessions/needadmin
2641                         COMPONENT examples)
2642 endif()
2643
2644         install(FILES
2645                       plugins/generic-table/assets/lwsgt.js
2646                       plugins/generic-table/assets/index.html
2647                 DESTINATION share/libwebsockets-test-server/generic-table
2648                         COMPONENT examples)
2649
2650 endif()
2651
2652 # Install the LibwebsocketsConfig.cmake and LibwebsocketsConfigVersion.cmake
2653 install(FILES
2654                "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake"
2655                "${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake"
2656                DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
2657
2658 # Install exports for the install-tree.
2659 if (LWS_WITH_EXPORT_LWSTARGETS)
2660     install(EXPORT LibwebsocketsTargets
2661             DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
2662 endif()
2663
2664 # build subdir is not part of sources
2665 set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) "/.git/" "/build/" "\\\\.tgz$" "\\\\.tar\\\\.gz$")
2666
2667 # Most people are more used to "make dist" compared to "make package_source"
2668 add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source)
2669
2670 include(UseRPMTools)
2671 if (RPMTools_FOUND)
2672         RPMTools_ADD_RPM_TARGETS(libwebsockets scripts/libwebsockets.spec)
2673 endif()
2674
2675 message("---------------------------------------------------------------------")
2676 message("  Settings:  (For more help do cmake -LH <srcpath>)")
2677 message("---------------------------------------------------------------------")
2678 message(" LWS_WITH_STATIC = ${LWS_WITH_STATIC}")
2679 message(" LWS_WITH_SHARED = ${LWS_WITH_SHARED}")
2680 message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)")
2681 message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}")
2682 message(" LWS_WITH_WOLFSSL = ${LWS_WITH_WOLFSSL} (wolfSSL/CyaSSL replacement for OpenSSL)")
2683 if (LWS_WITH_WOLFSSL)
2684         message("   LWS_WOLFSSL_LIBRARIES = ${LWS_WOLFSSL_LIBRARIES}")
2685         message("   LWS_WOLFSSL_INCLUDE_DIRS = ${LWS_WOLFSSL_INCLUDE_DIRS}")
2686 endif()
2687 message(" LWS_WITH_MBEDTLS = ${LWS_WITH_MBEDTLS} (mbedTLS replacement for OpenSSL)")
2688 message(" LWS_WITHOUT_BUILTIN_SHA1 = ${LWS_WITHOUT_BUILTIN_SHA1}")
2689 message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}")
2690 message(" LWS_WITHOUT_CLIENT = ${LWS_WITHOUT_CLIENT}")
2691 message(" LWS_WITHOUT_SERVER = ${LWS_WITHOUT_SERVER}")
2692 message(" LWS_LINK_TESTAPPS_DYNAMIC = ${LWS_LINK_TESTAPPS_DYNAMIC}")
2693 message(" LWS_WITHOUT_TESTAPPS = ${LWS_WITHOUT_TESTAPPS}")
2694 message(" LWS_WITHOUT_TEST_SERVER = ${LWS_WITHOUT_TEST_SERVER}")
2695 message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}")
2696 message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}")
2697 message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}")
2698 message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}")
2699 message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}")
2700 message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}")
2701 message(" LWS_WITH_LIBEV = ${LWS_WITH_LIBEV}")
2702 message(" LWS_WITH_LIBUV = ${LWS_WITH_LIBUV}")
2703 message(" LWS_WITH_LIBEVENT = ${LWS_WITH_LIBEVENT}")
2704 message(" LWS_IPV6 = ${LWS_IPV6}")
2705 message(" LWS_UNIX_SOCK = ${LWS_UNIX_SOCK}")
2706 message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}")
2707 message(" LWS_SSL_SERVER_WITH_ECDH_CERT = ${LWS_SSL_SERVER_WITH_ECDH_CERT}")
2708 message(" LWS_MAX_SMP = ${LWS_MAX_SMP}")
2709 message(" LWS_HAVE_PTHREAD_H = ${LWS_HAVE_PTHREAD_H}")
2710 message(" LWS_WITH_CGI = ${LWS_WITH_CGI}")
2711 message(" LWS_HAVE_OPENSSL_ECDH_H = ${LWS_HAVE_OPENSSL_ECDH_H}")
2712 message(" LWS_HAVE_SSL_CTX_set1_param = ${LWS_HAVE_SSL_CTX_set1_param}")
2713 message(" LWS_HAVE_RSA_SET0_KEY = ${LWS_HAVE_RSA_SET0_KEY}")
2714 message(" LWS_WITH_HTTP_PROXY = ${LWS_WITH_HTTP_PROXY}")
2715 message(" LIBHUBBUB_LIBRARIES = ${LIBHUBBUB_LIBRARIES}")
2716 message(" PLUGINS = ${PLUGINS_LIST}")
2717 message(" LWS_WITH_ACCESS_LOG = ${LWS_WITH_ACCESS_LOG}")
2718 message(" LWS_WITH_SERVER_STATUS = ${LWS_WITH_SERVER_STATUS}")
2719 message(" LWS_WITH_LEJP = ${LWS_WITH_LEJP}")
2720 message(" LWS_WITH_LEJP_CONF = ${LWS_WITH_LEJP_CONF}")
2721 message(" LWS_WITH_SMTP = ${LWS_WITH_SMTP}")
2722 message(" LWS_WITH_GENERIC_SESSIONS = ${LWS_WITH_GENERIC_SESSIONS}")
2723 message(" LWS_STATIC_PIC = ${LWS_STATIC_PIC}")
2724 message(" LWS_WITH_RANGES = ${LWS_WITH_RANGES}")
2725 message(" LWS_PLAT_OPTEE = ${LWS_PLAT_OPTEE}")
2726 message(" LWS_WITH_ESP32 = ${LWS_WITH_ESP32}")
2727 message(" LWS_WITH_ZIP_FOPS = ${LWS_WITH_ZIP_FOPS}")
2728 message(" LWS_AVOID_SIGPIPE_IGN = ${LWS_AVOID_SIGPIPE_IGN}")
2729 message(" LWS_WITH_STATS = ${LWS_WITH_STATS}")
2730 message(" LWS_WITH_SOCKS5 = ${LWS_WITH_SOCKS5}")
2731 message(" LWS_HAVE_SYS_CAPABILITY_H = ${LWS_HAVE_SYS_CAPABILITY_H}")
2732 message(" LWS_HAVE_LIBCAP = ${LWS_HAVE_LIBCAP}")
2733 message(" LWS_WITH_PEER_LIMITS = ${LWS_WITH_PEER_LIMITS}")
2734 message(" LWS_HAVE_ATOLL = ${LWS_HAVE_ATOLL}")
2735 message(" LWS_HAVE__ATOI64 = ${LWS_HAVE__ATOI64}")
2736 message(" LWS_HAVE_STAT32I64 = ${LWS_HAVE_STAT32I64}")
2737 message(" LWS_HAS_INTPTR_T = ${LWS_HAS_INTPTR_T}")
2738 message(" LWS_WITH_EXPORT_LWSTARGETS = ${LWS_WITH_EXPORT_LWSTARGETS}")
2739 message(" LWS_WITH_ABSTRACT = ${LWS_WITH_ABSTRACT}")
2740
2741 message("---------------------------------------------------------------------")
2742
2743 # These will be available to parent projects including libwebsockets using add_subdirectory()
2744 set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries")
2745 if (LWS_WITH_STATIC)
2746         set(LIBWEBSOCKETS_LIBRARIES_STATIC websockets CACHE STRING "Libwebsocket static library")
2747 endif()
2748 if (LWS_WITH_SHARED)
2749         set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library")
2750 endif()
2751
2752 if (LWS_WITH_MINIMAL_EXAMPLES)
2753         MACRO(SUBDIRLIST result curdir)
2754           FILE(GLOB children RELATIVE ${curdir} ${curdir}/*)
2755           SET(dirlist "")
2756
2757           FOREACH(child ${children})
2758             IF(IS_DIRECTORY ${curdir}/${child})
2759                 LIST(APPEND dirlist ${child})
2760             ENDIF()
2761           ENDFOREACH()
2762
2763           SET(${result} ${dirlist})
2764         ENDMACRO()
2765
2766         SUBDIRLIST(SUBDIRS "${PROJECT_SOURCE_DIR}/minimal-examples")
2767         FOREACH(subdir ${SUBDIRS})
2768
2769                 SUBDIRLIST(SUBDIRS2 "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}")
2770                 FOREACH(subdir2 ${SUBDIRS2})
2771                         if (EXISTS "${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}/CMakeLists.txt")
2772                                 message("Processing ${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}")
2773                                 add_subdirectory("${PROJECT_SOURCE_DIR}/minimal-examples/${subdir}/${subdir2}")
2774                         endif()
2775                 ENDFOREACH()
2776         ENDFOREACH()
2777 ENDIF()
2778
2779 # This must always be last!
2780 include(CPack)