1 cmake_minimum_required(VERSION 2.8.9)
3 if(NOT DEFINED CMAKE_BUILD_TYPE)
4 set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
7 project(libwebsockets C)
9 set(PACKAGE "libwebsockets")
10 set(CPACK_PACKAGE_NAME "${PACKAGE}")
11 set(CPACK_PACKAGE_VERSION_MAJOR "2")
12 set(CPACK_PACKAGE_VERSION_MINOR "1")
13 set(CPACK_PACKAGE_VERSION_PATCH "0")
14 set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
15 set(CPACK_PACKAGE_VENDOR "andy@warmcat.com")
16 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}")
18 if(NOT CPACK_GENERATOR)
20 set(CPACK_GENERATOR "TGZ")
22 set(CPACK_GENERATOR "ZIP")
25 set(CPACK_SOURCE_GENERATOR "TGZ")
26 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
27 set(VERSION "${CPACK_PACKAGE_VERSION}")
29 set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION})
30 set(LWS_LIBRARY_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR})
31 set(LWS_LIBRARY_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR})
32 set(LWS_LIBRARY_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH})
34 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
36 message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
38 # Try to find the current Git hash.
42 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
43 COMMAND "${GIT_EXECUTABLE}" describe
44 OUTPUT_VARIABLE GIT_HASH
45 OUTPUT_STRIP_TRAILING_WHITESPACE
48 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
50 OUTPUT_VARIABLE GIT_USER
51 OUTPUT_STRIP_TRAILING_WHITESPACE
54 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
56 OUTPUT_VARIABLE GIT_HOST
57 OUTPUT_STRIP_TRAILING_WHITESPACE
59 string(REGEX REPLACE "([^\\])[\\]([^\\])" "\\1\\\\\\\\\\2" GIT_USER ${GIT_USER})
60 set(LWS_BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH})
61 message("Git commit hash: ${LWS_BUILD_HASH}")
64 set(LWS_USE_BUNDLED_ZLIB_DEFAULT OFF)
66 set(LWS_USE_BUNDLED_ZLIB_DEFAULT ON)
69 option(LWS_WITH_STATIC "Build the static version of the library" ON)
70 option(LWS_WITH_SHARED "Build the shared version of the library" ON)
71 option(LWS_WITH_SSL "Include SSL support (default OpenSSL, wolfSSL if LWS_USE_WOLFSSL is set)" ON)
72 option(LWS_USE_BORINGSSL "Use BoringSSL replacement for OpenSSL" OFF)
73 option(LWS_USE_CYASSL "Use CyaSSL replacement for OpenSSL. When setting this, you also need to specify LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS" OFF)
74 option(LWS_USE_WOLFSSL "Use wolfSSL replacement for OpenSSL. When setting this, you also need to specify LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS" OFF)
75 option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" ON)
76 option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
77 option(LWS_WITH_LIBUV "Compile with support for libuv" OFF)
78 option(LWS_USE_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_USE_BUNDLED_ZLIB_DEFAULT})
79 option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of the OS-installed CA root certs" ON)
80 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)
81 option(LWS_WITHOUT_BUILTIN_SHA1 "Don't build the lws sha-1 (eg, because openssl will provide it" OFF)
82 option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF)
83 option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF)
84 option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF)
85 option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
86 option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF)
87 option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF)
88 option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF)
89 option(LWS_WITHOUT_TEST_ECHO "Don't build the echo test application" OFF)
90 option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
91 option(LWS_WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF)
92 option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" OFF)
93 option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF)
94 option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON)
95 option(LWS_IPV6 "Compile with support for ipv6" OFF)
96 option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket" OFF)
97 option(LWS_WITH_HTTP2 "Compile with support for http2" OFF)
98 option(LWS_MBED3 "Platform is MBED3" OFF)
99 option(LWS_SSL_SERVER_WITH_ECDH_CERT "Include SSL server use ECDH certificate" OFF)
100 option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out/err) APIs" OFF)
101 option(LWS_WITH_HTTP_PROXY "Support for rewriting HTTP proxying" OFF)
102 option(LWS_WITH_LWSWS "Libwebsockets Webserver" OFF)
103 option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions" OFF)
104 option(LWS_WITH_ACCESS_LOG "Support generating Apache-compatible access logs" OFF)
105 option(LWS_WITH_SERVER_STATUS "Support json + jscript server monitoring" OFF)
106 option(LWS_WITH_LEJP "With the Lightweight JSON Parser" OFF)
107 option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF)
108 option(LWS_WITH_GENERIC_SESSIONS "With the Generic Sessions plugin" OFF)
109 option(LWS_WITH_SQLITE3 "Require SQLITE3 support" OFF)
110 option(LWS_WITH_SMTP "Provide SMTP support" OFF)
111 option(LWS_WITH_ESP8266 "Build for ESP8266" OFF)
112 option(LWS_PLAT_OPTEE "Build for OPTEE" OFF)
113 option(LWS_WITH_NO_LOGS "Disable all logging from being compiled in" OFF)
114 option(LWS_STATIC_PIC "Build the static version of the library with position-independent code" OFF)
115 option(LWS_WITH_RANGES "Support http ranges (RFC7233)" ON)
116 option(LWS_FALLBACK_GETHOSTBYNAME "Also try to do dns resolution using gethostbyname if getaddrinfo fails" OFF)
119 message(STATUS "LWS_WITH_LWSWS --> Enabling LWS_WITH_PLUGINS and LWS_WITH_LIBUV")
120 set(LWS_WITH_PLUGINS 1)
121 set(LWS_WITH_LIBUV 1)
122 set(LWS_WITH_ACCESS_LOG 1)
123 set(LWS_WITH_SERVER_STATUS 1)
125 set(LWS_WITH_LEJP_CONF 1)
128 if (LWS_WITH_PLUGINS AND NOT LWS_WITH_LIBUV)
129 message(STATUS "LWS_WITH_PLUGINS --> Enabling LWS_WITH_LIBUV")
130 set(LWS_WITH_LIBUV 1)
133 if (LWS_WITH_SMTP AND NOT LWS_WITH_LIBUV)
134 message(STATUS "LWS_WITH_SMTP --> Enabling LWS_WITH_LIBUV")
135 set(LWS_WITH_LIBUV 1)
138 if (LWS_WITH_GENERIC_SESSIONS)
139 set(LWS_WITH_SQLITE3 1)
143 if (LWS_WITH_SMTP AND NOT LWS_WITH_LIBUV)
144 message(STATUS "LWS_WITH_SMTP --> Enabling LWS_WITH_LIBUV")
145 set(LWS_WITH_LIBUV 1)
148 if (DEFINED YOTTA_WEBSOCKETS_VERSION_STRING)
150 set(LWS_WITH_SHARED OFF)
151 set(LWS_WITH_SSL OFF)
152 set(LWS_WITH_ZLIB OFF)
153 set(LWS_WITHOUT_CLIENT ON)
154 set(LWS_WITHOUT_TESTAPPS ON)
155 set(LWS_WITHOUT_EXTENSIONS ON)
156 set(LWS_WITH_PLUGINS OFF)
158 # this implies no pthreads in the lib
163 if (LWS_WITH_ESP8266)
164 set(LWS_WITH_SHARED OFF)
165 set(LWS_WITH_SSL OFF)
166 set(LWS_WITH_ZLIB OFF)
167 set(LWS_WITHOUT_CLIENT ON)
168 set(LWS_WITHOUT_TESTAPPS ON)
169 set(LWS_WITHOUT_EXTENSIONS ON)
170 set(LWS_WITH_PLUGINS OFF)
171 set(LWS_WITH_RANGES OFF)
172 # this implies no pthreads in the lib
174 set(LWS_HAVE_MALLOC 1)
175 set(LWS_HAVE_REALLOC 1)
176 set(LWS_HAVE_GETIFADDRS 1)
181 # this implies no pthreads in the lib
186 if (LWS_WITHOUT_SERVER)
187 set(LWS_WITH_LWSWS OFF)
190 if (LWS_WITH_HTTP_PROXY AND (LWS_WITHOUT_CLIENT OR LWS_WITHOUT_SERVER))
191 message(FATAL_ERROR "You have to enable both client and server for http proxy")
194 # Allow the user to override installation directories.
195 set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
196 set(LWS_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
197 set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
198 set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files")
200 # Allow the user to use the old CyaSSL options/library in stead of wolfSSL
201 if (LWS_USE_CYASSL AND LWS_USE_WOLFSSL)
202 message(FATAL_ERROR "LWS_USE_CYASSL and LWS_USE_WOLFSSL are mutually exclusive!")
205 # Copy CyaSSL options to the wolfSSL options
206 set(LWS_USE_WOLFSSL ${LWS_USE_CYASSL} CACHE BOOL "Use wolfSSL/CyaSSL instead of OpenSSL" FORCE)
207 set(LWS_WOLFSSL_LIBRARIES ${LWS_CYASSL_LIBRARIES} CACHE PATH "Path to wolfSSL/CyaSSL libraries" FORCE)
208 set(LWS_WOLFSSL_INCLUDE_DIRS ${LWS_CYASSL_INCLUDE_DIRS} CACHE PATH "Path to wolfSSL/CyaSSL header files" FORCE)
211 if (LWS_WITHOUT_CLIENT AND LWS_WITHOUT_SERVER)
212 message(FATAL_ERROR "Makes no sense to compile with neither client nor server.")
215 if (NOT (LWS_WITH_STATIC OR LWS_WITH_SHARED))
216 message(FATAL_ERROR "Makes no sense to compile with neither static nor shared libraries.")
219 if (NOT LWS_WITHOUT_EXTENSIONS)
220 if (NOT LWS_WITH_ZLIB)
221 message(FATAL_ERROR "zlib is required for extensions.")
225 set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib library")
226 set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib include directory")
227 set(LWS_OPENSSL_LIBRARIES CACHE PATH "Path to the OpenSSL library")
228 set(LWS_OPENSSL_INCLUDE_DIRS CACHE PATH "Path to the OpenSSL include directory")
229 set(LWS_WOLFSSL_LIBRARIES CACHE PATH "Path to the wolfSSL library")
230 set(LWS_WOLFSSL_INCLUDE_DIRS CACHE PATH "Path to the wolfSSL include directory")
231 set( CACHE PATH "Path to the libev library")
232 set(LWS_LIBEV_INCLUDE_DIRS CACHE PATH "Path to the libev include directory")
233 set(LWS_LIBUV_LIBRARIES CACHE PATH "Path to the libuv library")
234 set(LWS_LIBUV_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory")
235 set(LWS_SQLITE3_LIBRARIES CACHE PATH "Path to the libuv library")
236 set(LWS_SQLITE3_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory")
239 if (NOT LWS_WITH_SSL)
240 set(LWS_WITHOUT_BUILTIN_SHA1 OFF)
243 if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL)
244 if ("${LWS_OPENSSL_LIBRARIES}" STREQUAL "" OR "${LWS_OPENSSL_INCLUDE_DIRS}" STREQUAL "")
246 set(OPENSSL_LIBRARIES ${LWS_OPENSSL_LIBRARIES})
247 set(OPENSSL_INCLUDE_DIRS ${LWS_OPENSSL_INCLUDE_DIRS})
252 if (LWS_WITH_SSL AND LWS_USE_WOLFSSL)
253 if ("${LWS_WOLFSSL_LIBRARIES}" STREQUAL "" OR "${LWS_WOLFSSL_INCLUDE_DIRS}" STREQUAL "")
254 if (NOT WOLFSSL_FOUND)
256 message(FATAL_ERROR "You must set LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS when LWS_USE_CYASSL is turned on.")
258 message(FATAL_ERROR "You must set LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS when LWS_USE_WOLFSSL is turned on.")
262 set(WOLFSSL_LIBRARIES ${LWS_WOLFSSL_LIBRARIES})
263 set(WOLFSSL_INCLUDE_DIRS ${LWS_WOLFSSL_INCLUDE_DIRS})
268 set(USE_OLD_CYASSL 1)
272 if (LWS_WITH_SSL AND LWS_USE_MBEDTLS)
273 if ("${LWS_MBEDTLS_LIBRARIES}" STREQUAL "" OR "${LWS_MBEDTLS_INCLUDE_DIRS}" STREQUAL "")
274 if (NOT MBEDTLS_FOUND)
275 message(FATAL_ERROR "You must set LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS when LWS_USE_MBEDTLS is turned on.")
278 set(MBEDTLS_LIBRARIES ${LWS_MBEDTLS_LIBRARIES})
279 set(MBEDTLS_INCLUDE_DIRS ${LWS_MBEDTLS_INCLUDE_DIRS})
285 if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB)
286 if ("${LWS_ZLIB_LIBRARIES}" STREQUAL "" OR "${LWS_ZLIB_INCLUDE_DIRS}" STREQUAL "")
288 set(ZLIB_LIBRARIES ${LWS_ZLIB_LIBRARIES})
289 set(ZLIB_INCLUDE_DIRS ${LWS_ZLIB_INCLUDE_DIRS})
295 if ("${LWS_LIBEV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEV_INCLUDE_DIRS}" STREQUAL "")
297 set(LIBEV_LIBRARIES ${LWS_LIBEV_LIBRARIES})
298 set(LIBEV_INCLUDE_DIRS ${LWS_LIBEV_INCLUDE_DIRS})
304 if ("${LWS_LIBUV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBUV_INCLUDE_DIRS}" STREQUAL "")
306 set(LIBUV_LIBRARIES ${LWS_LIBUV_LIBRARIES})
307 set(LIBUV_INCLUDE_DIRS ${LWS_LIBUV_INCLUDE_DIRS})
312 if (LWS_WITH_SQLITE3)
313 if ("${LWS_SQLITE3_LIBRARIES}" STREQUAL "" OR "${LWS_SQLITE3_INCLUDE_DIRS}" STREQUAL "")
315 set(SQLITE3_LIBRARIES ${LWS_SQLITE3_LIBRARIES})
316 set(SQLITE3_INCLUDE_DIRS ${LWS_SQLITE3_INCLUDE_DIRS})
322 # FIXME: This must be runtime-only option.
323 # The base dir where the test-apps look for the SSL certs.
324 set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory")
326 set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory")
330 message(WARNING "IPv6 does not currently work on Windows!")
333 set(LWS_UNIX_SOCK OFF)
334 message(WARNING "Windows does not support UNIX domain sockets")
337 set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory")
340 if (LWS_WITHOUT_EXTENSIONS)
341 set(LWS_NO_EXTENSIONS 1)
345 set(LWS_OPENSSL_SUPPORT 1)
348 if (LWS_SSL_CLIENT_USE_OS_CA_CERTS)
349 set(LWS_SSL_CLIENT_USE_OS_CA_CERTS 1)
352 if (LWS_WITH_LATENCY)
356 if (LWS_WITHOUT_DAEMONIZE OR WIN32)
357 set(LWS_NO_DAEMONIZE 1)
360 if (LWS_WITHOUT_SERVER)
364 if (LWS_WITHOUT_CLIENT)
381 set(LWS_USE_UNIX_SOCK 1)
388 if ("${LWS_MAX_SMP}" STREQUAL "")
393 if (LWS_WITH_ESP8266)
394 set(CMAKE_C_FLAGS "-nostdlib ${CMAKE_C_FLAGS}")
397 # set(CMAKE_C_FLAGS "-D_DEBUG ${CMAKE_C_FLAGS}")
401 set(LWS_MINGW_SUPPORT 1)
402 set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}")
405 if (LWS_SSL_SERVER_WITH_ECDH_CERT)
406 set(LWS_SSL_SERVER_WITH_ECDH_CERT 1)
409 include_directories("${PROJECT_BINARY_DIR}")
411 include(CheckCSourceCompiles)
413 # Check for different inline keyword versions.
414 foreach(KEYWORD "inline" "__inline__" "__inline")
415 set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}")
416 CHECK_C_SOURCE_COMPILES(
419 static KEYWORD void a() {}
420 int main(int argc, char **argv) { a(); return 0; }
421 " LWS_HAVE_${KEYWORD})
424 if (NOT LWS_HAVE_inline)
425 if (LWS_HAVE___inline__)
426 set(inline __inline__)
427 elseif(LWS_HAVE___inline)
432 # Put the libraries and binaries that get built into directories at the
433 # top of the build tree rather than in hard-to-find leaf directories.
434 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
435 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
436 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
438 SET(LWS_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}")
440 # Put absolute path of dynamic libraries into the object code. Some
441 # architectures, notably Mac OS X, need this.
442 SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}")
444 include(CheckFunctionExists)
445 include(CheckSymbolExists)
446 include(CheckIncludeFile)
447 include(CheckIncludeFiles)
448 include(CheckLibraryExists)
449 include(CheckTypeSize)
451 if (LWS_WITHOUT_BUILTIN_SHA1)
452 set(LWS_SHA1_USE_OPENSSL_NAME 1)
455 CHECK_FUNCTION_EXISTS(bzero LWS_HAVE_BZERO)
456 CHECK_FUNCTION_EXISTS(fork LWS_HAVE_FORK)
457 CHECK_FUNCTION_EXISTS(getenv LWS_HAVE_GETENV)
458 CHECK_FUNCTION_EXISTS(malloc LWS_HAVE_MALLOC)
459 CHECK_FUNCTION_EXISTS(memset LWS_HAVE_MEMSET)
460 CHECK_FUNCTION_EXISTS(realloc LWS_HAVE_REALLOC)
461 CHECK_FUNCTION_EXISTS(socket LWS_HAVE_SOCKET)
462 CHECK_FUNCTION_EXISTS(strerror LWS_HAVE_STRERROR)
463 CHECK_FUNCTION_EXISTS(vfork LWS_HAVE_VFORK)
464 CHECK_FUNCTION_EXISTS(execvpe LWS_HAVE_EXECVPE)
465 CHECK_FUNCTION_EXISTS(getifaddrs LWS_HAVE_GETIFADDRS)
466 CHECK_FUNCTION_EXISTS(snprintf LWS_HAVE_SNPRINTF)
467 CHECK_FUNCTION_EXISTS(_snprintf LWS_HAVE__SNPRINTF)
468 CHECK_FUNCTION_EXISTS(_vsnprintf LWS_HAVE__VSNPRINTF)
469 CHECK_FUNCTION_EXISTS(getloadavg LWS_HAVE_GETLOADAVG)
471 if (NOT LWS_HAVE_GETIFADDRS)
472 if (LWS_WITHOUT_BUILTIN_GETIFADDRS)
473 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.")
475 set(LWS_BUILTIN_GETIFADDRS 1)
478 CHECK_INCLUDE_FILE(dlfcn.h LWS_HAVE_DLFCN_H)
479 CHECK_INCLUDE_FILE(fcntl.h LWS_HAVE_FCNTL_H)
480 CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H)
481 CHECK_INCLUDE_FILE(inttypes.h LWS_HAVE_INTTYPES_H)
482 CHECK_INCLUDE_FILE(memory.h LWS_HAVE_MEMORY_H)
483 CHECK_INCLUDE_FILE(netinet/in.h LWS_HAVE_NETINET_IN_H)
484 CHECK_INCLUDE_FILE(stdint.h LWS_HAVE_STDINT_H)
485 CHECK_INCLUDE_FILE(stdlib.h LWS_HAVE_STDLIB_H)
486 CHECK_INCLUDE_FILE(strings.h LWS_HAVE_STRINGS_H)
487 CHECK_INCLUDE_FILE(string.h LWS_HAVE_STRING_H)
488 CHECK_INCLUDE_FILE(sys/prctl.h LWS_HAVE_SYS_PRCTL_H)
489 CHECK_INCLUDE_FILE(sys/socket.h LWS_HAVE_SYS_SOCKET_H)
490 CHECK_INCLUDE_FILE(sys/sockio.h LWS_HAVE_SYS_SOCKIO_H)
491 CHECK_INCLUDE_FILE(sys/stat.h LWS_HAVE_SYS_STAT_H)
492 CHECK_INCLUDE_FILE(sys/types.h LWS_HAVE_SYS_TYPES_H)
493 CHECK_INCLUDE_FILE(unistd.h LWS_HAVE_UNISTD_H)
494 CHECK_INCLUDE_FILE(vfork.h LWS_HAVE_VFORK_H)
497 CHECK_INCLUDE_FILE(uv-version.h LWS_HAVE_UV_VERSION_H)
501 if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB)
502 CHECK_INCLUDE_FILE(zlib.h LWS_HAVE_ZLIB_H)
505 # TODO: These can also be tested to see whether they actually work...
506 set(LWS_HAVE_WORKING_FORK LWS_HAVE_FORK)
507 set(LWS_HAVE_WORKING_VFORK LWS_HAVE_VFORK)
509 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
511 # These don't work Cross...
512 #CHECK_TYPE_SIZE(pid_t PID_T_SIZE)
513 #CHECK_TYPE_SIZE(size_t SIZE_T_SIZE)
514 #CHECK_TYPE_SIZE("void *" LWS_SIZEOFPTR LANGUAGE C)
521 set(size_t "unsigned int")
524 if (NOT LWS_HAVE_MALLOC)
525 set(malloc rpl_malloc)
528 if (NOT LWS_HAVE_REALLOC)
529 set(realloc rpl_realloc)
534 # Turn off stupid microsoft security warnings.
535 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
538 include_directories("${PROJECT_SOURCE_DIR}/lib")
540 # Group headers and sources.
541 # Some IDEs use this for nicer file structure.
543 lib/private-libwebsockets.h)
546 "${PROJECT_SOURCE_DIR}/lib/libwebsockets.h"
547 "${PROJECT_BINARY_DIR}/lws_config.h")
561 if (NOT LWS_WITHOUT_CLIENT)
564 lib/client-handshake.c
572 if (NOT LWS_WITHOUT_SERVER)
576 if (NOT LWS_WITHOUT_CLIENT)
582 if (NOT LWS_WITHOUT_BUILTIN_SHA1)
593 # select the active platform files
601 lib/lws-plat-mbed3.cpp
602 lib/lws-plat-mbed3.c)
604 if (LWS_WITH_ESP8266)
606 lib/lws-plat-esp8266.c)
610 lib/lws-plat-optee.c)
619 if (NOT LWS_WITHOUT_SERVER)
622 lib/server-handshake.c)
625 if (NOT LWS_WITHOUT_EXTENSIONS)
626 list(APPEND HDR_PRIVATE
627 lib/extension-permessage-deflate.h)
630 lib/extension-permessage-deflate.c)
633 if (LWS_WITH_HTTP_PROXY)
651 list(APPEND HDR_PUBLIC
654 if (LWS_WITH_LEJP_CONF)
670 # Add helper files for Windows.
672 set(WIN32_HELPERS_PATH win32port/win32helpers)
673 include_directories(${WIN32_HELPERS_PATH})
677 ${WIN32_HELPERS_PATH}/gettimeofday.c
680 list(APPEND HDR_PRIVATE
681 ${WIN32_HELPERS_PATH}/gettimeofday.h
687 if (NOT LWS_WITHOUT_DAEMONIZE)
694 if (NOT LWS_HAVE_GETIFADDRS)
695 list(APPEND HDR_PRIVATE lib/getifaddrs.h)
696 list(APPEND SOURCES lib/getifaddrs.c)
700 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
701 include (CheckCCompilerFlag)
702 CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY)
703 if (LWS_HAVE_VISIBILITY)
704 set(VISIBILITY_FLAG -fvisibility=hidden)
706 if (UNIX OR LWS_WITH_ESP8266)
707 set(CMAKE_C_FLAGS "-Wall -Werror ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
709 set(CMAKE_C_FLAGS "-Wall ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
713 if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS)
715 # jeez clang understands -pthread but dies if he sees it at link time!
716 # http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang
717 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
721 if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
722 # otherwise osx blows a bunch of openssl deprecated api errors
723 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" )
726 source_group("Headers Private" FILES ${HDR_PRIVATE})
727 source_group("Headers Public" FILES ${HDR_PUBLIC})
728 source_group("Sources" FILES ${SOURCES})
737 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
739 add_library(websockets STATIC
743 list(APPEND LWS_LIBRARIES websockets)
746 # Windows uses the same .lib ending for static libraries and shared
747 # library linker files, so rename the static library.
748 set_target_properties(websockets
750 OUTPUT_NAME websockets_static)
755 add_library(websockets_shared SHARED
759 list(APPEND LWS_LIBRARIES websockets_shared)
761 # We want the shared lib to be named "libwebsockets"
762 # not "libwebsocket_shared".
763 set_target_properties(websockets_shared
765 OUTPUT_NAME websockets)
768 # Compile as DLL (export function declarations)
770 TARGET websockets_shared
771 PROPERTY COMPILE_DEFINITIONS
777 set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES)
781 # Set the so version of the lib.
782 # Equivalent to LDFLAGS=-version-info x:x:x
783 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
784 foreach(lib ${LWS_LIBRARIES})
785 set_target_properties(${lib}
787 SOVERSION ${SOVERSION})
798 # ZLIB (Only needed for deflate extensions).
801 if (LWS_USE_BUNDLED_ZLIB)
803 set(WIN32_ZLIB_PATH "win32port/zlib")
805 ${WIN32_ZLIB_PATH}/adler32.c
806 ${WIN32_ZLIB_PATH}/compress.c
807 ${WIN32_ZLIB_PATH}/crc32.c
808 ${WIN32_ZLIB_PATH}/deflate.c
809 ${WIN32_ZLIB_PATH}/gzclose.c
810 ${WIN32_ZLIB_PATH}/gzio.c
811 ${WIN32_ZLIB_PATH}/gzlib.c
812 ${WIN32_ZLIB_PATH}/gzread.c
813 ${WIN32_ZLIB_PATH}/gzwrite.c
814 ${WIN32_ZLIB_PATH}/infback.c
815 ${WIN32_ZLIB_PATH}/inffast.c
816 ${WIN32_ZLIB_PATH}/inflate.c
817 ${WIN32_ZLIB_PATH}/inftrees.c
818 ${WIN32_ZLIB_PATH}/trees.c
819 ${WIN32_ZLIB_PATH}/uncompr.c
820 ${WIN32_ZLIB_PATH}/zutil.c)
821 add_library(zlib_internal STATIC ${ZLIB_SRCS})
822 set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
823 get_property(ZLIB_LIBRARIES TARGET zlib_internal PROPERTY LOCATION)
825 # Make sure zlib_internal is compiled before the libs.
826 foreach (lib ${LWS_LIBRARIES})
827 add_dependencies(${lib} zlib_internal)
830 message(FATAL_ERROR "Don't have bundled zlib for that platform")
832 elseif (NOT ZLIB_FOUND)
833 find_package(ZLIB REQUIRED)
835 message("zlib include dirs: ${ZLIB_INCLUDE_DIRS}")
836 message("zlib libraries: ${ZLIB_LIBRARIES}")
837 include_directories(${ZLIB_INCLUDE_DIRS})
838 list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
845 message("Compiling with SSL support")
848 # Use wolfSSL as OpenSSL replacement.
849 # TODO: Add a find_package command for this also.
850 message("wolfSSL include dir: ${WOLFSSL_INCLUDE_DIRS}")
851 message("wolfSSL libraries: ${WOLFSSL_LIBRARIES}")
853 # Additional to the root directory we need to include
854 # the wolfssl/ subdirectory which contains the OpenSSL
855 # compatibility layer headers.
858 foreach(inc ${WOLFSSL_INCLUDE_DIRS})
859 include_directories("${inc}" "${inc}/cyassl")
862 foreach(inc ${WOLFSSL_INCLUDE_DIRS})
863 include_directories("${inc}" "${inc}/wolfssl")
867 list(APPEND LIB_LIST "${WOLFSSL_LIBRARIES}")
872 if (NOT OPENSSL_FOUND AND NOT LWS_USE_BORINGSSL)
873 # TODO: Add support for STATIC also.
874 find_package(OpenSSL REQUIRED)
875 set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}")
878 message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}")
879 message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
881 include_directories("${OPENSSL_INCLUDE_DIRS}")
882 list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
884 # older (0.98) Openssl lacks this
885 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
886 check_include_file(openssl/ecdh.h LWS_HAVE_OPENSSL_ECDH_H)
888 if (LWS_SSL_SERVER_WITH_ECDH_CERT AND NOT LWS_HAVE_OPENSSL_ECDH_H)
889 message(FATAL_ERROR "Missing openssl/ecdh.h, so cannot use LWS_SSL_SERVER_WITH_ECDH_CERT")
897 find_path(LIBEV_INCLUDE_DIRS NAMES ev.h)
898 find_library(LIBEV_LIBRARIES NAMES ev)
899 if(LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES)
903 message("libev include dir: ${LIBEV_INCLUDE_DIRS}")
904 message("libev libraries: ${LIBEV_LIBRARIES}")
905 include_directories("${LIBEV_INCLUDE_DIRS}")
906 list(APPEND LIB_LIST ${LIBEV_LIBRARIES})
907 endif(LWS_WITH_LIBEV)
911 find_path(LIBUV_INCLUDE_DIRS NAMES uv.h)
912 find_library(LIBUV_LIBRARIES NAMES uv)
913 if(LIBUV_INCLUDE_DIRS AND LIBUV_LIBRARIES)
917 message("libuv include dir: ${LIBUV_INCLUDE_DIRS}")
918 message("libuv libraries: ${LIBUV_LIBRARIES}")
919 include_directories("${LIBUV_INCLUDE_DIRS}")
920 list(APPEND LIB_LIST ${LIBUV_LIBRARIES})
923 if (LWS_WITH_SQLITE3)
924 if (NOT SQLITE3_FOUND)
925 find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h)
926 find_library(SQLITE3_LIBRARIES NAMES sqlite3)
927 if(SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
931 message("sqlite3 include dir: ${SQLITE3_INCLUDE_DIRS}")
932 message("sqlite3 libraries: ${SQLITE3_LIBRARIES}")
933 include_directories("${SQLITE3_INCLUDE_DIRS}")
934 list(APPEND LIB_LIST ${SQLITE3_LIBRARIES})
938 if (LWS_WITH_HTTP_PROXY)
939 find_library(LIBHUBBUB_LIBRARIES NAMES hubbub)
940 list(APPEND LIB_LIST ${LIBHUBBUB_LIBRARIES} )
945 # Platform specific libs.
948 list(APPEND LIB_LIST ws2.lib)
950 list(APPEND LIB_LIST ws2_32.lib userenv.lib psapi.lib iphlpapi.lib)
954 list(APPEND LIB_LIST m)
957 # Setup the linking for all libs.
958 foreach (lib ${LWS_LIBRARIES})
959 target_link_libraries(${lib} ${LIB_LIST})
962 set (temp ${CMAKE_REQUIRED_LIBRARIES})
963 set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST})
964 CHECK_FUNCTION_EXISTS(SSL_CTX_set1_param LWS_HAVE_SSL_CTX_set1_param)
965 CHECK_FUNCTION_EXISTS(X509_VERIFY_PARAM_set1_host LWS_HAVE_X509_VERIFY_PARAM_set1_host)
966 set(CMAKE_REQUIRED_LIBRARIES ${temp})
967 # Generate the lws_config.h that includes all the public compilation settings.
969 "${PROJECT_SOURCE_DIR}/lws_config.h.in"
970 "${PROJECT_BINARY_DIR}/lws_config.h")
972 # Generate the lws_config.h that includes all the private compilation settings.
974 "${PROJECT_SOURCE_DIR}/lws_config_private.h.in"
975 "${PROJECT_BINARY_DIR}/lws_config_private.h")
983 if (NOT LWS_WITHOUT_TESTAPPS)
985 # Helper function for adding a test app.
987 macro(create_test_app TEST_NAME MAIN_SRC S2 S3 S4 S5 S6)
989 set(TEST_SRCS ${MAIN_SRC})
991 if ("${S2}" STREQUAL "")
993 list(APPEND TEST_SRCS ${S2})
995 if ("${S3}" STREQUAL "")
997 list(APPEND TEST_SRCS ${S3})
999 if ("${S4}" STREQUAL "")
1001 list(APPEND TEST_SRCS ${S4})
1003 if ("${S5}" STREQUAL "")
1005 list(APPEND TEST_SRCS ${S5})
1007 if ("${S6}" STREQUAL "")
1009 list(APPEND TEST_SRCS ${S6})
1012 list(APPEND TEST_SRCS
1013 ${WIN32_HELPERS_PATH}/getopt.c
1014 ${WIN32_HELPERS_PATH}/getopt_long.c
1015 ${WIN32_HELPERS_PATH}/gettimeofday.c
1018 list(APPEND TEST_HDR
1019 ${WIN32_HELPERS_PATH}/getopt.h
1020 ${WIN32_HELPERS_PATH}/gettimeofday.h
1024 source_group("Headers Private" FILES ${TEST_HDR})
1025 source_group("Sources" FILES ${TEST_SRCS})
1026 add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
1028 if (LWS_LINK_TESTAPPS_DYNAMIC)
1029 if (NOT LWS_WITH_SHARED)
1030 message(FATAL_ERROR "Build of the shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.")
1032 target_link_libraries(${TEST_NAME} websockets_shared)
1033 add_dependencies(${TEST_NAME} websockets_shared)
1035 if (NOT LWS_WITH_STATIC)
1036 message(FATAL_ERROR "Build of the static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.")
1038 target_link_libraries(${TEST_NAME} websockets)
1039 add_dependencies(${TEST_NAME} websockets)
1042 # Set test app specific defines.
1043 set_property(TARGET ${TEST_NAME}
1044 PROPERTY COMPILE_DEFINITIONS
1045 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1048 # Prefix the binary names with libwebsockets.
1049 set_target_properties(${TEST_NAME}
1051 OUTPUT_NAME libwebsockets-${TEST_NAME})
1053 # Add to the list of tests.
1054 list(APPEND TEST_APP_LIST ${TEST_NAME})
1057 if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL)
1058 message("Searching for OpenSSL executable and dlls")
1059 find_package(OpenSSLbins)
1060 message("OpenSSL executable: ${OPENSSL_EXECUTABLE}")
1063 if (UNIX AND LWS_WITH_PLUGINS)
1064 set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
1065 if(NOT(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD"))
1066 target_link_libraries(websockets dl)
1070 if (NOT LWS_WITHOUT_SERVER)
1074 if (NOT LWS_WITHOUT_TEST_SERVER)
1075 create_test_app(test-server "test-server/test-server.c"
1076 "test-server/test-server-http.c"
1077 "test-server/test-server-dumb-increment.c"
1078 "test-server/test-server-mirror.c"
1079 "test-server/test-server-status.c"
1080 "test-server/test-server-echogen.c")
1082 create_test_app(test-fuzxy "test-server/fuzxy.c"
1089 if (UNIX AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")))
1090 create_test_app(test-server-pthreads
1091 "test-server/test-server-pthreads.c"
1092 "test-server/test-server-http.c"
1093 "test-server/test-server-dumb-increment.c"
1094 "test-server/test-server-mirror.c"
1095 "test-server/test-server-status.c"
1096 "test-server/test-server-echogen.c")
1098 if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
1100 create_test_app(test-server-libev
1101 "test-server/test-server-libev.c"
1102 "test-server/test-server-http.c"
1103 "test-server/test-server-dumb-increment.c"
1104 "test-server/test-server-mirror.c"
1105 "test-server/test-server-status.c"
1106 "test-server/test-server-echogen.c")
1108 if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
1110 create_test_app(test-server-libuv
1111 "test-server/test-server-libuv.c"
1112 "test-server/test-server-http.c"
1113 "test-server/test-server-dumb-increment.c"
1114 "test-server/test-server-mirror.c"
1115 "test-server/test-server-status.c"
1116 "test-server/test-server-echogen.c")
1121 # test-server-extpoll
1123 if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL)
1124 create_test_app(test-server-extpoll "test-server/test-server.c"
1125 "test-server/test-server-http.c"
1126 "test-server/test-server-dumb-increment.c"
1127 "test-server/test-server-mirror.c"
1128 "test-server/test-server-status.c"
1129 "test-server/test-server-echogen.c")
1130 # Set defines for this executable only.
1132 TARGET test-server-extpoll
1133 PROPERTY COMPILE_DEFINITIONS
1135 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1138 # We need to link against winsock code.
1140 target_link_libraries(test-server-extpoll ws2_32.lib)
1147 if (LWS_WITH_PLUGINS)
1150 "test-server/test-server-v2.0.c"
1158 # Data files for running the test server.
1159 set(TEST_SERVER_DATA
1160 "${PROJECT_SOURCE_DIR}/test-server/favicon.ico"
1161 "${PROJECT_SOURCE_DIR}/test-server/leaf.jpg"
1162 "${PROJECT_SOURCE_DIR}/test-server/libwebsockets.org-logo.png"
1163 "${PROJECT_SOURCE_DIR}/test-server/lws-common.js"
1164 "${PROJECT_SOURCE_DIR}/test-server/test.html")
1166 # Generate self-signed SSL certs for the test-server.
1167 if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER)
1168 message("Generating SSL Certificates for the test-server...")
1170 set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem")
1171 set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem")
1175 message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -subj \"/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost\" -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
1177 COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -subj "/C=GB/ST=Erewhon/L=All around/O=libwebsockets-test/CN=localhost" -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1178 RESULT_VARIABLE OPENSSL_RETURN_CODE)
1180 file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt"
1184 "libwebsockets-test\n"
1186 "none@invalid.org\n\n"
1189 # The "type" command is a bit picky with paths.
1190 file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
1191 message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
1192 message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
1195 COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
1196 COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1197 RESULT_VARIABLE OPENSSL_RETURN_CODE
1198 OUTPUT_QUIET ERROR_QUIET)
1203 if (OPENSSL_RETURN_CODE)
1204 message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
1206 message("SUCCSESFULLY generated SSL certificate")
1211 COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n"
1212 COMMAND "${OPENSSL_EXECUTABLE}"
1213 req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1214 RESULT_VARIABLE OPENSSL_RETURN_CODE
1215 OUTPUT_QUIET ERROR_QUIET)
1217 if (OPENSSL_RETURN_CODE)
1218 message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
1220 message("SUCCESSFULLY generated SSL certificate")
1224 list(APPEND TEST_SERVER_DATA
1225 "${TEST_SERVER_SSL_KEY}"
1226 "${TEST_SERVER_SSL_CERT}")
1229 add_custom_command(TARGET test-server
1231 COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server")
1233 # Copy the file needed to run the server so that the test apps can
1234 # reach them from their default output location
1235 foreach (TEST_FILE ${TEST_SERVER_DATA})
1236 if (EXISTS ${TEST_FILE})
1237 add_custom_command(TARGET test-server
1239 COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM)
1242 endif(NOT LWS_WITHOUT_SERVER)
1244 if (NOT LWS_WITHOUT_CLIENT)
1248 if (NOT LWS_WITHOUT_TEST_CLIENT)
1249 create_test_app(test-client "test-server/test-client.c" "" "" "" "" "")
1255 if (NOT LWS_WITHOUT_TEST_FRAGGLE)
1256 create_test_app(test-fraggle "test-server/test-fraggle.c" "" "" "" "" "")
1262 if (NOT LWS_WITHOUT_TEST_PING)
1263 create_test_app(test-ping "test-server/test-ping.c" "" "" "" "" "")
1268 if (NOT LWS_WITHOUT_TEST_ECHO)
1269 create_test_app(test-echo "test-server/test-echo.c" "" "" "" "" "")
1272 endif(NOT LWS_WITHOUT_CLIENT)
1275 if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
1276 macro(create_plugin PLUGIN_NAME MAIN_SRC S2 S3)
1278 set(PLUGIN_SRCS ${MAIN_SRC})
1280 if ("${S2}" STREQUAL "")
1282 list(APPEND PLUGIN_SRCS ${S2})
1284 if ("${S3}" STREQUAL "")
1286 list(APPEND PLUGIN_SRCS ${S3})
1290 list(APPEND PLUGIN_SRCS
1291 ${WIN32_HELPERS_PATH}/getopt.c
1292 ${WIN32_HELPERS_PATH}/getopt_long.c
1293 ${WIN32_HELPERS_PATH}/gettimeofday.c
1296 list(APPEND PLUGIN_HDR
1297 ${WIN32_HELPERS_PATH}/getopt.h
1298 ${WIN32_HELPERS_PATH}/gettimeofday.h
1302 source_group("Headers Private" FILES ${PLUGIN_HDR})
1303 source_group("Sources" FILES ${PLUGIN_SRCS})
1304 add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR})
1306 target_link_libraries(${PLUGIN_NAME} websockets_shared)
1307 add_dependencies(${PLUGIN_NAME} websockets_shared)
1309 # Set test app specific defines.
1310 set_property(TARGET ${PLUGIN_NAME}
1311 PROPERTY COMPILE_DEFINITIONS
1312 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
1315 # set_target_properties(${PLUGIN_NAME}
1317 # OUTPUT_NAME ${PLUGIN_NAME})
1319 list(APPEND PLUGINS_LIST ${PLUGIN_NAME})
1324 create_plugin(protocol_dumb_increment
1325 "plugins/protocol_dumb_increment.c" "" "")
1326 create_plugin(protocol_lws_mirror
1327 "plugins/protocol_lws_mirror.c" "" "")
1328 create_plugin(protocol_lws_status
1329 "plugins/protocol_lws_status.c" "" "")
1330 create_plugin(protocol_post_demo
1331 "plugins/protocol_post_demo.c" "" "")
1332 create_plugin(protocol_lws_table_dirlisting
1333 "plugins/generic-table/protocol_table_dirlisting.c" "" "")
1335 if (LWS_WITH_SERVER_STATUS)
1336 create_plugin(protocol_lws_server_status
1337 "plugins/protocol_lws_server_status.c" "" "")
1340 if (NOT LWS_WITHOUT_CLIENT)
1341 create_plugin(protocol_client_loopback_test
1342 "plugins/protocol_client_loopback_test.c" "" "")
1343 endif(NOT LWS_WITHOUT_CLIENT)
1345 if (LWS_WITH_GENERIC_SESSIONS)
1346 create_plugin(protocol_generic_sessions
1347 "plugins/generic-sessions/protocol_generic_sessions.c"
1348 "plugins/generic-sessions/utils.c"
1349 "plugins/generic-sessions/handlers.c")
1352 target_link_libraries(protocol_generic_sessions ${LWS_SQLITE3_LIBRARIES})
1354 target_link_libraries(protocol_generic_sessions sqlite3 )
1357 create_plugin(protocol_lws_messageboard
1358 "plugins/generic-sessions/protocol_lws_messageboard.c" "" "")
1360 target_link_libraries(protocol_lws_messageboard ${LWS_SQLITE3_LIBRARIES})
1362 target_link_libraries(protocol_lws_messageboard sqlite3 )
1365 endif(LWS_WITH_GENERIC_SESSIONS)
1368 endif(LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
1371 # Copy OpenSSL dlls to the output directory on Windows.
1372 # (Otherwise we'll get an error when trying to run)
1374 if (WIN32 AND LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL)
1375 if(OPENSSL_BIN_FOUND)
1376 message("OpenSSL dlls found:")
1377 message(" Libeay: ${LIBEAY_BIN}")
1378 message(" SSLeay: ${SSLEAY_BIN}")
1380 foreach(TARGET_BIN ${TEST_APP_LIST})
1381 add_custom_command(TARGET ${TARGET_BIN}
1383 COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
1384 add_custom_command(TARGET ${TARGET_BIN}
1386 COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
1390 endif(NOT LWS_WITHOUT_TESTAPPS)
1393 list(APPEND LWSWS_SRCS
1398 list(APPEND LWSWS_SRCS
1399 ${WIN32_HELPERS_PATH}/getopt.c
1400 ${WIN32_HELPERS_PATH}/getopt_long.c
1401 ${WIN32_HELPERS_PATH}/gettimeofday.c
1404 list(APPEND LWSWS_HDR
1405 ${WIN32_HELPERS_PATH}/getopt.h
1406 ${WIN32_HELPERS_PATH}/gettimeofday.h
1410 source_group("Headers Private" FILES ${LWSWS_HDR})
1411 source_group("Sources" FILES ${LWSWS_SRCS})
1412 add_executable("lwsws" ${LWSWS_SRCS} ${LWSWS_HDR})
1414 target_link_libraries("lwsws" websockets_shared)
1415 add_dependencies("lwsws" websockets_shared)
1417 # Set test app specific defines.
1418 set_property(TARGET "lwsws"
1419 PROPERTY COMPILE_DEFINITIONS
1420 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1422 endif (LWS_WITH_LWSWS)
1426 # Generate and install pkgconfig.
1427 # (This is not indented, because the tabs will be part of the output)
1428 file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc"
1429 "prefix=\"${CMAKE_INSTALL_PREFIX}\"
1430 exec_prefix=\${prefix}
1431 libdir=\${exec_prefix}/lib${LIB_SUFFIX}
1432 includedir=\${prefix}/include
1435 Description: Websockets server and client library
1436 Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
1438 Libs: -L\${libdir} -lwebsockets
1439 Cflags: -I\${includedir}"
1442 install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc"
1443 DESTINATION lib${LIB_SUFFIX}/pkgconfig)
1447 # Installation preparations.
1450 if(WIN32 AND NOT CYGWIN)
1451 set(DEF_INSTALL_CMAKE_DIR cmake)
1453 set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets)
1456 set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
1458 # Export targets (This is used for other CMake projects to easily find the libraries and include files).
1459 export(TARGETS ${LWS_LIBRARIES}
1460 FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
1461 export(PACKAGE libwebsockets)
1463 # Generate the config file for the build-tree.
1464 set(LWS__INCLUDE_DIRS
1465 "${PROJECT_SOURCE_DIR}/lib"
1466 "${PROJECT_BINARY_DIR}")
1467 set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories")
1468 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
1469 ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake
1472 # Generate the config file for the installation tree.
1473 get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE)
1474 get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE)
1477 "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}"
1478 "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir.
1480 # Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in,
1481 # we escape it here so it's evaluated when it is included instead
1482 # so that the include dirs are given relative to where the
1483 # config file is located.
1484 set(LWS__INCLUDE_DIRS
1485 "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}")
1486 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
1487 ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake
1490 # Generate version info for both build-tree and install-tree.
1491 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in
1492 ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake
1495 set_target_properties(${LWS_LIBRARIES}
1496 PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
1502 # Install libs and headers.
1503 install(TARGETS ${LWS_LIBRARIES}
1504 EXPORT LibwebsocketsTargets
1505 LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
1506 ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
1507 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT libraries # Windows DLLs
1508 PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
1509 set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
1510 set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files")
1512 # Install test apps.
1513 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_CLIENT)
1514 install(TARGETS test-client ${TEST_APP_LIST}
1515 RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR}
1517 set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files")
1522 install(TARGETS lwsws
1523 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT lwsws )
1526 # Programs shared files used by the test-server.
1527 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_SERVER)
1528 install(FILES ${TEST_SERVER_DATA}
1529 DESTINATION share/libwebsockets-test-server
1532 install(FILES "${PROJECT_SOURCE_DIR}/test-server/private/index.html"
1533 DESTINATION share/libwebsockets-test-server/private
1536 set(CGI_TEST_SCRIPT "${PROJECT_SOURCE_DIR}/test-server/lws-cgi-test.sh")
1537 install(FILES ${CGI_TEST_SCRIPT}
1538 PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
1539 DESTINATION share/libwebsockets-test-server
1546 if (LWS_WITH_PLUGINS)
1547 install(TARGETS ${PLUGINS_LIST}
1548 PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
1549 DESTINATION share/libwebsockets-test-server/plugins
1551 if (LWS_WITH_SERVER_STATUS)
1552 install(FILES plugins/server-status.html;plugins/lwsws-logo.png
1553 DESTINATION share/libwebsockets-test-server/server-status
1556 if (LWS_WITH_GENERIC_SESSIONS)
1558 plugins/generic-sessions/assets/lwsgs-logo.png
1559 plugins/generic-sessions/assets/seats.jpg
1560 plugins/generic-sessions/assets/failed-login.html
1561 plugins/generic-sessions/assets/lwsgs.js
1562 plugins/generic-sessions/assets/post-register-fail.html
1563 plugins/generic-sessions/assets/post-register-ok.html
1564 plugins/generic-sessions/assets/post-verify-ok.html
1565 plugins/generic-sessions/assets/post-verify-fail.html
1566 plugins/generic-sessions/assets/sent-forgot-ok.html
1567 plugins/generic-sessions/assets/sent-forgot-fail.html
1568 plugins/generic-sessions/assets/post-forgot-ok.html
1569 plugins/generic-sessions/assets/post-forgot-fail.html
1570 plugins/generic-sessions/assets/index.html
1571 DESTINATION share/libwebsockets-test-server/generic-sessions
1573 install(FILES plugins/generic-sessions/assets/successful-login.html
1574 DESTINATION share/libwebsockets-test-server/generic-sessions/needauth
1576 install(FILES plugins/generic-sessions/assets/admin-login.html
1577 DESTINATION share/libwebsockets-test-server/generic-sessions/needadmin
1582 plugins/generic-table/assets/lwsgt.js
1583 plugins/generic-table/assets/index.html
1584 DESTINATION share/libwebsockets-test-server/generic-table
1589 # Install the LibwebsocketsConfig.cmake and LibwebsocketsConfigVersion.cmake
1591 "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake"
1592 "${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake"
1593 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
1595 # Install exports for the install-tree.
1596 install(EXPORT LibwebsocketsTargets
1597 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
1599 # build subdir is not part of sources
1600 set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) ".git" "build" "tgz" "tar.gz")
1602 # Most people are more used to "make dist" compared to "make package_source"
1603 add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source)
1605 include(UseRPMTools)
1607 RPMTools_ADD_RPM_TARGETS(libwebsockets libwebsockets.spec)
1610 message("---------------------------------------------------------------------")
1611 message(" Settings: (For more help do cmake -LH <srcpath>)")
1612 message("---------------------------------------------------------------------")
1613 message(" LWS_WITH_STATIC = ${LWS_WITH_STATIC}")
1614 message(" LWS_WITH_SHARED = ${LWS_WITH_SHARED}")
1615 message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)")
1616 message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}")
1617 message(" LWS_USE_WOLFSSL = ${LWS_USE_WOLFSSL} (wolfSSL/CyaSSL replacement for OpenSSL)")
1618 if (LWS_USE_WOLFSSL)
1619 message(" LWS_WOLFSSL_LIBRARIES = ${LWS_WOLFSSL_LIBRARIES}")
1620 message(" LWS_WOLFSSL_INCLUDE_DIRS = ${LWS_WOLFSSL_INCLUDE_DIRS}")
1622 message(" LWS_WITHOUT_BUILTIN_SHA1 = ${LWS_WITHOUT_BUILTIN_SHA1}")
1623 message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}")
1624 message(" LWS_WITHOUT_CLIENT = ${LWS_WITHOUT_CLIENT}")
1625 message(" LWS_WITHOUT_SERVER = ${LWS_WITHOUT_SERVER}")
1626 message(" LWS_LINK_TESTAPPS_DYNAMIC = ${LWS_LINK_TESTAPPS_DYNAMIC}")
1627 message(" LWS_WITHOUT_TESTAPPS = ${LWS_WITHOUT_TESTAPPS}")
1628 message(" LWS_WITHOUT_TEST_SERVER = ${LWS_WITHOUT_TEST_SERVER}")
1629 message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}")
1630 message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}")
1631 message(" LWS_WITHOUT_TEST_ECHO = ${LWS_WITHOUT_TEST_ECHO}")
1632 message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}")
1633 message(" LWS_WITHOUT_TEST_FRAGGLE = ${LWS_WITHOUT_TEST_FRAGGLE}")
1634 message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}")
1635 message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}")
1636 message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}")
1637 message(" LWS_USE_LIBEV = ${LWS_USE_LIBEV}")
1638 message(" LWS_USE_LIBUV = ${LWS_USE_LIBUV}")
1639 message(" LWS_IPV6 = ${LWS_IPV6}")
1640 message(" LWS_UNIX_SOCK = ${LWS_UNIX_SOCK}")
1641 message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}")
1642 message(" LWS_MBED3 = ${LWS_MBED3}")
1643 message(" LWS_SSL_SERVER_WITH_ECDH_CERT = ${LWS_SSL_SERVER_WITH_ECDH_CERT}")
1644 message(" LWS_MAX_SMP = ${LWS_MAX_SMP}")
1645 message(" LWS_WITH_CGI = ${LWS_WITH_CGI}")
1646 message(" LWS_HAVE_OPENSSL_ECDH_H = ${LWS_HAVE_OPENSSL_ECDH_H}")
1647 message(" LWS_HAVE_SSL_CTX_set1_param = ${LWS_HAVE_SSL_CTX_set1_param}")
1648 message(" LWS_WITH_HTTP_PROXY = ${LWS_WITH_HTTP_PROXY}")
1649 message(" LIBHUBBUB_LIBRARIES = ${LIBHUBBUB_LIBRARIES}")
1650 message(" PLUGINS = ${PLUGINS_LIST}")
1651 message(" LWS_WITH_ACCESS_LOG = ${LWS_WITH_ACCESS_LOG}")
1652 message(" LWS_WITH_SERVER_STATUS = ${LWS_WITH_SERVER_STATUS}")
1653 message(" LWS_WITH_LEJP = ${LWS_WITH_LEJP}")
1654 message(" LWS_WITH_LEJP_CONF = ${LWS_WITH_LEJP_CONF}")
1655 message(" LWS_WITH_SMTP = ${LWS_WITH_SMTP}")
1656 message(" LWS_WITH_GENERIC_SESSIONS = ${LWS_WITH_GENERIC_SESSIONS}")
1657 message(" LWS_STATIC_PIC = ${LWS_STATIC_PIC}")
1658 message(" LWS_WITH_RANGES = ${LWS_WITH_RANGES}")
1659 message(" LWS_PLAT_OPTEE = ${LWS_PLAT_OPTEE}")
1661 message("---------------------------------------------------------------------")
1663 # These will be available to parent projects including libwebsockets using add_subdirectory()
1664 set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries")
1665 if (LWS_WITH_STATIC)
1666 set(LIBWEBSOCKETS_LIBRARIES_STATIC websocket CACHE STRING "Libwebsocket static library")
1668 if (LWS_WITH_SHARED)
1669 set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library")
1672 # This must always be last!