2020-05-22 16:47:40 +01:00
#
# libwebsockets - small server side websockets and web server implementation
#
# Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
2020-09-28 07:34:55 +01:00
cmake_minimum_required(VERSION 2.8.12)
2020-05-22 16:47:40 +01:00
include(CheckFunctionExists)
include(CheckSymbolExists)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckTypeSize)
include(CheckCSourceCompiles)
2013-02-01 14:52:53 +01:00
2020-06-03 17:14:03 +01:00
if (POLICY CMP0048)
2020-04-21 01:33:33 +02:00
cmake_policy(SET CMP0048 NEW)
endif()
2020-06-03 17:14:03 +01:00
#if (POLICY CMP0024)
# cmake_policy(SET CMP0024 NEW)
#endif()
if (POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
2020-05-22 16:47:40 +01:00
2017-11-10 08:56:44 +08:00
# General Advice
#
# For selecting between DEBUG / RELEASE, use -DCMAKE_BUILD_TYPE=DEBUG or =RELEASE
# debug builds include source level debug info and extra logging
2017-10-21 09:03:42 +08:00
set(LWS_WITH_BUNDLED_ZLIB_DEFAULT OFF)
if(WIN32)
set(LWS_WITH_BUNDLED_ZLIB_DEFAULT ON)
endif()
2018-04-27 15:20:56 +08:00
2018-04-25 08:42:18 +08:00
set(LWS_ROLE_RAW 1)
2018-04-29 10:44:36 +08:00
set(LWS_WITH_POLL 1)
2017-10-21 09:03:42 +08:00
2020-05-22 16:47:40 +01:00
if (ESP_PLATFORM)
2020-05-14 21:28:48 +01:00
set(LWS_ESP_PLATFORM 1)
2020-12-06 17:29:36 +00:00
#set(CMAKE_TOOLCHAIN_FILE contrib/cross-esp32.cmake)
2020-05-14 21:28:48 +01:00
set(LWIP_PROVIDE_ERRNO 1)
endif()
2020-05-22 16:47:40 +01:00
2020-01-20 18:13:53 +00:00
# it's at this point any toolchain file is brought in
2020-09-28 10:13:39 +01:00
project(libwebsockets C CXX)
2020-05-01 05:45:18 +01:00
include(CTest)
2020-01-20 18:13:53 +00:00
2020-12-06 17:29:36 +00:00
if (ESP_PLATFORM)
include_directories(
2021-08-26 12:31:06 +01:00
$ENV{IDF_PATH}/components/esp_hw_support/include/soc/
$ENV{IDF_PATH}/components/freertos/include/
$ENV{IDF_PATH}/components/xtensa/${CONFIG_IDF_TARGET}/include/
$ENV{IDF_PATH}/components/freertos/include/esp_additions
$ENV{IDF_PATH}/components/hal/include
$ENV{IDF_PATH}/components/soc/${CONFIG_IDF_TARGET}/include/
$ENV{IDF_PATH}/components/soc/include/
$ENV{IDF_PATH}/components/esp_hw_support/include
$ENV{IDF_PATH}/components/hal/${CONFIG_IDF_TARGET}/include/
)
if (CONFIG_IDF_TARGET_ARCH_RISCV)
include_directories(
$ENV{IDF_PATH}/components/freertos/port/riscv/include
$ENV{IDF_PATH}/components/riscv/include)
else()
include_directories(
$ENV{IDF_PATH}/components/freertos/port/xtensa/include
$ENV{IDF_PATH}/components/xtensa/include)
endif()
2020-12-06 17:29:36 +00:00
endif()
2018-01-27 08:01:33 +08:00
#
# Select features recommended for PC distro packaging
#
option(LWS_WITH_DISTRO_RECOMMENDED "Enable features recommended for distro packaging" OFF)
2018-11-12 15:24:42 +08:00
option(LWS_FOR_GITOHASHI "Enable features recommended for use with gitohashi" OFF)
2018-01-27 08:01:33 +08:00
2020-05-26 16:35:16 +02:00
#
# Compiler features
#
option(DISABLE_WERROR "Avoid treating compiler warnings as fatal errors" OFF)
2017-10-21 09:03:42 +08:00
#
# Major individual features
#
2019-01-13 06:58:21 +08:00
option(LWS_WITH_NETWORK "Compile with network-related code" ON)
2018-04-27 15:20:56 +08:00
option(LWS_ROLE_H1 "Compile with support for http/1 (needed for ws)" ON)
2018-04-25 08:42:18 +08:00
option(LWS_ROLE_WS "Compile with support for websockets" ON)
2020-02-25 13:28:25 +00:00
option(LWS_ROLE_MQTT "Build with support for MQTT client" OFF)
2018-10-02 10:50:24 +08:00
option(LWS_ROLE_DBUS "Compile with support for DBUS" OFF)
2018-11-29 08:29:48 +08:00
option(LWS_ROLE_RAW_PROXY "Raw packet proxy" OFF)
2020-02-28 15:50:15 +00:00
option(LWS_ROLE_RAW_FILE "Compile with support for raw files" ON)
2018-11-12 15:24:42 +08:00
option(LWS_WITH_HTTP2 "Compile with server support for HTTP/2" ON)
2017-10-21 09:03:42 +08:00
option(LWS_WITH_LWSWS "Libwebsockets Webserver" OFF)
option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out/err) APIs" OFF)
option(LWS_IPV6 "Compile with support for ipv6" OFF)
2020-05-24 13:57:21 +01:00
option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket if OS supports it" ON)
2020-08-30 07:39:27 +01:00
option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions (implies LWS_WITH_PLUGINS_API)" OFF)
2021-01-31 05:50:12 +00:00
option(LWS_WITH_PLUGINS_BUILTIN "Build the plugin protocols directly into lws library" OFF)
2019-08-17 21:20:55 +01:00
option(LWS_WITH_HTTP_PROXY "Support for active HTTP proxying" OFF)
2017-11-14 11:25:54 +08:00
option(LWS_WITH_ZIP_FOPS "Support serving pre-zipped files" OFF)
2017-10-21 09:03:42 +08:00
option(LWS_WITH_SOCKS5 "Allow use of SOCKS5 proxy on client connections" OFF)
option(LWS_WITH_PEER_LIMITS "Track peers and restrict resources a single peer can allocate" OFF)
option(LWS_WITH_ACCESS_LOG "Support generating Apache-compatible access logs" OFF)
2017-11-14 11:25:54 +08:00
option(LWS_WITH_RANGES "Support http ranges (RFC7233)" OFF)
2018-11-12 15:24:42 +08:00
option(LWS_WITH_THREADPOOL "Managed worker thread pool support (relies on pthreads)" OFF)
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written. The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
option(LWS_WITH_HTTP_STREAM_COMPRESSION "Support HTTP stream compression" OFF)
option(LWS_WITH_HTTP_BROTLI "Also offer brotli http stream compression (requires LWS_WITH_HTTP_STREAM_COMPRESSION)" OFF)
2017-10-21 06:36:35 +08:00
option(LWS_WITH_ACME "Enable support for ACME automatic cert acquisition + maintenance (letsencrypt etc)" OFF)
2018-09-04 08:06:46 +08:00
option(LWS_WITH_HUBBUB "Enable libhubbub rewriting support" OFF)
2019-10-14 16:46:48 +01:00
option(LWS_WITH_ALSA "Enable alsa audio example" OFF)
2020-02-07 11:39:32 +00:00
option(LWS_WITH_GTK "Enable gtk example" OFF)
2018-11-12 15:24:42 +08:00
option(LWS_WITH_FTS "Full Text Search support" OFF)
2019-09-22 07:25:58 -07:00
option(LWS_WITH_SYS_ASYNC_DNS "Nonblocking internal IPv4 + IPv6 DNS resolver" OFF)
option(LWS_WITH_SYS_NTPCLIENT "Build in tiny ntpclient good for tls date validation and run via lws_system" OFF)
2019-09-27 14:32:59 -07:00
option(LWS_WITH_SYS_DHCP_CLIENT "Build in tiny DHCP client" OFF)
2020-02-28 09:29:25 +00:00
option(LWS_WITH_HTTP_BASIC_AUTH "Support Basic Auth" ON)
2020-02-28 10:31:04 +00:00
option(LWS_WITH_HTTP_UNCOMMON_HEADERS "Include less common http header support" ON)
2020-06-23 13:19:30 +01:00
option(LWS_WITH_SYS_STATE "lws_system state support" ON)
2020-06-24 20:15:46 +01:00
option(LWS_WITH_SYS_SMD "Lws System Message Distribution" ON)
2021-02-17 10:31:22 +00:00
option(LWS_WITH_SYS_FAULT_INJECTION "Enable fault injection support" OFF)
2021-01-06 15:08:22 +00:00
option(LWS_WITH_SYS_METRICS "Lws Metrics API" OFF)
2020-02-28 09:29:25 +00:00
2020-02-29 12:37:24 +00:00
#
# Secure Streams
#
option(LWS_WITH_SECURE_STREAMS "Secure Streams protocol-agnostic API" OFF)
2020-09-28 10:13:39 +01:00
option(LWS_WITH_SECURE_STREAMS_CPP "Secure Streams C++ classes" OFF)
2020-02-29 12:37:24 +00:00
option(LWS_WITH_SECURE_STREAMS_PROXY_API "Secure Streams support to work across processes" OFF)
option(LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM "Auth support for api.amazon.com" OFF)
2020-03-26 06:48:34 +00:00
option(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY "Secure Streams Policy is hardcoded only" OFF)
2020-12-29 16:42:25 -08:00
option(LWS_WITH_SECURE_STREAMS_AUTH_SIGV4 "Secure Streams Auth support for AWS Sigv4" OFF)
2020-02-29 12:37:24 +00:00
2020-05-01 05:45:18 +01:00
#
# CTest options
#
#
# If you build with LWS_WITH_MINIMAL_EXAMPLES, you can use CTest / make test to run
# examples that can give a pass/fail response. By default it runs tests both against
# a local server peer and warmcat.com, if your CI wants to do the tests but does not
# have internet routing, then you can still run a subset of tests with CTest / make
# test that only does local tests by disabling this option.
#
option(LWS_CTEST_INTERNET_AVAILABLE "CTest will performs tests that need the Internet" ON)
2017-10-21 09:03:42 +08:00
#
# TLS library options... all except mbedTLS are basically OpenSSL variants.
#
option(LWS_WITH_SSL "Include SSL support (defaults to OpenSSL or similar, mbedTLS if LWS_WITH_MBEDTLS is set)" ON)
option(LWS_WITH_MBEDTLS "Use mbedTLS (>=2.0) replacement for OpenSSL. When setting this, you also may need to specify LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS" OFF)
option(LWS_WITH_BORINGSSL "Use BoringSSL replacement for OpenSSL" OFF)
option(LWS_WITH_CYASSL "Use CyaSSL replacement for OpenSSL. When setting this, you also need to specify LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS" OFF)
option(LWS_WITH_WOLFSSL "Use wolfSSL replacement for OpenSSL. When setting this, you also need to specify LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS" OFF)
option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of the OS-installed CA root certs" ON)
2021-01-23 20:56:01 +00:00
option(LWS_TLS_LOG_PLAINTEXT_RX "For debugging log the received plaintext as soon as decrypted" OFF)
option(LWS_TLS_LOG_PLAINTEXT_TX "For debugging log the transmitted plaintext just before encryption" OFF)
2021-03-25 08:37:36 +00:00
option(LWS_WITH_TLS_SESSIONS "Enable persistent, resumable TLS sessions" ON)
2021-01-23 20:56:01 +00:00
2017-10-21 09:03:42 +08:00
#
# Event library options (may select multiple, or none for default poll()
#
option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
option(LWS_WITH_LIBUV "Compile with support for libuv" OFF)
option(LWS_WITH_LIBEVENT "Compile with support for libevent" OFF)
2020-02-07 11:39:32 +00:00
option(LWS_WITH_GLIB "Compile with support for glib event loop" OFF)
2021-01-06 14:15:53 +01:00
option(LWS_WITH_SDEVENT "Compile with support for sd-event loop" OFF)
2021-03-15 19:33:37 +00:00
option(LWS_WITH_ULOOP "Compile with support for uloop" OFF)
2020-02-07 11:39:32 +00:00
2020-08-27 15:37:14 +01:00
if (UNIX)
# since v4.1, on unix platforms default is build any event libs as runtime plugins
option(LWS_WITH_EVLIB_PLUGINS "Compile event lib support into runtime-selected plugins" ON)
else()
# otherwise default to linking the event lib(s) to libwebsockets.so
option(LWS_WITH_EVLIB_PLUGINS "Compile event lib support into runtime-selected plugins" OFF)
endif()
2020-06-10 19:17:08 +01:00
#
# LWS Drivers
#
option(LWS_WITH_DRIVERS "With generic drivers for gpio, i2c, display etc" OFF)
2017-10-21 09:03:42 +08:00
#
# Static / Dynamic build options
#
option(LWS_WITH_STATIC "Build the static version of the library" ON)
option(LWS_WITH_SHARED "Build the shared version of the library" ON)
option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF)
option(LWS_STATIC_PIC "Build the static version of the library with position-independent code" OFF)
2021-02-14 06:05:16 +00:00
option(LWS_SUPPRESS_DEPRECATED_API_WARNINGS "Turn off complaints about, eg, openssl deprecated api usage" OFF)
2017-10-21 09:03:42 +08:00
#
# Specific platforms
#
option(LWS_WITH_ESP32 "Build for ESP32" OFF)
option(LWS_PLAT_OPTEE "Build for OPTEE" OFF)
2019-08-18 10:35:43 +01:00
option(LWS_PLAT_FREERTOS "Build for FreeRTOS" OFF)
2019-09-19 06:54:53 +01:00
option(LWS_PLAT_ANDROID "Android flavour of unix platform" OFF)
2019-08-18 10:35:43 +01:00
2017-10-21 09:03:42 +08:00
#
# Client / Server / Test Apps build control
#
option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF)
option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF)
option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF)
option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF)
option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF)
option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
#
# Extensions (permessage-deflate)
#
2017-11-14 11:25:54 +08:00
option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" ON)
2017-10-21 09:03:42 +08:00
#
# Helpers + misc
#
option(LWS_WITHOUT_BUILTIN_GETIFADDRS "Don't use the BSD getifaddrs implementation from libwebsockets if it is missing (this will result in a compilation error) ... The default is to assume that your libc provides it. On some systems such as uclibc it doesn't exist." OFF)
option(LWS_FALLBACK_GETHOSTBYNAME "Also try to do dns resolution using gethostbyname if getaddrinfo fails" OFF)
option(LWS_WITHOUT_BUILTIN_SHA1 "Don't build the lws sha-1 (eg, because openssl will provide it" OFF)
option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON)
option(LWS_SSL_SERVER_WITH_ECDH_CERT "Include SSL server use ECDH certificate" OFF)
2018-08-05 18:18:40 +08:00
option(LWS_WITH_LEJP "With the Lightweight JSON Parser" ON)
2017-10-21 09:03:42 +08:00
option(LWS_WITH_SQLITE3 "Require SQLITE3 support" OFF)
2019-08-17 20:46:53 +01:00
option(LWS_WITH_STRUCT_JSON "Generic struct serialization to and from JSON" OFF)
2019-03-30 22:14:15 +08:00
option(LWS_WITH_STRUCT_SQLITE3 "Generic struct serialization to and from SQLITE3" OFF)
2020-01-02 08:32:23 +00:00
# broken atm
#option(LWS_WITH_SMTP "Provide SMTP support" OFF)
2020-04-08 10:51:50 +01:00
if (LWS_WITH_ESP32)
2019-03-14 08:24:40 +08:00
option(LWS_WITH_DIR "Directory scanning api support" OFF)
2019-03-14 21:22:17 +08:00
option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF)
2019-03-14 08:24:40 +08:00
else()
option(LWS_WITH_DIR "Directory scanning api support" ON)
2019-03-14 21:22:17 +08:00
option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" ON)
2019-03-14 08:24:40 +08:00
endif()
2020-04-22 06:32:15 +01:00
option(LWS_WITH_NO_LOGS "Disable all logging other than _err and _user from being compiled in" OFF)
set(LWS_LOGGING_BITFIELD_SET 0 CACHE STRING "Bitfield describing which log levels to force included into the build")
set(LWS_LOGGING_BITFIELD_CLEAR 0 CACHE STRING "Bitfield describing which log levels to force removed from the build")
2020-02-28 10:31:04 +00:00
option(LWS_LOGS_TIMESTAMP "Timestamp at start of logs" ON)
2021-02-01 10:45:23 +00:00
option(LWS_LOG_TAG_LIFECYCLE "Log tagged object lifecycle as NOTICE" ON)
2017-10-21 09:03:42 +08:00
option(LWS_AVOID_SIGPIPE_IGN "Android 7+ reportedly needs this" OFF)
2018-12-13 20:05:12 +08:00
option(LWS_WITH_JOSE "JSON Web Signature / Encryption / Keys (RFC7515/6/) API" OFF)
option(LWS_WITH_GENCRYPTO "Enable support for Generic Crypto apis independent of TLS backend" OFF)
2017-10-21 09:03:42 +08:00
option(LWS_WITH_SELFTESTS "Selftests run at context creation" OFF)
2017-11-14 11:25:54 +08:00
option(LWS_WITH_GCOV "Build with gcc gcov coverage instrumentation" OFF)
2017-11-20 12:41:29 +01:00
option(LWS_WITH_EXPORT_LWSTARGETS "Export libwebsockets CMake targets. Disable if they conflict with an outer cmake project." ON)
2017-12-10 00:54:06 +01:00
option(LWS_REPRODUCIBLE "Build libwebsockets reproducible. It removes the build user and hostname from the build" ON)
2018-03-17 06:43:12 +08:00
option(LWS_WITH_MINIMAL_EXAMPLES "Also build the normally standalone minimal examples, for QA" OFF)
2018-10-14 06:12:27 +08:00
option(LWS_WITH_LWSAC "lwsac Chunk Allocation api" ON)
2019-02-26 17:18:24 +08:00
option(LWS_WITH_CUSTOM_HEADERS "Store and allow querying custom HTTP headers (H1 only)" ON)
2018-11-12 15:24:42 +08:00
option(LWS_WITH_DISKCACHE "Hashed cache directory with lazy LRU deletion to size limit" OFF)
2018-11-03 14:47:48 +08:00
option(LWS_WITH_ASAN "Build with gcc runtime sanitizer options enabled (needs libasan)" OFF)
2019-07-01 14:54:05 +01:00
option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF)
2019-07-03 19:46:23 +01:00
option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" OFF)
option(LWS_WITH_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_WITH_BUNDLED_ZLIB_DEFAULT})
option(LWS_WITH_MINIZ "Use miniz instead of zlib" OFF)
2020-05-28 12:48:17 +01:00
option(LWS_WITH_DEPRECATED_THINGS "Temporary workaround for deprecated apis" OFF)
2020-09-29 09:29:18 +01:00
option(LWS_WITH_SEQUENCER "lws_seq_t support" OFF)
2019-08-10 09:33:07 +01:00
option(LWS_WITH_EXTERNAL_POLL "Support external POLL integration using callback messages (not recommended)" OFF)
2019-08-11 06:47:19 +01:00
option(LWS_WITH_LWS_DSH "Support lws_dsh_t Disordered Shared Heap" OFF)
2019-08-17 21:20:55 +01:00
option(LWS_CLIENT_HTTP_PROXYING "Support external http proxies for client connections" ON)
2019-08-18 06:29:34 +01:00
option(LWS_WITH_FILE_OPS "Support file operations vfs" ON)
2019-09-30 09:42:38 -07:00
option(LWS_WITH_UDP "Platform supports UDP" ON)
2020-02-12 10:12:39 +00:00
option(LWS_WITH_SPAWN "Spawn subprocesses with piped stdin/out/stderr" OFF)
2020-02-15 10:09:50 +00:00
option(LWS_WITH_FSMOUNT "Overlayfs and fallback mounting apis" OFF)
2020-03-27 18:35:23 +00:00
option(LWS_WITH_FANALYZER "Enable gcc -fanalyzer if compiler supports" OFF)
2020-04-23 15:12:17 +01:00
option(LWS_HTTP_HEADERS_ALL "Override header reduction optimization and include all like older lws versions" OFF)
2020-07-15 10:25:18 +01:00
option(LWS_WITH_SUL_DEBUGGING "Enable zombie lws_sul checking on object deletion" OFF)
2020-08-30 07:39:27 +01:00
option(LWS_WITH_PLUGINS_API "Build generic lws_plugins apis (see LWS_WITH_PLUGINS to also build protocol plugins)" OFF)
2021-03-15 05:20:15 +00:00
option(LWS_WITH_CONMON "Collect introspectable connection latency stats on individual client connections" ON)
2021-04-20 14:58:20 +01:00
option(LWS_WITHOUT_EVENTFD "Force using pipe instead of eventfd" OFF)
2019-09-30 09:42:38 -07:00
2020-10-04 07:28:41 +01:00
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
option(LWS_WITH_NETLINK "Monitor Netlink for Routing Table changes" ON)
else()
set(LWS_WITH_NETLINK 0)
endif()
2021-03-08 10:52:06 +00:00
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
# its openssl has md5 deprecated
set(LWS_SUPPRESS_DEPRECATED_API_WARNINGS 1)
endif()
2020-10-04 07:28:41 +01:00
2019-07-03 19:46:23 +01:00
#
# to use miniz, enable both LWS_WITH_ZLIB and LWS_WITH_MINIZ
2017-10-21 09:03:42 +08:00
#
# End of user settings
#
2020-05-22 16:47:40 +01:00
# sets of sub-options implied by other options
#
ss: static policy: dynamic vhost instantiation
Presently a vh is allocated per trust store at policy parsing-time, this
is no problem on a linux-class device or if you decide you need a dynamic
policy for functionality reasons.
However if you're in a constrained enough situation that the static policy
makes sense, in the case your trust stores do not have 100% duty cycle, ie,
are anyway always in use, the currently-unused vhosts and their x.509 stack
are sitting there taking up heap for no immediate benefit.
This patch modifies behaviour in ..._STATIC_POLICY_ONLY so that vhosts and
associated x.509 tls contexts are not instantiated until a secure stream using
them is created; they are refcounted, and when the last logical secure
stream using a vhost is destroyed, the vhost and its tls context is also
destroyed.
If another ss connection is created that wants to use the trust store, the
vhost and x.509 context is regenerated again as needed.
Currently the refcounting is by ss, it's also possible to move the refcounting
to be by connection. The choice is between the delay to generate the vh
being visisble at logical ss creation-time, or at connection-time. It's anyway
not preferable to have ss instantiated and taking up space with no associated
connection or connection attempt underway.
NB you will need to reprocess any static policies after this patch so they
conform to the trust_store changes.
2020-07-20 07:28:28 +01:00
set(LIB_LIST "")
2020-05-22 16:47:40 +01:00
set(LIB_LIST_AT_END)
set(LWS_LIBRARIES)
set(LWS_OPENSSL_SUPPORT 0)
include(CMakeLists-implied-options.txt)
2018-10-03 14:14:29 +08:00
2020-05-22 16:47:40 +01:00
#
# Structural helpers for cmake in subdirs
#
2015-04-22 10:52:13 -07:00
2020-05-22 16:47:40 +01:00
macro(add_subdir_include_directories arg1)
add_subdirectory(${arg1})
include_directories(${_CMAKE_INC_LIST})
endmacro()
2018-09-04 08:06:46 +08:00
2020-05-22 16:47:40 +01:00
macro(exports_to_parent_scope)
set(SOURCES ${SOURCES} PARENT_SCOPE)
2020-06-07 07:53:36 +01:00
if (LIB_LIST)
set(LIB_LIST ${LIB_LIST} PARENT_SCOPE)
endif()
2020-05-22 16:47:40 +01:00
get_property(_CURR DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
set(_CMAKE_INC_LIST ${_CURR} PARENT_SCOPE)
2020-06-07 07:53:36 +01:00
if (LWS_LIB_BUILD_INC_PATHS)
set(LWS_LIB_BUILD_INC_PATHS ${LWS_LIB_BUILD_INC_PATHS} PARENT_SCOPE)
endif()
2020-05-22 16:47:40 +01:00
endmacro()
2018-09-04 08:06:46 +08:00
2020-05-22 16:47:40 +01:00
macro(export_to_parent_intermediate)
set(SOURCES ${SOURCES} PARENT_SCOPE)
2020-06-07 07:53:36 +01:00
if (LIB_LIST)
set(LIB_LIST ${LIB_LIST} PARENT_SCOPE)
endif()
2020-05-22 16:47:40 +01:00
set(_CMAKE_INC_LIST ${_CMAKE_INC_LIST} PARENT_SCOPE)
2020-06-07 07:53:36 +01:00
if (LWS_LIB_BUILD_INC_PATHS)
set(LWS_LIB_BUILD_INC_PATHS ${LWS_LIB_BUILD_INC_PATHS} PARENT_SCOPE)
endif()
2020-05-22 16:47:40 +01:00
endmacro()
2018-10-14 06:12:27 +08:00
2020-05-22 16:47:40 +01:00
#
# Try to find the current Git hash
#
2020-05-01 05:45:18 +01:00
find_package(Git)
if(GIT_EXECUTABLE)
execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "${GIT_EXECUTABLE}" describe --tags --always
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(LWS_BUILD_HASH ${GIT_HASH})
# append the build user and hostname
2020-05-22 16:47:40 +01:00
if (NOT LWS_REPRODUCIBLE)
2020-05-01 05:45:18 +01:00
execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "whoami"
OUTPUT_VARIABLE GIT_USER
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "hostname"
OUTPUT_VARIABLE GIT_HOST
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE "([^\\])[\\]([^\\])" "\\1\\\\\\\\\\2" GIT_USER ${GIT_USER})
set(LWS_BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH})
endif()
message("Git commit hash: ${LWS_BUILD_HASH}")
endif()
2021-04-20 08:30:18 -04:00
if ("${LWS_BUILD_HASH}" STREQUAL "")
set(LWS_BUILD_HASH "unknown")
endif()
2013-02-01 14:52:53 +01:00
set(PACKAGE "libwebsockets")
2020-05-01 05:45:18 +01:00
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
2013-02-22 09:28:08 +08:00
set(CPACK_PACKAGE_NAME "${PACKAGE}")
2020-03-04 10:01:28 +00:00
set(CPACK_PACKAGE_VERSION_MAJOR "4")
2021-04-15 16:55:07 +00:00
set(CPACK_PACKAGE_VERSION_MINOR "2")
2021-07-13 07:22:14 +01:00
set(CPACK_PACKAGE_VERSION_PATCH_NUMBER "1")
2020-05-29 08:24:07 +01:00
set(CPACK_PACKAGE_VERSION_PATCH "${CPACK_PACKAGE_VERSION_PATCH_NUMBER}-${LWS_BUILD_HASH}")
2018-11-23 11:30:56 +08:00
set(CPACK_PACKAGE_RELEASE 1)
2020-05-01 05:45:18 +01:00
2015-12-14 17:25:29 +00:00
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
2013-02-22 09:28:08 +08:00
set(CPACK_PACKAGE_VENDOR "andy@warmcat.com")
2018-11-23 11:30:56 +08:00
set(CPACK_PACKAGE_CONTACT "andy@warmcat.com")
2020-05-14 21:28:48 +01:00
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${CPACK_PACKAGE_VERSION}")
2021-04-15 16:55:07 +00:00
set(SOVERSION "18")
2016-11-07 21:36:05 +01:00
if(NOT CPACK_GENERATOR)
if(UNIX)
set(CPACK_GENERATOR "TGZ")
else()
set(CPACK_GENERATOR "ZIP")
endif()
endif()
2013-02-22 09:28:08 +08:00
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(VERSION "${CPACK_PACKAGE_VERSION}")
2013-02-01 14:52:53 +01:00
2020-05-01 05:45:18 +01:00
set(CPACK_RPM_PACKAGE_RELEASE_DIST ON)
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
2020-08-27 15:37:14 +01:00
# below makes path length problems in CI
set(CPACK_RPM_DEBUGINFO_PACKAGE OFF)
2020-05-01 05:45:18 +01:00
# below makes some kind of chimera rpm with binaries and sources
set(CPACK_RPM_PACKAGE_SOURCES OFF)
set(CPACK_RPM_INSTALL_WITH_EXEC ON)
2020-08-27 15:37:14 +01:00
set(CPACK_RPM_COMPONENT_INSTALL ON)
2020-05-01 05:45:18 +01:00
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_DEBUGINFO_PACKAGE ON)
set(CPACK_DEBIAN_PACKAGE_SOURCE ON)
2020-08-27 15:37:14 +01:00
set(CPACK_DEBIAN_COMPONENT_INSTALL ON)
2020-05-01 05:45:18 +01:00
2013-02-22 09:28:08 +08:00
set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION})
2015-12-14 17:25:29 +00:00
set(LWS_LIBRARY_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR})
set(LWS_LIBRARY_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR})
2020-05-29 08:24:07 +01:00
set(LWS_LIBRARY_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH_NUMBER})
set(LWS_LIBRARY_VERSION_PATCH_ELABORATED ${CPACK_PACKAGE_VERSION_PATCH})
2015-12-14 17:25:29 +00:00
2020-05-14 21:28:48 +01:00
if (NOT CMAKE_MODULE_PATH)
set(CMAKE_MODULE_PATH "")
endif()
2013-02-18 20:20:05 +08:00
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
2013-02-06 15:26:58 +09:00
2018-11-23 11:30:56 +08:00
2020-05-14 21:28:48 +01:00
if (CMAKE_TOOLCHAIN_FILE)
message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
endif()
if (NOT LIB_SUFFIX)
set(LIB_SUFFIX "")
endif()
2013-03-30 10:30:03 +08:00
2020-05-22 16:47:40 +01:00
if (WIN32)
2018-02-05 15:33:36 +01:00
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/win32port/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc @ONLY)
set(RESOURCES ${CMAKE_CURRENT_BINARY_DIR}/win32port/version.rc)
endif()
2020-05-22 16:47:40 +01:00
include_directories(include)
2014-02-15 13:48:56 +08:00
# Allow the user to override installation directories.
set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
set(LWS_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files")
2019-07-03 19:46:23 +01:00
# if you gave LWS_WITH_MINIZ, point to MINIZ here if not found
# automatically
set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib/miniz library")
set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib/miniz include directory")
2017-02-18 15:51:34 +08:00
set(LWS_SQLITE3_LIBRARIES CACHE PATH "Path to the sqlite3 library")
set(LWS_SQLITE3_INCLUDE_DIRS CACHE PATH "Path to the sqlite3 include directory")
2020-02-15 10:09:50 +00:00
set(LWS_LIBMOUNT_INCLUDE_DIRS CACHE PATH "Path to the libmount include directory")
set(LWS_LIBMOUNT_LIBRARIES CACHE PATH "Path to the libmount library")
2020-04-07 14:05:21 +01:00
# on unix, these are in the toolchain. On win32 you have to put them somewhere
# yourself and point to them here
set(LWS_EXT_PTHREAD_INCLUDE_DIR CACHE PATH "Path to an external pthreads include directory")
set(LWS_EXT_PTHREAD_LIBRARIES CACHE PATH "Path to an external pthreads library")
2016-05-19 15:28:31 +08:00
2015-04-22 10:52:13 -07:00
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written. The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
if (LWS_WITH_HTTP_STREAM_COMPRESSION)
set(LWS_WITH_ZLIB 1)
endif()
2017-09-28 11:29:03 +08:00
if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB)
2015-04-22 10:52:13 -07:00
if ("${LWS_ZLIB_LIBRARIES}" STREQUAL "" OR "${LWS_ZLIB_INCLUDE_DIRS}" STREQUAL "")
else()
set(ZLIB_LIBRARIES ${LWS_ZLIB_LIBRARIES})
set(ZLIB_INCLUDE_DIRS ${LWS_ZLIB_INCLUDE_DIRS})
set(ZLIB_FOUND 1)
endif()
endif()
2020-02-07 11:39:32 +00:00
2016-05-19 15:28:31 +08:00
if (LWS_WITH_SQLITE3)
if ("${LWS_SQLITE3_LIBRARIES}" STREQUAL "" OR "${LWS_SQLITE3_INCLUDE_DIRS}" STREQUAL "")
else()
set(SQLITE3_LIBRARIES ${LWS_SQLITE3_LIBRARIES})
set(SQLITE3_INCLUDE_DIRS ${LWS_SQLITE3_INCLUDE_DIRS})
set(SQLITE3_FOUND 1)
endif()
endif()
2013-10-26 20:03:43 +08:00
include_directories("${PROJECT_BINARY_DIR}")
2013-02-01 14:52:53 +01:00
2013-02-06 15:28:07 +09:00
# Check for different inline keyword versions.
foreach(KEYWORD "inline" "__inline__" "__inline")
set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}")
CHECK_C_SOURCE_COMPILES(
"
#include <stdio.h>
2015-04-22 10:52:13 -07:00
static KEYWORD void a() {}
2013-02-06 15:28:07 +09:00
int main(int argc, char **argv) { a(); return 0; }
2015-06-24 16:46:02 +02:00
" LWS_HAVE_${KEYWORD})
2013-02-06 15:28:07 +09:00
endforeach()
2015-06-24 16:46:02 +02:00
if (NOT LWS_HAVE_inline)
if (LWS_HAVE___inline__)
2013-02-06 15:28:07 +09:00
set(inline __inline__)
2015-06-24 16:46:02 +02:00
elseif(LWS_HAVE___inline)
2013-02-06 15:28:07 +09:00
set(inline __inline)
endif()
endif()
2016-10-02 02:21:03 +03:00
# Put the libraries and binaries that get built into directories at the
2013-02-06 15:26:58 +09:00
# top of the build tree rather than in hard-to-find leaf directories.
2013-10-26 20:03:43 +08:00
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
2013-02-06 15:26:58 +09:00
2016-07-06 10:48:41 +08:00
SET(LWS_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}")
2013-04-16 19:48:05 +08:00
# Put absolute path of dynamic libraries into the object code. Some
# architectures, notably Mac OS X, need this.
2014-02-15 13:48:56 +08:00
SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}")
2013-04-16 19:48:05 +08:00
2015-10-15 11:20:40 +08:00
if (LWS_WITHOUT_BUILTIN_SHA1)
set(LWS_SHA1_USE_OPENSSL_NAME 1)
endif()
2019-03-16 08:10:47 +08:00
CHECK_C_SOURCE_COMPILES(
"#include <malloc.h>
int main(int argc, char **argv) { return malloc_trim(0); }
" LWS_HAVE_MALLOC_TRIM)
CHECK_C_SOURCE_COMPILES(
"#include <malloc.h>
int main(int argc, char **argv) { return (int)malloc_usable_size((void *)0); }
" LWS_HAVE_MALLOC_USABLE_SIZE)
2018-10-09 15:14:12 +08:00
2015-06-24 16:46:02 +02:00
CHECK_FUNCTION_EXISTS(fork LWS_HAVE_FORK)
CHECK_FUNCTION_EXISTS(getenv LWS_HAVE_GETENV)
CHECK_FUNCTION_EXISTS(malloc LWS_HAVE_MALLOC)
CHECK_FUNCTION_EXISTS(memset LWS_HAVE_MEMSET)
CHECK_FUNCTION_EXISTS(realloc LWS_HAVE_REALLOC)
CHECK_FUNCTION_EXISTS(socket LWS_HAVE_SOCKET)
CHECK_FUNCTION_EXISTS(strerror LWS_HAVE_STRERROR)
CHECK_FUNCTION_EXISTS(vfork LWS_HAVE_VFORK)
2016-03-20 11:55:25 +08:00
CHECK_FUNCTION_EXISTS(execvpe LWS_HAVE_EXECVPE)
2015-06-24 16:46:02 +02:00
CHECK_FUNCTION_EXISTS(getifaddrs LWS_HAVE_GETIFADDRS)
2016-03-04 10:53:51 +08:00
CHECK_FUNCTION_EXISTS(snprintf LWS_HAVE_SNPRINTF)
CHECK_FUNCTION_EXISTS(_snprintf LWS_HAVE__SNPRINTF)
CHECK_FUNCTION_EXISTS(_vsnprintf LWS_HAVE__VSNPRINTF)
2016-04-26 07:45:45 +08:00
CHECK_FUNCTION_EXISTS(getloadavg LWS_HAVE_GETLOADAVG)
2017-06-09 20:20:42 +08:00
CHECK_FUNCTION_EXISTS(atoll LWS_HAVE_ATOLL)
CHECK_FUNCTION_EXISTS(_atoi64 LWS_HAVE__ATOI64)
CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64)
2019-08-08 20:05:03 +01:00
CHECK_FUNCTION_EXISTS(clock_gettime LWS_HAVE_CLOCK_GETTIME)
2021-03-25 09:57:49 +03:00
CHECK_FUNCTION_EXISTS(localtime_r LWS_HAVE_LOCALTIME_R)
2021-03-25 10:51:01 +03:00
CHECK_FUNCTION_EXISTS(gmtime_r LWS_HAVE_GMTIME_R)
2021-03-25 10:33:05 +03:00
CHECK_FUNCTION_EXISTS(ctime_r LWS_HAVE_CTIME_R)
2021-03-24 06:11:03 +00:00
CHECK_FUNCTION_EXISTS(getgrgid_r LWS_HAVE_GETGRGID_R)
CHECK_FUNCTION_EXISTS(getgrnam_r LWS_HAVE_GETGRNAM_R)
CHECK_FUNCTION_EXISTS(getpwuid_r LWS_HAVE_GETPWUID_R)
CHECK_FUNCTION_EXISTS(getpwnam_r LWS_HAVE_GETPWNAM_R)
2021-08-01 08:55:34 +01:00
CHECK_FUNCTION_EXISTS(timegm LWS_HAVE_TIMEGM)
2020-04-13 19:28:33 +01:00
2021-05-30 23:27:43 +08:00
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
if(CMAKE_OSX_DEPLOYMENT_TARGET LESS "10.12")
message("No clock_gettime found on macOS ${CMAKE_OSX_DEPLOYMENT_TARGET}. Disabling LWS_HAVE_CLOCK_GETTIME.")
set(LWS_HAVE_CLOCK_GETTIME 0)
endif()
endif()
2015-06-24 16:46:02 +02:00
if (NOT LWS_HAVE_GETIFADDRS)
2014-02-15 13:48:56 +08:00
if (LWS_WITHOUT_BUILTIN_GETIFADDRS)
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.")
2013-02-06 15:27:27 +09:00
endif()
set(LWS_BUILTIN_GETIFADDRS 1)
2013-02-06 15:26:58 +09:00
endif()
2020-04-07 14:05:21 +01:00
if (LWS_EXT_PTHREAD_INCLUDE_DIR)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES};${LWS_EXT_PTHREAD_INCLUDE_DIR})
include_directories(${LWS_EXT_PTHREAD_INCLUDE_DIR})
2020-05-22 16:47:40 +01:00
list(APPEND LIB_LIST_AT_END ${LWS_EXT_PTHREAD_LIBRARIES})
2020-04-07 14:05:21 +01:00
set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} " -DHAVE_STRUCT_TIMESPEC=1")
endif()
2020-05-22 16:47:40 +01:00
#
# add libs here that need to be at the end of the link order
#
if (LWS_EXT_PTHREAD_INCLUDE_DIR)
list(APPEND LIB_LIST_AT_END ${LWS_EXT_PTHREAD_LIBRARIES})
endif()
if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB)
list(APPEND LIB_LIST_AT_END "${ZLIB_LIBRARIES}")
endif()
2020-12-06 19:16:48 +00:00
if (LWS_WITH_PLUGINS_API AND UNIX AND CMAKE_DL_LIBS AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX"))
list(APPEND LIB_LIST_AT_END ${CMAKE_DL_LIBS})
2020-08-31 09:19:40 +01:00
endif()
2015-06-24 16:46:02 +02:00
CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H)
CHECK_INCLUDE_FILE(memory.h LWS_HAVE_MEMORY_H)
CHECK_INCLUDE_FILE(netinet/in.h LWS_HAVE_NETINET_IN_H)
CHECK_INCLUDE_FILE(stdint.h LWS_HAVE_STDINT_H)
CHECK_INCLUDE_FILE(stdlib.h LWS_HAVE_STDLIB_H)
CHECK_INCLUDE_FILE(strings.h LWS_HAVE_STRINGS_H)
CHECK_INCLUDE_FILE(string.h LWS_HAVE_STRING_H)
CHECK_INCLUDE_FILE(sys/prctl.h LWS_HAVE_SYS_PRCTL_H)
CHECK_INCLUDE_FILE(sys/socket.h LWS_HAVE_SYS_SOCKET_H)
2016-09-09 06:48:24 +08:00
CHECK_INCLUDE_FILE(sys/sockio.h LWS_HAVE_SYS_SOCKIO_H)
2015-06-24 16:46:02 +02:00
CHECK_INCLUDE_FILE(sys/stat.h LWS_HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE(sys/types.h LWS_HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE(unistd.h LWS_HAVE_UNISTD_H)
CHECK_INCLUDE_FILE(vfork.h LWS_HAVE_VFORK_H)
2017-06-07 06:10:02 +08:00
CHECK_INCLUDE_FILE(sys/capability.h LWS_HAVE_SYS_CAPABILITY_H)
2018-01-26 07:22:35 +08:00
CHECK_INCLUDE_FILE(malloc.h LWS_HAVE_MALLOC_H)
2018-03-02 09:01:22 +08:00
CHECK_INCLUDE_FILE(pthread.h LWS_HAVE_PTHREAD_H)
2019-07-31 16:31:22 +08:00
CHECK_INCLUDE_FILE(inttypes.h LWS_HAVE_INTTYPES_H)
2020-11-01 11:24:31 +01:00
CHECK_INCLUDE_FILE(sys/resource.h LWS_HAVE_SYS_RESOURCE_H)
2017-06-07 06:10:02 +08:00
2020-06-03 09:29:28 +01:00
if (WIN32 OR MSVC)
CHECK_C_SOURCE_COMPILES("#include <winsock2.h>
#include <afunix.h>
int main() { return 0; }" LWS_HAVE_WIN32_AFUNIX_H)
if (LWS_UNIX_SOCK AND NOT LWS_HAVE_WIN32_AFUNIX_H)
2020-09-17 14:30:23 +03:00
message("No afunix.h found. Disabling LWS_UNIX_SOCK.")
set(LWS_WITH_UNIX_SOCK OFF)
2020-06-03 09:29:28 +01:00
endif()
endif()
2018-10-02 10:50:24 +08:00
CHECK_LIBRARY_EXISTS(cap cap_set_flag "" LWS_HAVE_LIBCAP)
2020-05-22 16:47:40 +01:00
if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB)
if (LWS_WITH_MINIZ)
CHECK_INCLUDE_FILE(miniz.h LWS_HAVE_ZLIB_H)
else()
CHECK_INCLUDE_FILE(zlib.h LWS_HAVE_ZLIB_H)
2018-10-02 10:50:24 +08:00
endif()
endif()
2015-11-02 08:21:08 +08:00
2020-05-22 16:47:40 +01:00
CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h" STDC_HEADERS)
2013-02-01 14:52:53 +01:00
2020-05-14 21:28:48 +01:00
if (NOT CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_FLAGS "")
endif()
if (NOT CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_INCLUDES "")
endif()
if (NOT CMAKE_REQUIRED_LIBRARIES)
set(CMAKE_REQUIRED_LIBRARIES "")
endif()
2017-07-07 08:32:04 +08:00
CHECK_C_SOURCE_COMPILES("#include <stdint.h>
int main(void) {
intptr_t test = 1;
return 0;
}" LWS_HAS_INTPTR_T)
2020-05-22 16:47:40 +01:00
if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR
(CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(COMPILER_IS_CLANG ON)
endif()
2020-01-24 13:55:21 +00:00
2020-05-22 16:47:40 +01:00
if (LWS_HAVE_PTHREAD_H AND NOT LWS_PLAT_FREERTOS)
2021-03-25 11:09:13 +03:00
CHECK_C_SOURCE_COMPILES("
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
2020-05-22 16:47:40 +01:00
#include <pthread.h>
int main(void) {
2021-04-04 18:50:05 +01:00
#ifdef __PTW32_H
pthread_t th = {0,0};
#else
2020-05-22 16:47:40 +01:00
pthread_t th = 0;
2021-04-04 18:50:05 +01:00
#endif
2020-05-22 16:47:40 +01:00
pthread_setname_np(th, NULL);
return 0;
}" LWS_HAS_PTHREAD_SETNAME_NP)
endif()
2014-02-28 00:42:08 +01:00
2019-01-11 18:19:21 +08:00
CHECK_C_SOURCE_COMPILES("#include <stddef.h>
2020-01-03 14:02:06 +00:00
#include <getopt.h>
int main(void) {
2019-01-11 16:48:53 +08:00
void *p = (void *)getopt_long;
return p != NULL;
}" LWS_HAS_GETOPT_LONG)
2020-10-09 17:48:39 +08:00
CHECK_C_SOURCE_COMPILES("#include <linux/rtnetlink.h>
int main(void) {
int test = RTA_PREF;
return 0;
}" LWS_HAVE_RTA_PREF)
2019-01-11 16:48:53 +08:00
2020-12-12 06:21:40 +00:00
CHECK_C_SOURCE_COMPILES("#include <sys/types.h>
int main(void) {
suseconds_t x = 0;
return (int)x;
}" LWS_HAVE_SUSECONDS_T)
2014-02-28 00:42:08 +01:00
if (NOT PID_T_SIZE)
2013-02-01 14:52:53 +01:00
set(pid_t int)
2014-02-28 00:42:08 +01:00
endif()
if (NOT SIZE_T_SIZE)
2013-02-01 14:52:53 +01:00
set(size_t "unsigned int")
endif()
2015-06-24 16:46:02 +02:00
if (NOT LWS_HAVE_MALLOC)
2013-02-01 14:52:53 +01:00
set(malloc rpl_malloc)
endif()
2015-06-24 16:46:02 +02:00
if (NOT LWS_HAVE_REALLOC)
2013-02-01 14:52:53 +01:00
set(realloc rpl_realloc)
endif()
2013-03-16 12:32:59 +08:00
2019-06-20 16:16:03 -07:00
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR COMPILER_IS_CLANG)
2015-01-27 19:46:26 +08:00
include (CheckCCompilerFlag)
2015-06-24 16:46:02 +02:00
CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY)
2020-03-27 18:35:23 +00:00
if (LWS_WITH_FANALYZER)
CHECK_C_COMPILER_FLAG(-fanalyzer LWS_HAVE_FANALYZER)
endif()
2015-06-24 16:46:02 +02:00
if (LWS_HAVE_VISIBILITY)
2015-01-27 19:46:26 +08:00
set(VISIBILITY_FLAG -fvisibility=hidden)
endif()
2017-11-14 11:25:54 +08:00
if (LWS_WITH_GCOV)
2019-02-28 07:05:12 +08:00
set (GCOV_FLAGS "-fprofile-arcs -ftest-coverage ")
2020-05-14 21:28:48 +01:00
else()
set(GCOV_FLAGS "")
2017-11-14 11:25:54 +08:00
endif()
2018-04-20 10:33:23 +08:00
2018-11-03 14:47:48 +08:00
if (LWS_WITH_ASAN)
2019-06-20 16:16:03 -07:00
set (ASAN_FLAGS "-fsanitize=address -fsanitize=undefined -fsanitize-address-use-after-scope -fsanitize-undefined-trap-on-error")
if (NOT COMPILER_IS_CLANG)
set (ASAN_FLAGS "${ASAN_FLAGS} -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak")
endif()
2018-11-03 14:47:48 +08:00
message("Enabling ASAN")
2020-05-14 21:28:48 +01:00
else()
set(ASAN_FLAGS "")
2018-11-03 14:47:48 +08:00
endif()
2018-04-20 10:33:23 +08:00
2019-05-15 07:27:18 +01:00
check_c_compiler_flag("-Wignored-qualifiers" LWS_GCC_HAS_IGNORED_QUALIFIERS)
check_c_compiler_flag("-Wtype-limits" LWS_GCC_HAS_TYPE_LIMITS)
2021-02-14 06:05:16 +00:00
check_c_compiler_flag("-Wno-deprecated-declarations" LWS_GCC_HAS_NO_DEPRECATED_DECLARATIONS)
2019-05-15 07:27:18 +01:00
if (LWS_GCC_HAS_IGNORED_QUALIFIERS)
set(CMAKE_C_FLAGS "-Wignored-qualifiers ${CMAKE_C_FLAGS}" )
endif()
if (LWS_GCC_HAS_TYPE_LIMITS)
set(CMAKE_C_FLAGS "-Wtype-limits ${CMAKE_C_FLAGS}" )
endif()
2020-03-27 18:35:23 +00:00
if (LWS_WITH_FANALYZER AND LWS_HAVE_FANALYZER)
set(CMAKE_C_FLAGS "-fanalyzer ${CMAKE_C_FLAGS}" )
endif()
2020-09-15 15:00:09 +03:00
if (CMAKE_COMPILER_IS_CLANG OR CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4)
2020-08-30 09:28:35 +03:00
set(CMAKE_C_FLAGS "-Wuninitialized ${CMAKE_C_FLAGS}")
endif()
2020-05-26 16:35:16 +02:00
# always warn all and generate debug info
2020-08-30 09:28:35 +03:00
if (UNIX AND NOT LWS_PLAT_FREERTOS)
2020-12-12 06:21:40 +00:00
set(CMAKE_C_FLAGS "-Wall -Wconversion -Wsign-compare -Wstrict-aliasing ${VISIBILITY_FLAG} -Wundef ${GCOV_FLAGS} ${CMAKE_C_FLAGS} ${ASAN_FLAGS}" )
2020-08-30 09:28:35 +03:00
else()
2020-09-29 16:58:05 +01:00
set(CMAKE_C_FLAGS "-Wall -Wsign-compare ${VISIBILITY_FLAG} ${GCOV_FLAGS} ${CMAKE_C_FLAGS}" )
2020-08-30 09:28:35 +03:00
endif()
2013-03-16 12:32:59 +08:00
2020-08-30 09:28:35 +03:00
if ("${DISABLE_WERROR}" STREQUAL "OFF")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif()
2021-02-14 06:05:16 +00:00
if (LWS_SUPPRESS_DEPRECATED_API_WARNINGS)
set(CMAKE_C_FLAGS "-Wno-deprecated ${CMAKE_C_FLAGS}")
if (LWS_GCC_HAS_NO_DEPRECATED_DECLARATIONS)
set(CMAKE_C_FLAGS "-Wno-deprecated-declarations ${CMAKE_C_FLAGS}")
endif()
endif()
2020-08-30 09:28:35 +03:00
endif ()
2019-01-15 06:59:48 +08:00
2016-01-25 21:39:07 +08:00
if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS)
2020-09-03 08:20:16 +01:00
if (UNIX AND LWS_HAVE_PTHREAD_H AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "QNX"))
2015-11-29 19:41:13 +08:00
# jeez clang understands -pthread but dies if he sees it at link time!
# http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
2020-09-28 10:13:39 +01:00
list(APPEND LIB_LIST_AT_END -lpthread)
2015-11-29 19:41:13 +08:00
endif()
endif()
2019-06-20 16:16:03 -07:00
if (COMPILER_IS_CLANG)
2018-11-05 10:25:36 +08:00
2015-11-29 19:19:09 +08:00
# otherwise osx blows a bunch of openssl deprecated api errors
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" )
2018-11-05 10:25:36 +08:00
if (UNIX AND LWS_HAVE_PTHREAD_H)
2020-01-24 13:55:21 +00:00
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread -Wno-error=unused-command-line-argument" )
2018-11-05 10:25:36 +08:00
endif()
2015-11-29 19:19:09 +08:00
endif()
2020-05-22 16:47:40 +01:00
if (WINCE)
list(APPEND LIB_LIST_AT_END ws2.lib)
elseif (WIN32)
2020-08-05 12:01:14 +01:00
list(APPEND LIB_LIST_AT_END ws2_32.lib userenv.lib psapi.lib iphlpapi.lib crypt32.lib)
2020-05-22 16:47:40 +01:00
endif()
if (MSVC)
# Turn off pointless microsoft security warnings.
add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
# Fail the build if any warnings
add_compile_options(/W3 /WX)
endif(MSVC)
if (MINGW)
set(LWS_MINGW_SUPPORT 1)
set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}")
add_definitions(-DWINVER=0x0601 -D_WIN32_WINNT=0x0601)
endif()
2020-06-07 07:53:36 +01:00
if (HDR_PRIVATE)
source_group("Headers Private" FILES ${HDR_PRIVATE})
endif()
if (HDR_PUBLIC)
source_group("Headers Public" FILES ${HDR_PUBLIC})
endif()
if (SOURCES)
source_group("Sources" FILES ${SOURCES})
endif()
2020-05-14 21:28:48 +01:00
if (RESOURCES)
source_group("Resources" FILES ${RESOURCES})
endif()
2013-02-06 15:25:26 +09:00
2020-05-22 16:47:40 +01:00
2013-02-06 15:25:26 +09:00
#
2020-05-22 16:47:40 +01:00
# ZLIB (needed for deflate extension and if LWS_WITH_HTTP_STREAM_COMPRESSION)
2013-02-01 14:52:53 +01:00
#
2015-04-22 10:52:13 -07:00
if (LWS_WITH_ZLIB)
2020-05-22 16:47:40 +01:00
if (NOT ZLIB_FOUND)
2019-07-03 19:46:23 +01:00
if (LWS_WITH_MINIZ)
find_package(Miniz REQUIRED)
set(ZLIB_INCLUDE_DIRS ${MINIZ_INCLUDE_DIRS})
set(ZLIB_LIBRARIES ${MINIZ_LIBRARIES})
else()
find_package(ZLIB REQUIRED)
endif()
2013-02-19 10:14:37 +08:00
endif()
2019-07-03 19:46:23 +01:00
message("zlib/miniz include dirs: ${ZLIB_INCLUDE_DIRS}")
message("zlib/miniz libraries: ${ZLIB_LIBRARIES}")
2013-02-19 10:14:37 +08:00
include_directories(${ZLIB_INCLUDE_DIRS})
2020-02-06 06:51:19 +00:00
# done later at end of link list
# list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
2020-05-28 21:55:08 +03:00
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${ZLIB_LIBRARIES})
2020-05-22 16:47:40 +01:00
list(APPEND LIB_LIST_AT_END ${ZLIB_LIBRARIES})
2015-04-22 10:52:13 -07:00
endif()
2013-02-01 14:52:53 +01:00
2020-02-07 11:39:32 +00:00
2020-02-15 10:09:50 +00:00
if (LWS_WITH_FSMOUNT AND ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
2020-06-03 17:14:03 +01:00
if (NOT LWS_LIBMOUNT_INCLUDE_DIRS STREQUAL "")
include_directories(${LWS_LIBMOUNT_INCLUDE_DIRS})
message("libmount include dir: ${LWS_LIBMOUNT_INCLUDE_DIRS}")
endif()
if (NOT LWS_LIBMOUNT_LIBRARIES STREQUAL "")
message("libmount libraries: ${LWS_LIBMOUNT_LIBRARIES}")
list(APPEND LIB_LIST ${LWS_LIBMOUNT_LIBRARIES})
else()
list(APPEND LIB_LIST mount)
endif()
2020-02-15 10:09:50 +00:00
endif()
2020-02-07 11:39:32 +00:00
2016-05-19 15:28:31 +08:00
if (LWS_WITH_SQLITE3)
if (NOT SQLITE3_FOUND)
find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h)
find_library(SQLITE3_LIBRARIES NAMES sqlite3)
if(SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
set(SQLITE3_FOUND 1)
endif()
endif()
message("sqlite3 include dir: ${SQLITE3_INCLUDE_DIRS}")
message("sqlite3 libraries: ${SQLITE3_LIBRARIES}")
include_directories("${SQLITE3_INCLUDE_DIRS}")
list(APPEND LIB_LIST ${SQLITE3_LIBRARIES})
endif()
2018-09-04 08:06:46 +08:00
if (LWS_WITH_HUBBUB)
2016-10-10 20:10:34 +08:00
find_library(LIBHUBBUB_LIBRARIES NAMES hubbub)
2016-03-20 11:59:53 +08:00
list(APPEND LIB_LIST ${LIBHUBBUB_LIBRARIES} )
endif()
2020-07-19 16:29:07 +02:00
if (LWS_HAVE_LIBCAP)
find_library(LIBCAP_LIBRARIES NAMES cap)
list(APPEND LIB_LIST ${LIBCAP_LIBRARIES} )
endif()
2021-01-31 05:50:12 +00:00
if (LWS_WITH_PLUGINS_BUILTIN)
add_subdirectory(plugins)
endif()
2020-06-03 17:14:03 +01:00
2013-02-06 15:26:58 +09:00
#
2020-05-22 16:47:40 +01:00
# Append the "at end" pieces to the lib list
2013-02-06 15:26:58 +09:00
#
2020-05-22 16:47:40 +01:00
list(APPEND LIB_LIST ${LIB_LIST_AT_END})
2018-01-04 10:37:25 +08:00
2020-02-06 06:51:19 +00:00
#
2020-05-22 16:47:40 +01:00
# Second-level CMakeLists
2020-02-06 06:51:19 +00:00
#
2020-05-22 16:47:40 +01:00
include_directories("${PROJECT_SOURCE_DIR}/lib")
2017-09-24 15:30:42 +00:00
2021-01-31 05:50:12 +00:00
add_subdirectory(lib)
2017-06-07 06:10:02 +08:00
2020-01-17 12:33:28 +00:00
2020-05-22 16:47:40 +01:00
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR cmake)
else()
set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets)
2020-02-06 06:51:19 +00:00
endif()
2020-11-25 10:58:09 +00:00
configure_file(${PROJECT_SOURCE_DIR}/cmake/LwsCheckRequirements.cmake
${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LwsCheckRequirements.cmake
@ONLY)
configure_file(${PROJECT_SOURCE_DIR}/cmake/LwsCheckRequirements.cmake
${PROJECT_BINARY_DIR}/LwsCheckRequirements.cmake
@ONLY)
2017-11-08 15:53:43 +08:00
2020-05-22 16:47:40 +01:00
# Generate version info for both build-tree and install-tree.
configure_file(${PROJECT_SOURCE_DIR}/cmake/libwebsockets-config-version.cmake.in
${PROJECT_BINARY_DIR}/libwebsockets-config-version.cmake
@ONLY)
2020-05-14 21:28:48 +01:00
2020-05-22 16:47:40 +01:00
# Generate the config file for the build-tree.
set(LWS__INCLUDE_DIRS
"${PROJECT_SOURCE_DIR}/lib"
"${PROJECT_BINARY_DIR}")
set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories")
configure_file(${PROJECT_SOURCE_DIR}/cmake/libwebsockets-config.cmake.in
${PROJECT_BINARY_DIR}/libwebsockets-config.cmake
@ONLY)
set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
2019-01-11 13:14:32 +08:00
2020-05-22 16:47:40 +01:00
# Export targets (This is used for other CMake projects to easily find the libraries and include files).
if (LWS_WITH_EXPORT_LWSTARGETS)
export(TARGETS ${LWS_LIBRARIES}
FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
2017-04-07 11:29:57 +08:00
endif()
2018-04-12 21:37:59 +08:00
2020-05-22 16:47:40 +01:00
set(libwebsockets_DIR ${PROJECT_BINARY_DIR})
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
message("DIR ${libwebsockets_DIR} CMP ${CMAKE_MODULE_PATH}")
2020-03-19 10:14:25 +00:00
2020-05-22 16:47:40 +01:00
if (LWS_WITH_MINIMAL_EXAMPLES)
add_subdirectory(minimal-examples)
endif()
2020-03-19 10:14:25 +00:00
2020-05-22 16:47:40 +01:00
if (NOT LWS_WITHOUT_TESTAPPS)
add_subdirectory(test-apps)
endif()
2018-04-18 18:45:27 +08:00
2021-01-31 05:50:12 +00:00
if (NOT LWS_WITH_PLUGINS_BUILTIN)
2020-05-22 16:47:40 +01:00
add_subdirectory(plugins)
2021-01-31 05:50:12 +00:00
endif()
2020-05-22 16:47:40 +01:00
add_subdirectory(lwsws)
2018-04-18 18:45:27 +08:00
2016-04-13 22:17:05 +02:00
# Generate the lws_config.h that includes all the public compilation settings.
configure_file(
2017-09-22 09:46:58 +08:00
"${PROJECT_SOURCE_DIR}/cmake/lws_config.h.in"
2016-04-13 22:17:05 +02:00
"${PROJECT_BINARY_DIR}/lws_config.h")
2020-05-22 16:47:40 +01:00
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/include/lws_config.h
${PROJECT_BINARY_DIR}/include/libwebsockets
${PROJECT_BINARY_DIR}/include/libwebsockets.h
COMMENT "Creating build include dir"
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets.h
${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets.h
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/include/libwebsockets/
${CMAKE_CURRENT_BINARY_DIR}/include/libwebsockets
COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_BINARY_DIR}/lws_config.h
${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h
MAIN_DEPENDENCY ${PROJECT_BINARY_DIR}/lws_config.h
)
2016-04-13 22:17:05 +02:00
2020-05-22 16:47:40 +01:00
add_custom_target(GENHDR DEPENDS ${PROJECT_BINARY_DIR}/include/lws_config.h)
2017-03-08 11:11:41 +08:00
2020-05-22 16:47:40 +01:00
file(GLOB HDR_PUBLIC1 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/libwebsockets/*.h)
file(GLOB HDR_PUBLIC2 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} include/libwebsockets.h)
file(GLOB HDR_PUBLIC3 RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/include/lws_config.h)
list(APPEND HDR_PUBLIC ${HDR_PUBLIC1} ${HDR_PUBLIC2} ${HDR_PUBLIC3})
2017-03-08 11:11:41 +08:00
2020-05-22 16:47:40 +01:00
set_source_files_properties(${HDR_PUBLIC} PROPERTIES GENERATED 1)
2017-03-08 11:11:41 +08:00
2020-05-22 16:47:40 +01:00
if (LWS_WITH_STATIC)
add_dependencies(websockets GENHDR)
2017-03-08 11:11:41 +08:00
endif()
2020-05-22 16:47:40 +01:00
if (LWS_WITH_SHARED)
add_dependencies(websockets_shared GENHDR)
2017-03-08 11:11:41 +08:00
endif()
2016-04-13 22:17:05 +02:00
2013-02-06 15:26:58 +09:00
#
2014-02-15 13:48:56 +08:00
#
# Installation preparations.
#
export(PACKAGE libwebsockets)
2020-05-22 16:47:40 +01:00
install(DIRECTORY include/libwebsockets
2020-08-27 15:37:14 +01:00
DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
2020-05-22 16:47:40 +01:00
install(FILES ${PROJECT_BINARY_DIR}/include/libwebsockets.h ${PROJECT_BINARY_DIR}/include/lws_config.h
2020-08-27 15:37:14 +01:00
DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
2014-02-15 13:48:56 +08:00
# Generate the config file for the installation tree.
2014-02-28 16:29:28 +01:00
get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE)
get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE)
2014-02-15 13:48:56 +08:00
file(RELATIVE_PATH
REL_INCLUDE_DIR
2014-02-28 16:29:28 +01:00
"${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}"
"${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir.
2014-02-15 13:48:56 +08:00
2020-12-24 16:18:46 +03:00
if (DEFINED REL_INCLUDE_DIR)
set(LWS__INCLUDE_DIRS "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}")
endif()
configure_file(${PROJECT_SOURCE_DIR}/cmake/libwebsockets-config.cmake.in
${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libwebsockets-config.cmake
@ONLY)
2020-05-22 16:47:40 +01:00
set_target_properties(${LWS_LIBRARIES}
PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
2016-04-06 16:15:40 +08:00
2015-12-08 10:26:57 +08:00
# Install the LibwebsocketsConfig.cmake and LibwebsocketsConfigVersion.cmake
install(FILES
2020-05-22 16:47:40 +01:00
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libwebsockets-config.cmake"
"${PROJECT_BINARY_DIR}/libwebsockets-config-version.cmake"
2020-11-25 10:58:09 +00:00
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LwsCheckRequirements.cmake"
2015-12-08 10:26:57 +08:00
DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
2016-03-29 18:27:32 +08:00
# Install exports for the install-tree.
2017-11-20 12:41:29 +01:00
if (LWS_WITH_EXPORT_LWSTARGETS)
install(EXPORT LibwebsocketsTargets
DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
endif()
2016-03-29 18:27:32 +08:00
2013-03-10 08:11:48 +08:00
# build subdir is not part of sources
2018-05-26 09:19:54 +08:00
set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) "/.git/" "/build/" "\\\\.tgz$" "\\\\.tar\\\\.gz$")
2013-03-10 08:11:48 +08:00
2013-02-22 09:28:08 +08:00
# Most people are more used to "make dist" compared to "make package_source"
2013-10-26 20:03:43 +08:00
add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source)
2013-02-22 09:28:08 +08:00
2014-02-15 13:48:56 +08:00
2018-03-17 06:43:12 +08:00
2013-02-22 09:28:08 +08:00
# This must always be last!
include(CPack)