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