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