1# 2# libwebsockets - small server side websockets and web server implementation 3# 4# Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com> 5# 6# Permission is hereby granted, free of charge, to any person obtaining a copy 7# of this software and associated documentation files (the "Software"), to 8# deal in the Software without restriction, including without limitation the 9# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10# sell copies of the Software, and to permit persons to whom the Software is 11# furnished to do so, subject to the following conditions: 12# 13# The above copyright notice and this permission notice shall be included in 14# all copies or substantial portions of the Software. 15# 16# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22# IN THE SOFTWARE. 23# 24 25cmake_minimum_required(VERSION 2.8.12) 26include(CheckFunctionExists) 27include(CheckSymbolExists) 28include(CheckIncludeFile) 29include(CheckIncludeFiles) 30include(CheckLibraryExists) 31include(CheckTypeSize) 32include(CheckCSourceCompiles) 33 34if (POLICY CMP0048) 35 cmake_policy(SET CMP0048 NEW) 36endif() 37 38#if (POLICY CMP0024) 39# cmake_policy(SET CMP0024 NEW) 40#endif() 41 42if (POLICY CMP0075) 43 cmake_policy(SET CMP0075 NEW) 44endif() 45 46# General Advice 47# 48# For selecting between DEBUG / RELEASE, use -DCMAKE_BUILD_TYPE=DEBUG or =RELEASE 49# debug builds include source level debug info and extra logging 50 51set(LWS_WITH_BUNDLED_ZLIB_DEFAULT OFF) 52if(WIN32) 53 set(LWS_WITH_BUNDLED_ZLIB_DEFAULT ON) 54endif() 55 56set(LWS_ROLE_RAW 1) 57set(LWS_WITH_POLL 1) 58 59if (ESP_PLATFORM) 60 set(LWS_ESP_PLATFORM 1) 61 #set(CMAKE_TOOLCHAIN_FILE contrib/cross-esp32.cmake) 62 set(LWIP_PROVIDE_ERRNO 1) 63endif() 64 65# it's at this point any toolchain file is brought in 66project(libwebsockets C CXX) 67include(CTest) 68 69if (ESP_PLATFORM) 70 include_directories( 71 $ENV{IDF_PATH}/components/esp_hw_support/include/soc/ 72 $ENV{IDF_PATH}/components/freertos/include/ 73 $ENV{IDF_PATH}/components/freertos/esp_additions/include/ 74 $ENV{IDF_PATH}/components/freertos/esp_additions/include/freertos/ 75 $ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/ 76 $ENV{IDF_PATH}/components/freertos/FreeRTOS-Kernel/portable/linux/include/ 77 $ENV{IDF_PATH}/components/xtensa/${CONFIG_IDF_TARGET}/include/ 78 $ENV{IDF_PATH}/components/freertos/include/esp_additions 79 $ENV{IDF_PATH}/components/hal/include 80 $ENV{IDF_PATH}/components/soc/${CONFIG_IDF_TARGET}/include/ 81 $ENV{IDF_PATH}/components/soc/include/ 82 $ENV{IDF_PATH}/components/esp_hw_support/include 83 $ENV{IDF_PATH}/components/hal/${CONFIG_IDF_TARGET}/include/ 84 ) 85 86 if (CONFIG_IDF_TARGET_ARCH_RISCV) 87 include_directories( 88 $ENV{IDF_PATH}/components/freertos/port/riscv/include 89 $ENV{IDF_PATH}/components/riscv/include) 90 else() 91 include_directories( 92 $ENV{IDF_PATH}/components/freertos/port/xtensa/include 93 $ENV{IDF_PATH}/components/xtensa/include) 94 endif() 95 96endif() 97 98 99# 100# Select features recommended for PC distro packaging 101# 102option(LWS_WITH_DISTRO_RECOMMENDED "Enable features recommended for distro packaging" OFF) 103option(LWS_FOR_GITOHASHI "Enable features recommended for use with gitohashi" OFF) 104 105# 106# Compiler features 107# 108option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors" OFF) 109 110# 111# Major individual features 112# 113option(LWS_WITH_NETWORK "Compile with network-related code" ON) 114option(LWS_ROLE_H1 "Compile with support for http/1 (needed for ws)" ON) 115option(LWS_ROLE_WS "Compile with support for websockets" ON) 116option(LWS_ROLE_MQTT "Build with support for MQTT client" OFF) 117option(LWS_ROLE_DBUS "Compile with support for DBUS" OFF) 118option(LWS_ROLE_RAW_PROXY "Raw packet proxy" OFF) 119option(LWS_ROLE_RAW_FILE "Compile with support for raw files" ON) 120option(LWS_WITH_HTTP2 "Compile with server support for HTTP/2" ON) 121option(LWS_WITH_LWSWS "Libwebsockets Webserver" OFF) 122option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out/err) APIs" OFF) 123option(LWS_IPV6 "Compile with support for ipv6" OFF) 124option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket if OS supports it" ON) 125option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions (implies LWS_WITH_PLUGINS_API)" OFF) 126option(LWS_WITH_PLUGINS_BUILTIN "Build the plugin protocols directly into lws library" OFF) 127option(LWS_WITH_HTTP_PROXY "Support for active HTTP proxying" OFF) 128option(LWS_WITH_ZIP_FOPS "Support serving pre-zipped files" OFF) 129option(LWS_WITH_SOCKS5 "Allow use of SOCKS5 proxy on client connections" OFF) 130option(LWS_WITH_PEER_LIMITS "Track peers and restrict resources a single peer can allocate" OFF) 131option(LWS_WITH_ACCESS_LOG "Support generating Apache-compatible access logs" OFF) 132option(LWS_WITH_RANGES "Support http ranges (RFC7233)" OFF) 133option(LWS_WITH_THREADPOOL "Managed worker thread pool support (relies on pthreads)" OFF) 134option(LWS_WITH_HTTP_STREAM_COMPRESSION "Support HTTP stream compression" OFF) 135option(LWS_WITH_HTTP_BROTLI "Also offer brotli http stream compression (requires LWS_WITH_HTTP_STREAM_COMPRESSION)" OFF) 136option(LWS_WITH_ACME "Enable support for ACME automatic cert acquisition + maintenance (letsencrypt etc)" OFF) 137option(LWS_WITH_HUBBUB "Enable libhubbub rewriting support" OFF) 138option(LWS_WITH_ALSA "Enable alsa audio example" OFF) 139option(LWS_WITH_GTK "Enable gtk example" OFF) 140option(LWS_WITH_FTS "Full Text Search support" OFF) 141option(LWS_WITH_SYS_ASYNC_DNS "Nonblocking internal IPv4 + IPv6 DNS resolver" OFF) 142option(LWS_WITH_SYS_NTPCLIENT "Build in tiny ntpclient good for tls date validation and run via lws_system" OFF) 143option(LWS_WITH_SYS_DHCP_CLIENT "Build in tiny DHCP client" OFF) 144option(LWS_WITH_HTTP_BASIC_AUTH "Support Basic Auth" ON) 145option(LWS_WITH_HTTP_UNCOMMON_HEADERS "Include less common http header support" ON) 146option(LWS_WITH_SYS_STATE "lws_system state support" ON) 147option(LWS_WITH_SYS_SMD "Lws System Message Distribution" ON) 148option(LWS_WITH_SYS_FAULT_INJECTION "Enable fault injection support" OFF) 149option(LWS_WITH_SYS_METRICS "Lws Metrics API" OFF) 150 151# 152# Secure Streams 153# 154option(LWS_WITH_SECURE_STREAMS "Secure Streams protocol-agnostic API" OFF) 155option(LWS_WITH_SECURE_STREAMS_CPP "Secure Streams C++ classes" OFF) 156option(LWS_WITH_SECURE_STREAMS_PROXY_API "Secure Streams support to work across processes" OFF) 157option(LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM "Auth support for api.amazon.com" OFF) 158option(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY "Secure Streams Policy is hardcoded only" OFF) 159option(LWS_WITH_SECURE_STREAMS_AUTH_SIGV4 "Secure Streams Auth support for AWS Sigv4" OFF) 160option(LWS_WITH_SECURE_STREAMS_BUFFER_DUMP "Secure Streams protocol buffer dump" OFF) 161option(LWS_WITH_SS_DIRECT_PROTOCOL_STR "Secure Streams directly set/get metadata w/o policy" OFF) 162 163# 164# CTest options 165# 166# 167# If you build with LWS_WITH_MINIMAL_EXAMPLES, you can use CTest / make test to run 168# examples that can give a pass/fail response. By default it runs tests both against 169# a local server peer and warmcat.com, if your CI wants to do the tests but does not 170# have internet routing, then you can still run a subset of tests with CTest / make 171# test that only does local tests by disabling this option. 172# 173option(LWS_CTEST_INTERNET_AVAILABLE "CTest will performs tests that need the Internet" ON) 174 175# 176# TLS library options... all except mbedTLS are basically OpenSSL variants. 177# 178option(LWS_WITH_SSL "Include SSL support (defaults to OpenSSL or similar, mbedTLS if LWS_WITH_MBEDTLS is set)" ON) 179option(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) 180option(LWS_WITH_BORINGSSL "Use BoringSSL replacement for OpenSSL" OFF) 181option(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) 182option(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) 183option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of the OS-installed CA root certs" ON) 184option(LWS_TLS_LOG_PLAINTEXT_RX "For debugging log the received plaintext as soon as decrypted" OFF) 185option(LWS_TLS_LOG_PLAINTEXT_TX "For debugging log the transmitted plaintext just before encryption" OFF) 186option(LWS_WITH_TLS_SESSIONS "Enable persistent, resumable TLS sessions" ON) 187option(LWS_WITH_TLS_JIT_TRUST "Enable dynamically computing which trusted TLS CA is needed to be instantiated" OFF) 188 189# 190# Event library options (may select multiple, or none for default poll() 191# 192option(LWS_WITH_LIBEV "Compile with support for libev" OFF) 193option(LWS_WITH_LIBUV "Compile with support for libuv" OFF) 194option(LWS_WITH_LIBEVENT "Compile with support for libevent" OFF) 195option(LWS_WITH_GLIB "Compile with support for glib event loop" OFF) 196option(LWS_WITH_SDEVENT "Compile with support for sd-event loop" OFF) 197option(LWS_WITH_ULOOP "Compile with support for uloop" OFF) 198 199if (UNIX) 200# since v4.1, on unix platforms default is build any event libs as runtime plugins 201option(LWS_WITH_EVLIB_PLUGINS "Compile event lib support into runtime-selected plugins" ON) 202else() 203# otherwise default to linking the event lib(s) to libwebsockets.so 204option(LWS_WITH_EVLIB_PLUGINS "Compile event lib support into runtime-selected plugins" OFF) 205endif() 206# 207# LWS Drivers 208# 209 210option(LWS_WITH_DRIVERS "With generic drivers for gpio, i2c, display etc" OFF) 211 212# 213# Static / Dynamic build options 214# 215option(LWS_WITH_STATIC "Build the static version of the library" ON) 216option(LWS_WITH_SHARED "Build the shared version of the library" ON) 217option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF) 218option(LWS_STATIC_PIC "Build the static version of the library with position-independent code" OFF) 219option(LWS_SUPPRESS_DEPRECATED_API_WARNINGS "Turn off complaints about, eg, openssl 3 deprecated api usage" ON) 220 221# 222# Specific platforms 223# 224option(LWS_WITH_ESP32 "Build for ESP32" OFF) 225option(LWS_PLAT_OPTEE "Build for OPTEE" OFF) 226option(LWS_PLAT_FREERTOS "Build for FreeRTOS" OFF) 227option(LWS_PLAT_ANDROID "Android flavour of unix platform" OFF) 228 229# 230# Client / Server / Test Apps build control 231# 232option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF) 233option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF) 234option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF) 235option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF) 236option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF) 237option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF) 238option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF) 239# 240# Extensions (permessage-deflate) 241# 242option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" ON) 243# 244# Helpers + misc 245# 246option(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) 247option(LWS_FALLBACK_GETHOSTBYNAME "Also try to do dns resolution using gethostbyname if getaddrinfo fails" OFF) 248option(LWS_WITHOUT_BUILTIN_SHA1 "Don't build the lws sha-1 (eg, because openssl will provide it" OFF) 249option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON) 250option(LWS_SSL_SERVER_WITH_ECDH_CERT "Include SSL server use ECDH certificate" OFF) 251option(LWS_WITH_LEJP "With the Lightweight JSON Parser" ON) 252option(LWS_WITH_CBOR "With the Lightweight LECP CBOR Parser" OFF) 253option(LWS_WITH_CBOR_FLOAT "Build floating point types if building CBOR LECP" ON) 254option(LWS_WITH_SQLITE3 "Require SQLITE3 support" OFF) 255option(LWS_WITH_STRUCT_JSON "Generic struct serialization to and from JSON" OFF) 256option(LWS_WITH_STRUCT_SQLITE3 "Generic struct serialization to and from SQLITE3" OFF) 257# broken atm 258#option(LWS_WITH_SMTP "Provide SMTP support" OFF) 259if (LWS_WITH_ESP32) 260option(LWS_WITH_DIR "Directory scanning api support" OFF) 261option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF) 262else() 263option(LWS_WITH_DIR "Directory scanning api support" ON) 264option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" ON) 265endif() 266option(LWS_WITH_NO_LOGS "Disable all logging other than _err and _user from being compiled in" OFF) 267set(LWS_LOGGING_BITFIELD_SET 0 CACHE STRING "Bitfield describing which log levels to force included into the build") 268set(LWS_LOGGING_BITFIELD_CLEAR 0 CACHE STRING "Bitfield describing which log levels to force removed from the build") 269option(LWS_LOGS_TIMESTAMP "Timestamp at start of logs" ON) 270option(LWS_LOG_TAG_LIFECYCLE "Log tagged object lifecycle as NOTICE" ON) 271option(LWS_AVOID_SIGPIPE_IGN "Android 7+ reportedly needs this" OFF) 272option(LWS_WITH_JOSE "JOSE JSON Web Signature / Encryption / Keys (RFC7515/6/) API" OFF) 273option(LWS_WITH_COSE "COSE CBOR Signature / Encryption / Keys (RFC8152) API" OFF) 274option(LWS_WITH_GENCRYPTO "Enable support for Generic Crypto apis independent of TLS backend" OFF) 275option(LWS_WITH_SELFTESTS "Selftests run at context creation" OFF) 276option(LWS_WITH_GCOV "Build with gcc gcov coverage instrumentation" OFF) 277option(LWS_WITH_EXPORT_LWSTARGETS "Export libwebsockets CMake targets. Disable if they conflict with an outer cmake project." ON) 278option(LWS_REPRODUCIBLE "Build libwebsockets reproducible. It removes the build user and hostname from the build" ON) 279option(LWS_WITH_MINIMAL_EXAMPLES "Also build the normally standalone minimal examples, for QA" OFF) 280option(LWS_WITH_LWSAC "lwsac Chunk Allocation api" ON) 281option(LWS_WITH_CUSTOM_HEADERS "Store and allow querying custom HTTP headers (H1 only)" ON) 282option(LWS_WITH_DISKCACHE "Hashed cache directory with lazy LRU deletion to size limit (unrelated to lws_cache_ttl)" OFF) 283option(LWS_WITH_ASAN "Build with gcc runtime sanitizer options enabled (needs libasan)" OFF) 284option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF) 285option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" OFF) 286option(LWS_WITH_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_WITH_BUNDLED_ZLIB_DEFAULT}) 287option(LWS_WITH_MINIZ "Use miniz instead of zlib" OFF) 288option(LWS_WITH_SEQUENCER "lws_seq_t support" OFF) 289option(LWS_WITH_EXTERNAL_POLL "Support external POLL integration using callback messages (not recommended)" OFF) 290option(LWS_WITH_LWS_DSH "Support lws_dsh_t Disordered Shared Heap" OFF) 291option(LWS_CLIENT_HTTP_PROXYING "Support external http proxies for client connections" ON) 292option(LWS_WITH_FILE_OPS "Support file operations vfs" ON) 293option(LWS_WITH_UDP "Platform supports UDP" ON) 294option(LWS_WITH_SPAWN "Spawn subprocesses with piped stdin/out/stderr" OFF) 295option(LWS_WITH_FSMOUNT "Overlayfs and fallback mounting apis" OFF) 296option(LWS_WITH_FANALYZER "Enable gcc -fanalyzer if compiler supports" OFF) 297option(LWS_HTTP_HEADERS_ALL "Override header reduction optimization and include all like older lws versions" OFF) 298option(LWS_WITH_SUL_DEBUGGING "Enable zombie lws_sul checking on object deletion" OFF) 299option(LWS_WITH_PLUGINS_API "Build generic lws_plugins apis (see LWS_WITH_PLUGINS to also build protocol plugins)" OFF) 300option(LWS_WITH_CONMON "Collect introspectable connection latency stats on individual client connections" ON) 301option(LWS_WITHOUT_EVENTFD "Force using pipe instead of eventfd" OFF) 302if (UNIX OR WIN32) 303 option(LWS_WITH_CACHE_NSCOOKIEJAR "Build file-backed lws-cache-ttl that uses netscape cookie jar format (linux-only)" ON) 304else() 305 option(LWS_WITH_CACHE_NSCOOKIEJAR "Build file-backed lws-cache-ttl that uses netscape cookie jar format (linux-only)" OFF) 306endif() 307 308if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 309 option(LWS_WITH_NETLINK "Monitor Netlink for Routing Table changes" ON) 310else() 311 set(LWS_WITH_NETLINK 0) 312endif() 313 314if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") 315 # its openssl has md5 deprecated 316 set(LWS_SUPPRESS_DEPRECATED_API_WARNINGS 1) 317endif() 318 319 320# 321# to use miniz, enable both LWS_WITH_ZLIB and LWS_WITH_MINIZ 322# 323# End of user settings 324# 325 326# sets of sub-options implied by other options 327# 328set(LIB_LIST "") 329set(LIB_LIST_AT_END) 330set(LWS_LIBRARIES) 331set(LWS_OPENSSL_SUPPORT 0) 332include(CMakeLists-implied-options.txt) 333 334# 335# Structural helpers for cmake in subdirs 336# 337 338macro(add_subdir_include_directories arg1) 339 add_subdirectory(${arg1}) 340 include_directories(${_CMAKE_INC_LIST}) 341endmacro() 342 343macro(exports_to_parent_scope) 344 set(SOURCES ${SOURCES} PARENT_SCOPE) 345 if (LIB_LIST) 346 set(LIB_LIST ${LIB_LIST} PARENT_SCOPE) 347 endif() 348 get_property(_CURR DIRECTORY PROPERTY INCLUDE_DIRECTORIES) 349 set(_CMAKE_INC_LIST ${_CURR} PARENT_SCOPE) 350 if (LWS_LIB_BUILD_INC_PATHS) 351 set(LWS_LIB_BUILD_INC_PATHS ${LWS_LIB_BUILD_INC_PATHS} PARENT_SCOPE) 352 endif() 353endmacro() 354 355macro(export_to_parent_intermediate) 356 set(SOURCES ${SOURCES} PARENT_SCOPE) 357 if (LIB_LIST) 358 set(LIB_LIST ${LIB_LIST} PARENT_SCOPE) 359 endif() 360 set(_CMAKE_INC_LIST ${_CMAKE_INC_LIST} PARENT_SCOPE) 361 if (LWS_LIB_BUILD_INC_PATHS) 362 set(LWS_LIB_BUILD_INC_PATHS ${LWS_LIB_BUILD_INC_PATHS} PARENT_SCOPE) 363 endif() 364endmacro() 365 366# 367# Try to find the current Git hash 368# 369 370find_package(Git) 371if(GIT_EXECUTABLE) 372 execute_process( 373 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 374 COMMAND "${GIT_EXECUTABLE}" describe --tags --always 375 OUTPUT_VARIABLE GIT_HASH 376 OUTPUT_STRIP_TRAILING_WHITESPACE 377 ) 378 set(LWS_BUILD_HASH ${GIT_HASH}) 379 380 # append the build user and hostname 381 if (NOT LWS_REPRODUCIBLE) 382 execute_process( 383 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 384 COMMAND "whoami" 385 OUTPUT_VARIABLE GIT_USER 386 OUTPUT_STRIP_TRAILING_WHITESPACE 387 ) 388 execute_process( 389 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" 390 COMMAND "hostname" 391 OUTPUT_VARIABLE GIT_HOST 392 OUTPUT_STRIP_TRAILING_WHITESPACE 393 ) 394 string(REGEX REPLACE "([^\\])[\\]([^\\])" "\\1\\\\\\\\\\2" GIT_USER ${GIT_USER}) 395 set(LWS_BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH}) 396 endif() 397 398 message("Git commit hash: ${LWS_BUILD_HASH}") 399endif() 400 401if ("${LWS_BUILD_HASH}" STREQUAL "") 402 set(LWS_BUILD_HASH "unknown") 403endif() 404 405set(PACKAGE "libwebsockets") 406set(CPACK_RPM_PACKAGE_LICENSE "MIT") 407set(CPACK_PACKAGE_NAME "${PACKAGE}") 408set(CPACK_PACKAGE_VERSION_MAJOR "4") 409set(CPACK_PACKAGE_VERSION_MINOR "3") 410set(CPACK_PACKAGE_VERSION_PATCH_NUMBER "0") 411 412set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH_NUMBER}-${LWS_BUILD_HASH}") 413set(CPACK_PACKAGE_RELEASE 1) 414 415set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") 416set(CPACK_PACKAGE_VENDOR "andy@warmcat.com") 417set(CPACK_PACKAGE_CONTACT "andy@warmcat.com") 418set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${CPACK_PACKAGE_VERSION}") 419set(SOVERSION "19") 420if(NOT CPACK_GENERATOR) 421 if(UNIX) 422 set(CPACK_GENERATOR "TGZ") 423 else() 424 set(CPACK_GENERATOR "ZIP") 425 endif() 426endif() 427set(CPACK_SOURCE_GENERATOR "TGZ") 428set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") 429set(VERSION "${CPACK_PACKAGE_VERSION}") 430 431set(CPACK_RPM_PACKAGE_RELEASE_DIST ON) 432set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") 433# below makes path length problems in CI 434set(CPACK_RPM_DEBUGINFO_PACKAGE OFF) 435# below makes some kind of chimera rpm with binaries and sources 436set(CPACK_RPM_PACKAGE_SOURCES OFF) 437set(CPACK_RPM_INSTALL_WITH_EXEC ON) 438set(CPACK_RPM_COMPONENT_INSTALL ON) 439 440set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT") 441set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) 442set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON) 443set(CPACK_DEBIAN_PACKAGE_SOURCE ON) 444set(CPACK_DEBIAN_COMPONENT_INSTALL ON) 445 446 447set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION}) 448set(LWS_LIBRARY_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR}) 449set(LWS_LIBRARY_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR}) 450set(LWS_LIBRARY_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH_NUMBER}) 451set(LWS_LIBRARY_VERSION_PATCH_ELABORATED ${CPACK_PACKAGE_VERSION_PATCH}) 452 453if (NOT CMAKE_MODULE_PATH) 454 set(CMAKE_MODULE_PATH "") 455endif() 456set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") 457 458 459if (CMAKE_TOOLCHAIN_FILE) 460 message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'") 461endif() 462 463if (NOT LIB_SUFFIX) 464 set(LIB_SUFFIX "") 465endif() 466 467if (WIN32) 468 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/win32port/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc @ONLY) 469 set(RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc) 470endif() 471 472include_directories(include) 473 474# Allow the user to override installation directories. 475set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") 476set(LWS_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") 477set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") 478set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files") 479 480# if you gave LWS_WITH_MINIZ, point to MINIZ here if not found 481# automatically 482 483set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib/miniz library") 484set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib/miniz include directory") 485set(LWS_SQLITE3_LIBRARIES CACHE PATH "Path to the sqlite3 library") 486set(LWS_SQLITE3_INCLUDE_DIRS CACHE PATH "Path to the sqlite3 include directory") 487set(LWS_LIBMOUNT_INCLUDE_DIRS CACHE PATH "Path to the libmount include directory") 488set(LWS_LIBMOUNT_LIBRARIES CACHE PATH "Path to the libmount library") 489# on unix, these are in the toolchain. On win32 you have to put them somewhere 490# yourself and point to them here 491set(LWS_EXT_PTHREAD_INCLUDE_DIR CACHE PATH "Path to an external pthreads include directory") 492set(LWS_EXT_PTHREAD_LIBRARIES CACHE PATH "Path to an external pthreads library") 493 494 495if (LWS_WITH_HTTP_STREAM_COMPRESSION) 496 set(LWS_WITH_ZLIB 1) 497endif() 498 499if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB) 500 if ("${LWS_ZLIB_LIBRARIES}" STREQUAL "" OR "${LWS_ZLIB_INCLUDE_DIRS}" STREQUAL "") 501 else() 502 set(ZLIB_LIBRARIES ${LWS_ZLIB_LIBRARIES}) 503 set(ZLIB_INCLUDE_DIRS ${LWS_ZLIB_INCLUDE_DIRS}) 504 set(ZLIB_FOUND 1) 505 endif() 506endif() 507 508 509if (LWS_WITH_SQLITE3) 510 if ("${LWS_SQLITE3_LIBRARIES}" STREQUAL "" OR "${LWS_SQLITE3_INCLUDE_DIRS}" STREQUAL "") 511 else() 512 set(SQLITE3_LIBRARIES ${LWS_SQLITE3_LIBRARIES}) 513 set(SQLITE3_INCLUDE_DIRS ${LWS_SQLITE3_INCLUDE_DIRS}) 514 set(SQLITE3_FOUND 1) 515 endif() 516endif() 517 518include_directories("${PROJECT_BINARY_DIR}") 519 520# Check for different inline keyword versions. 521foreach(KEYWORD "inline" "__inline__" "__inline") 522 set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}") 523 CHECK_C_SOURCE_COMPILES( 524 " 525 #include <stdio.h> 526 static KEYWORD void a() {} 527 int main(int argc, char **argv) { a(); return 0; } 528 " LWS_HAVE_${KEYWORD}) 529endforeach() 530 531if (NOT LWS_HAVE_inline) 532 if (LWS_HAVE___inline__) 533 set(inline __inline__) 534 elseif(LWS_HAVE___inline) 535 set(inline __inline) 536 endif() 537endif() 538 539# Put the libraries and binaries that get built into directories at the 540# top of the build tree rather than in hard-to-find leaf directories. 541SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") 542SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") 543SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") 544 545SET(LWS_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}") 546 547# Put absolute path of dynamic libraries into the object code. Some 548# architectures, notably Mac OS X, need this. 549SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}") 550 551if (LWS_WITHOUT_BUILTIN_SHA1) 552 set(LWS_SHA1_USE_OPENSSL_NAME 1) 553endif() 554 555CHECK_C_SOURCE_COMPILES( 556 "#include <malloc.h> 557 int main(int argc, char **argv) { return malloc_trim(0); } 558 " LWS_HAVE_MALLOC_TRIM) 559CHECK_C_SOURCE_COMPILES( 560 "#include <malloc.h> 561 int main(int argc, char **argv) { return (int)malloc_usable_size((void *)0); } 562 " LWS_HAVE_MALLOC_USABLE_SIZE) 563 564CHECK_FUNCTION_EXISTS(fork LWS_HAVE_FORK) 565CHECK_FUNCTION_EXISTS(getenv LWS_HAVE_GETENV) 566CHECK_FUNCTION_EXISTS(malloc LWS_HAVE_MALLOC) 567CHECK_FUNCTION_EXISTS(memset LWS_HAVE_MEMSET) 568CHECK_FUNCTION_EXISTS(realloc LWS_HAVE_REALLOC) 569CHECK_FUNCTION_EXISTS(socket LWS_HAVE_SOCKET) 570CHECK_FUNCTION_EXISTS(strerror LWS_HAVE_STRERROR) 571CHECK_FUNCTION_EXISTS(vfork LWS_HAVE_VFORK) 572CHECK_FUNCTION_EXISTS(execvpe LWS_HAVE_EXECVPE) 573CHECK_FUNCTION_EXISTS(getifaddrs LWS_HAVE_GETIFADDRS) 574CHECK_FUNCTION_EXISTS(snprintf LWS_HAVE_SNPRINTF) 575CHECK_FUNCTION_EXISTS(_snprintf LWS_HAVE__SNPRINTF) 576CHECK_FUNCTION_EXISTS(_vsnprintf LWS_HAVE__VSNPRINTF) 577CHECK_FUNCTION_EXISTS(getloadavg LWS_HAVE_GETLOADAVG) 578CHECK_FUNCTION_EXISTS(atoll LWS_HAVE_ATOLL) 579CHECK_FUNCTION_EXISTS(_atoi64 LWS_HAVE__ATOI64) 580CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64) 581CHECK_FUNCTION_EXISTS(clock_gettime LWS_HAVE_CLOCK_GETTIME) 582CHECK_FUNCTION_EXISTS(localtime_r LWS_HAVE_LOCALTIME_R) 583CHECK_FUNCTION_EXISTS(gmtime_r LWS_HAVE_GMTIME_R) 584CHECK_FUNCTION_EXISTS(ctime_r LWS_HAVE_CTIME_R) 585CHECK_FUNCTION_EXISTS(getgrgid_r LWS_HAVE_GETGRGID_R) 586CHECK_FUNCTION_EXISTS(getgrnam_r LWS_HAVE_GETGRNAM_R) 587CHECK_FUNCTION_EXISTS(getpwuid_r LWS_HAVE_GETPWUID_R) 588CHECK_FUNCTION_EXISTS(getpwnam_r LWS_HAVE_GETPWNAM_R) 589CHECK_FUNCTION_EXISTS(timegm LWS_HAVE_TIMEGM) 590 591if(CMAKE_SYSTEM_NAME MATCHES "Darwin") 592 if(CMAKE_OSX_DEPLOYMENT_TARGET LESS "10.12") 593 message("No clock_gettime found on macOS ${CMAKE_OSX_DEPLOYMENT_TARGET}. Disabling LWS_HAVE_CLOCK_GETTIME.") 594 set(LWS_HAVE_CLOCK_GETTIME 0) 595 endif() 596endif() 597 598if (NOT LWS_HAVE_GETIFADDRS) 599 if (LWS_WITHOUT_BUILTIN_GETIFADDRS) 600 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.") 601 endif() 602 set(LWS_BUILTIN_GETIFADDRS 1) 603endif() 604 605if (LWS_EXT_PTHREAD_INCLUDE_DIR) 606 set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_EXT_PTHREAD_INCLUDE_DIR}) 607 include_directories(${LWS_EXT_PTHREAD_INCLUDE_DIR}) 608 609 list(APPEND LIB_LIST_AT_END ${LWS_EXT_PTHREAD_LIBRARIES}) 610 set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} " -DHAVE_STRUCT_TIMESPEC=1") 611endif() 612 613# 614# add libs here that need to be at the end of the link order 615# 616 617if (LWS_EXT_PTHREAD_INCLUDE_DIR) 618 list(APPEND LIB_LIST_AT_END ${LWS_EXT_PTHREAD_LIBRARIES}) 619endif() 620 621if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB) 622 list(APPEND LIB_LIST_AT_END "${ZLIB_LIBRARIES}") 623endif() 624 625if (LWS_WITH_PLUGINS_API AND UNIX AND CMAKE_DL_LIBS AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX")) 626 list(APPEND LIB_LIST_AT_END ${CMAKE_DL_LIBS}) 627endif() 628 629 630CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H) 631CHECK_INCLUDE_FILE(memory.h LWS_HAVE_MEMORY_H) 632CHECK_INCLUDE_FILE(netinet/in.h LWS_HAVE_NETINET_IN_H) 633CHECK_INCLUDE_FILE(stdint.h LWS_HAVE_STDINT_H) 634CHECK_INCLUDE_FILE(stdlib.h LWS_HAVE_STDLIB_H) 635CHECK_INCLUDE_FILE(strings.h LWS_HAVE_STRINGS_H) 636CHECK_INCLUDE_FILE(string.h LWS_HAVE_STRING_H) 637CHECK_INCLUDE_FILE(sys/prctl.h LWS_HAVE_SYS_PRCTL_H) 638CHECK_INCLUDE_FILE(sys/socket.h LWS_HAVE_SYS_SOCKET_H) 639CHECK_INCLUDE_FILE(sys/sockio.h LWS_HAVE_SYS_SOCKIO_H) 640CHECK_INCLUDE_FILE(sys/stat.h LWS_HAVE_SYS_STAT_H) 641CHECK_INCLUDE_FILE(sys/types.h LWS_HAVE_SYS_TYPES_H) 642CHECK_INCLUDE_FILE(unistd.h LWS_HAVE_UNISTD_H) 643CHECK_INCLUDE_FILE(vfork.h LWS_HAVE_VFORK_H) 644CHECK_INCLUDE_FILE(sys/capability.h LWS_HAVE_SYS_CAPABILITY_H) 645CHECK_INCLUDE_FILE(malloc.h LWS_HAVE_MALLOC_H) 646CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H) 647CHECK_INCLUDE_FILE(inttypes.h LWS_HAVE_INTTYPES_H) 648CHECK_INCLUDE_FILE(sys/resource.h LWS_HAVE_SYS_RESOURCE_H) 649 650if (WIN32 OR MSVC) 651 CHECK_C_SOURCE_COMPILES("#include <winsock2.h> 652 #include <afunix.h> 653 int main() { return 0; }" LWS_HAVE_WIN32_AFUNIX_H) 654 655 if (LWS_UNIX_SOCK AND NOT LWS_HAVE_WIN32_AFUNIX_H) 656 message("No afunix.h found. Disabling LWS_UNIX_SOCK.") 657 set(LWS_WITH_UNIX_SOCK OFF) 658 endif() 659endif() 660 661CHECK_LIBRARY_EXISTS(cap cap_set_flag "" LWS_HAVE_LIBCAP) 662 663 664if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB) 665 if (LWS_WITH_MINIZ) 666 CHECK_INCLUDE_FILE(miniz.h LWS_HAVE_ZLIB_H) 667 else() 668 CHECK_INCLUDE_FILE(zlib.h LWS_HAVE_ZLIB_H) 669 endif() 670endif() 671 672CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h" STDC_HEADERS) 673 674if (NOT CMAKE_REQUIRED_FLAGS) 675 set(CMAKE_REQUIRED_FLAGS "") 676endif() 677if (NOT CMAKE_REQUIRED_INCLUDES) 678 set(CMAKE_REQUIRED_INCLUDES "") 679endif() 680if (NOT CMAKE_REQUIRED_LIBRARIES) 681 set(CMAKE_REQUIRED_LIBRARIES "") 682endif() 683 684CHECK_C_SOURCE_COMPILES("#include <stdint.h> 685 int main(void) { 686 intptr_t test = 1; 687 return 0; 688 }" LWS_HAS_INTPTR_T) 689 690if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR 691 (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) 692 set(COMPILER_IS_CLANG ON) 693endif() 694 695if (LWS_HAVE_PTHREAD_H AND NOT LWS_PLAT_FREERTOS) 696 CHECK_C_SOURCE_COMPILES(" 697 #ifndef _GNU_SOURCE 698 #define _GNU_SOURCE 699 #endif 700 #include <pthread.h> 701 int main(void) { 702 #ifdef __PTW32_H 703 pthread_t th = {0,0}; 704 #else 705 pthread_t th = 0; 706 #endif 707 pthread_setname_np(th, NULL); 708 return 0; 709 }" LWS_HAS_PTHREAD_SETNAME_NP) 710endif() 711 712CHECK_C_SOURCE_COMPILES("#include <stddef.h> 713 #include <getopt.h> 714 int main(void) { 715 void *p = (void *)getopt_long; 716 return p != NULL; 717 }" LWS_HAS_GETOPT_LONG) 718 719CHECK_C_SOURCE_COMPILES("#include <linux/rtnetlink.h> 720 int main(void) { 721 int test = RTA_PREF; 722 return 0; 723 }" LWS_HAVE_RTA_PREF) 724 725CHECK_C_SOURCE_COMPILES("#include <sys/types.h> 726 int main(void) { 727 suseconds_t x = 0; 728 return (int)x; 729 }" LWS_HAVE_SUSECONDS_T) 730 731if (NOT PID_T_SIZE) 732 set(pid_t int) 733endif() 734 735if (NOT SIZE_T_SIZE) 736 set(size_t "unsigned int") 737endif() 738 739if (NOT LWS_HAVE_MALLOC) 740 set(malloc rpl_malloc) 741endif() 742 743if (NOT LWS_HAVE_REALLOC) 744 set(realloc rpl_realloc) 745endif() 746 747 748 749 750if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG) 751 include (CheckCCompilerFlag) 752 CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY) 753 if (LWS_WITH_FANALYZER) 754 CHECK_C_COMPILER_FLAG(-fanalyzer LWS_HAVE_FANALYZER) 755 endif() 756 if (LWS_HAVE_VISIBILITY) 757 set(VISIBILITY_FLAG -fvisibility=hidden) 758 endif() 759 if (LWS_WITH_GCOV) 760 set (GCOV_FLAGS "-fprofile-arcs -ftest-coverage ") 761 else() 762 set(GCOV_FLAGS "") 763 endif() 764 765 if (LWS_WITH_ASAN) 766 set (ASAN_FLAGS "-fsanitize=address -fsanitize=undefined -fsanitize-address-use-after-scope -fsanitize-undefined-trap-on-error") 767 if (NOT COMPILER_IS_CLANG) 768 set (ASAN_FLAGS "${ASAN_FLAGS} -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak") 769 endif() 770 message("Enabling ASAN") 771 else() 772 set(ASAN_FLAGS "") 773 endif() 774 775 check_c_compiler_flag("-Wignored-qualifiers" LWS_GCC_HAS_IGNORED_QUALIFIERS) 776 check_c_compiler_flag("-Wtype-limits" LWS_GCC_HAS_TYPE_LIMITS) 777 check_c_compiler_flag("-Wno-deprecated-declarations" LWS_GCC_HAS_NO_DEPRECATED_DECLARATIONS) 778 779 if (LWS_GCC_HAS_IGNORED_QUALIFIERS) 780 set(CMAKE_C_FLAGS "-Wignored-qualifiers ${CMAKE_C_FLAGS}" ) 781 endif() 782 783 if (LWS_GCC_HAS_TYPE_LIMITS) 784 set(CMAKE_C_FLAGS "-Wtype-limits ${CMAKE_C_FLAGS}" ) 785 endif() 786 787 if (LWS_WITH_FANALYZER AND LWS_HAVE_FANALYZER) 788 set(CMAKE_C_FLAGS "-fanalyzer ${CMAKE_C_FLAGS}" ) 789 endif() 790 791 if (CMAKE_COMPILER_IS_CLANG OR CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4) 792 set(CMAKE_C_FLAGS "-Wuninitialized ${CMAKE_C_FLAGS}") 793 endif() 794 795 # always warn all and generate debug info 796 if (UNIX AND NOT LWS_PLAT_FREERTOS) 797 set(CMAKE_C_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wconversion -Wsign-compare -Wstrict-aliasing ${VISIBILITY_FLAG} -Wundef ${GCOV_FLAGS} ${CMAKE_C_FLAGS} ${ASAN_FLAGS}" ) 798 else() 799 set(CMAKE_C_FLAGS "-Wall -Wsign-compare ${VISIBILITY_FLAG} ${GCOV_FLAGS} ${CMAKE_C_FLAGS}" ) 800 endif() 801 802 if (PICO_SDK_PATH) 803 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wno-unused-parameter -Wconversion -Wsign-compare -Wstrict-aliasing -Wundef -nolibc") 804 endif() 805 806 if (ESP_PLATFORM AND (CONFIG_IDF_TARGET_ESP32 OR CONFIG_IDF_TARGET_ESP32S2 OR CONFIG_IDF_TARGET_ESP32S3)) 807 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mlongcalls") 808 endif() 809 810 if ("${DISABLE_WERROR}" STREQUAL "OFF") 811 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror") 812 endif() 813 814 if (LWS_SUPPRESS_DEPRECATED_API_WARNINGS) 815 set(CMAKE_C_FLAGS "-Wno-deprecated ${CMAKE_C_FLAGS}") 816 if (LWS_GCC_HAS_NO_DEPRECATED_DECLARATIONS) 817 set(CMAKE_C_FLAGS "-Wno-deprecated-declarations ${CMAKE_C_FLAGS}") 818 endif() 819 endif() 820endif () 821 822if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS) 823 if (UNIX AND LWS_HAVE_PTHREAD_H AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX")) 824 # jeez clang understands -pthread but dies if he sees it at link time! 825 # http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang 826 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" ) 827 list(APPEND LIB_LIST_AT_END -lpthread) 828 endif() 829endif() 830 831if (COMPILER_IS_CLANG) 832 833 # otherwise osx blows a bunch of openssl deprecated api errors 834 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" ) 835 if (UNIX AND LWS_HAVE_PTHREAD_H) 836 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -Wno-error=unused-command-line-argument" ) 837 endif() 838endif() 839 840if (WINCE) 841 list(APPEND LIB_LIST_AT_END ws2.lib) 842elseif (WIN32) 843 list(APPEND LIB_LIST_AT_END ws2_32.lib userenv.lib psapi.lib iphlpapi.lib crypt32.lib) 844endif() 845 846if (MSVC) 847 # Turn off pointless microsoft security warnings. 848 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) 849 # Fail the build if any warnings 850 add_compile_options(/W3 /WX) 851 # Unbreak MSVC broken preprocessor __VA_ARGS__ behaviour 852 add_compile_options(/Zc:preprocessor /experimental:preprocessor /wd5105) 853endif(MSVC) 854 855if (MINGW) 856 set(LWS_MINGW_SUPPORT 1) 857 set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}") 858 add_definitions(-DWINVER=0x0601 -D_WIN32_WINNT=0x0601) 859endif() 860 861if (HDR_PRIVATE) 862 source_group("Headers Private" FILES ${HDR_PRIVATE}) 863endif() 864if (HDR_PUBLIC) 865 source_group("Headers Public" FILES ${HDR_PUBLIC}) 866endif() 867if (SOURCES) 868 source_group("Sources" FILES ${SOURCES}) 869endif() 870if (RESOURCES) 871 source_group("Resources" FILES ${RESOURCES}) 872endif() 873 874 875# 876# ZLIB (needed for deflate extension and if LWS_WITH_HTTP_STREAM_COMPRESSION) 877# 878if (LWS_WITH_ZLIB) 879 if (NOT ZLIB_FOUND) 880 if (LWS_WITH_MINIZ) 881 find_package(Miniz REQUIRED) 882 set(ZLIB_INCLUDE_DIRS ${MINIZ_INCLUDE_DIR}) 883 set(ZLIB_LIBRARIES ${MINIZ_LIBRARIES}) 884 else() 885 find_package(ZLIB REQUIRED) 886 endif() 887 endif() 888 message("zlib/miniz include dirs: ${ZLIB_INCLUDE_DIRS}") 889 message("zlib/miniz libraries: ${ZLIB_LIBRARIES}") 890 include_directories(${ZLIB_INCLUDE_DIRS}) 891 # done later at end of link list 892 # list(APPEND LIB_LIST ${ZLIB_LIBRARIES}) 893 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${ZLIB_LIBRARIES}) 894 list(APPEND LIB_LIST_AT_END ${ZLIB_LIBRARIES}) 895endif() 896 897 898if (LWS_WITH_FSMOUNT AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 899 if (NOT LWS_LIBMOUNT_INCLUDE_DIRS STREQUAL "") 900 include_directories(${LWS_LIBMOUNT_INCLUDE_DIRS}) 901 message("libmount include dir: ${LWS_LIBMOUNT_INCLUDE_DIRS}") 902 endif() 903 if (NOT LWS_LIBMOUNT_LIBRARIES STREQUAL "") 904 message("libmount libraries: ${LWS_LIBMOUNT_LIBRARIES}") 905 list(APPEND LIB_LIST ${LWS_LIBMOUNT_LIBRARIES}) 906 else() 907 list(APPEND LIB_LIST mount) 908 endif() 909endif() 910 911 912if (LWS_WITH_SQLITE3) 913 if (NOT SQLITE3_FOUND) 914 find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h) 915 find_library(SQLITE3_LIBRARIES NAMES sqlite3) 916 if(SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES) 917 set(SQLITE3_FOUND 1) 918 endif() 919 endif() 920 message("sqlite3 include dir: ${SQLITE3_INCLUDE_DIRS}") 921 message("sqlite3 libraries: ${SQLITE3_LIBRARIES}") 922 include_directories("${SQLITE3_INCLUDE_DIRS}") 923 list(APPEND LIB_LIST ${SQLITE3_LIBRARIES}) 924endif() 925 926 927if (LWS_WITH_HUBBUB) 928 find_library(LIBHUBBUB_LIBRARIES NAMES hubbub) 929 list(APPEND LIB_LIST ${LIBHUBBUB_LIBRARIES} ) 930endif() 931 932if (LWS_HAVE_LIBCAP) 933 find_library(LIBCAP_LIBRARIES NAMES cap) 934 list(APPEND LIB_LIST ${LIBCAP_LIBRARIES} ) 935endif() 936 937if (LWS_WITH_PLUGINS_BUILTIN) 938 add_subdirectory(plugins) 939endif() 940 941 942# 943# Append the "at end" pieces to the lib list 944# 945list(APPEND LIB_LIST ${LIB_LIST_AT_END}) 946 947# 948# Second-level CMakeLists 949# 950 951include_directories("${PROJECT_SOURCE_DIR}/lib") 952 953add_subdirectory(lib) 954 955 956if(WIN32 AND NOT CYGWIN) 957 set(DEF_INSTALL_CMAKE_DIR cmake) 958else() 959 set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets) 960endif() 961 962configure_file(${PROJECT_SOURCE_DIR}/cmake/LwsCheckRequirements.cmake 963 ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LwsCheckRequirements.cmake 964 @ONLY) 965 966configure_file(${PROJECT_SOURCE_DIR}/cmake/LwsCheckRequirements.cmake 967 ${PROJECT_BINARY_DIR}/LwsCheckRequirements.cmake 968 @ONLY) 969 970# Generate version info for both build-tree and install-tree. 971configure_file(${PROJECT_SOURCE_DIR}/cmake/libwebsockets-config-version.cmake.in 972 ${PROJECT_BINARY_DIR}/libwebsockets-config-version.cmake 973 @ONLY) 974 975# Generate the config file for the build-tree. 976set(LWS__INCLUDE_DIRS 977 "${PROJECT_SOURCE_DIR}/lib" 978 "${PROJECT_BINARY_DIR}") 979set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories") 980configure_file(${PROJECT_SOURCE_DIR}/cmake/libwebsockets-config.cmake.in 981 ${PROJECT_BINARY_DIR}/libwebsockets-config.cmake 982 @ONLY) 983set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") 984 985# Export targets (This is used for other CMake projects to easily find the libraries and include files). 986if (LWS_WITH_EXPORT_LWSTARGETS) 987 export(TARGETS ${LWS_LIBRARIES} 988 FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake") 989endif() 990 991 992 993set(libwebsockets_DIR ${PROJECT_BINARY_DIR}) 994set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") 995message("DIR ${libwebsockets_DIR} CMP ${CMAKE_MODULE_PATH}") 996 997if (LWS_WITH_MINIMAL_EXAMPLES) 998 add_subdirectory(minimal-examples) 999endif() 1000 1001if (NOT LWS_WITHOUT_TESTAPPS) 1002 add_subdirectory(test-apps) 1003endif() 1004 1005if (NOT LWS_WITH_PLUGINS_BUILTIN) 1006add_subdirectory(plugins) 1007endif() 1008add_subdirectory(lwsws) 1009 1010# Generate the lws_config.h that includes all the public compilation settings. 1011configure_file( 1012 "${PROJECT_SOURCE_DIR}/cmake/lws_config.h.in" 1013 "${PROJECT_BINARY_DIR}/lws_config.h") 1014 1015add_custom_command( 1016 OUTPUT ${PROJECT_BINARY_DIR}/include/lws_config.h 1017 ${PROJECT_BINARY_DIR}/include/libwebsockets 1018 ${PROJECT_BINARY_DIR}/include/libwebsockets.h 1019 COMMENT "Creating build include dir" 1020 COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets.h 1021 ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets.h 1022 COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets/ 1023 ${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets 1024 COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lws_config.h 1025 ${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h 1026 MAIN_DEPENDENCY ${PROJECT_BINARY_DIR}/lws_config.h 1027) 1028 1029add_custom_target(GENHDR DEPENDS ${PROJECT_BINARY_DIR}/include/lws_config.h) 1030 1031file(GLOB HDR_PUBLIC1 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/libwebsockets/*.h) 1032file(GLOB HDR_PUBLIC2 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/libwebsockets.h) 1033file(GLOB HDR_PUBLIC3 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h) 1034list(APPEND HDR_PUBLIC ${HDR_PUBLIC1} ${HDR_PUBLIC2} ${HDR_PUBLIC3}) 1035 1036set_source_files_properties(${HDR_PUBLIC} PROPERTIES GENERATED 1) 1037 1038if (LWS_WITH_STATIC) 1039 add_dependencies(websockets GENHDR) 1040endif() 1041if (LWS_WITH_SHARED) 1042 add_dependencies(websockets_shared GENHDR) 1043endif() 1044 1045 1046 1047# 1048# 1049# Installation preparations. 1050# 1051 1052export(PACKAGE libwebsockets) 1053 1054install(DIRECTORY include/libwebsockets 1055 DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev) 1056install(FILES ${PROJECT_BINARY_DIR}/include/libwebsockets.h ${PROJECT_BINARY_DIR}/include/lws_config.h 1057 DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev) 1058 1059# Generate the config file for the installation tree. 1060get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE) 1061get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE) 1062file(RELATIVE_PATH 1063 REL_INCLUDE_DIR 1064 "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}" 1065 "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir. 1066 1067if (DEFINED REL_INCLUDE_DIR) 1068 set(LWS__INCLUDE_DIRS "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}") 1069endif() 1070if (DEFINED OPENSSL_INCLUDE_DIRS) 1071 set(LWS__INCLUDE_DIRS "${LWS__INCLUDE_DIRS};${OPENSSL_INCLUDE_DIRS}") 1072endif() 1073 1074configure_file(${PROJECT_SOURCE_DIR}/cmake/libwebsockets-config.cmake.in 1075 ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libwebsockets-config.cmake 1076 @ONLY) 1077 1078set_target_properties(${LWS_LIBRARIES} 1079 PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}") 1080 1081# Install the LibwebsocketsConfig.cmake and LibwebsocketsConfigVersion.cmake 1082install(FILES 1083 "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libwebsockets-config.cmake" 1084 "${PROJECT_BINARY_DIR}/libwebsockets-config-version.cmake" 1085 "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LwsCheckRequirements.cmake" 1086 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev) 1087 1088# Install exports for the install-tree. 1089if (LWS_WITH_EXPORT_LWSTARGETS) 1090 install(EXPORT LibwebsocketsTargets 1091 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev) 1092endif() 1093 1094# build subdir is not part of sources 1095set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) "/.git/" "/build/" "\\\\.tgz$" "\\\\.tar\\\\.gz$") 1096 1097# Most people are more used to "make dist" compared to "make package_source" 1098add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source) 1099 1100 1101 1102# This must always be last! 1103include(CPack) 1104