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