1 cmake_minimum_required(VERSION 2.8)
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 "0")
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 set(CPACK_SOURCE_GENERATOR "TGZ")
19 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
20 set(VERSION "${CPACK_PACKAGE_VERSION}")
22 set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION})
23 set(LWS_LIBRARY_VERSION_MAJOR ${CPACK_PACKAGE_VERSION_MAJOR})
24 set(LWS_LIBRARY_VERSION_MINOR ${CPACK_PACKAGE_VERSION_MINOR})
25 set(LWS_LIBRARY_VERSION_PATCH ${CPACK_PACKAGE_VERSION_PATCH})
27 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
29 message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
31 # Try to find the current Git hash.
35 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
36 COMMAND "${GIT_EXECUTABLE}" describe
37 OUTPUT_VARIABLE GIT_HASH
38 OUTPUT_STRIP_TRAILING_WHITESPACE
41 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
43 OUTPUT_VARIABLE GIT_USER
44 OUTPUT_STRIP_TRAILING_WHITESPACE
47 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
49 OUTPUT_VARIABLE GIT_HOST
50 OUTPUT_STRIP_TRAILING_WHITESPACE
52 string(REGEX REPLACE "([^\\])[\\]([^\\])" "\\1\\\\\\\\\\2" GIT_USER ${GIT_USER})
53 set(LWS_BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH})
54 message("Git commit hash: ${LWS_BUILD_HASH}")
57 set(LWS_USE_BUNDLED_ZLIB_DEFAULT OFF)
59 set(LWS_USE_BUNDLED_ZLIB_DEFAULT ON)
62 option(LWS_WITH_STATIC "Build the static version of the library" ON)
63 option(LWS_WITH_SHARED "Build the shared version of the library" ON)
64 option(LWS_WITH_SSL "Include SSL support (default OpenSSL, wolfSSL if LWS_USE_WOLFSSL is set)" ON)
65 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)
66 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)
67 option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" ON)
68 option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
69 option(LWS_WITH_LIBUV "Compile with support for libuv" OFF)
70 option(LWS_USE_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_USE_BUNDLED_ZLIB_DEFAULT})
71 option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of the OS-installed CA root certs" ON)
72 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)
73 option(LWS_WITHOUT_BUILTIN_SHA1 "Don't build the lws sha-1 (eg, because openssl will provide it" OFF)
74 option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF)
75 option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF)
76 option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF)
77 option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
78 option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF)
79 option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF)
80 option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF)
81 option(LWS_WITHOUT_TEST_ECHO "Don't build the echo test application" OFF)
82 option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
83 option(LWS_WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF)
84 option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" OFF)
85 option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF)
86 option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON)
87 option(LWS_IPV6 "Compile with support for ipv6" OFF)
88 option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket" OFF)
89 option(LWS_WITH_HTTP2 "Compile with support for http2" OFF)
90 option(LWS_MBED3 "Platform is MBED3" OFF)
91 option(LWS_SSL_SERVER_WITH_ECDH_CERT "Include SSL server use ECDH certificate" OFF)
92 option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out/err) APIs" OFF)
93 option(LWS_WITH_HTTP_PROXY "Support for rewriting HTTP proxying" OFF)
94 option(LWS_WITH_LWSWS "Libwebsockets Webserver" OFF)
95 option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions" OFF)
96 option(LWS_WITH_ACCESS_LOG "Support generating Apache-compatible access logs" OFF)
97 option(LWS_WITH_SERVER_STATUS "Support json + jscript server monitoring" OFF)
98 option(LWS_WITH_LEJP "With the Lightweight JSON Parser" OFF)
99 option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF)
100 option(LWS_WITH_GENERIC_SESSIONS "With the Generic Sessions plugin" OFF)
101 option(LWS_WITH_SQLITE3 "Require SQLITE3 support" OFF)
102 option(LWS_WITH_SMTP "Provide SMTP support" OFF)
103 option(LWS_WITH_ESP8266 "Build for ESP8266" OFF)
104 option(LWS_WITH_NO_LOGS "Disable all logging from being compiled in" OFF)
107 message(STATUS "LWS_WITH_LWSWS --> Enabling LWS_WITH_PLUGINS and LWS_WITH_LIBUV")
108 set(LWS_WITH_PLUGINS 1)
109 set(LWS_WITH_LIBUV 1)
110 set(LWS_WITH_ACCESS_LOG 1)
111 set(LWS_WITH_SERVER_STATUS 1)
113 set(LWS_WITH_LEJP_CONF 1)
116 if (LWS_WITH_PLUGINS AND NOT LWS_WITH_LIBUV)
117 message(STATUS "LWS_WITH_PLUGINS --> Enabling LWS_WITH_LIBUV")
118 set(LWS_WITH_LIBUV 1)
121 if (LWS_WITH_SMTP AND NOT LWS_WITH_LIBUV)
122 message(STATUS "LWS_WITH_SMTP --> Enabling LWS_WITH_LIBUV")
123 set(LWS_WITH_LIBUV 1)
126 if (LWS_WITH_GENERIC_SESSIONS)
127 set(LWS_WITH_SQLITE3 1)
131 if (LWS_WITH_SMTP AND NOT LWS_WITH_LIBUV)
132 message(STATUS "LWS_WITH_SMTP --> Enabling LWS_WITH_LIBUV")
133 set(LWS_WITH_LIBUV 1)
136 if (DEFINED YOTTA_WEBSOCKETS_VERSION_STRING)
138 set(LWS_WITH_SHARED OFF)
139 set(LWS_WITH_SSL OFF)
140 set(LWS_WITH_ZLIB OFF)
141 set(LWS_WITHOUT_CLIENT ON)
142 set(LWS_WITHOUT_TESTAPPS ON)
143 set(LWS_WITHOUT_EXTENSIONS ON)
144 set(LWS_WITH_PLUGINS OFF)
146 # this implies no pthreads in the lib
151 if (LWS_WITH_ESP8266)
152 set(LWS_WITH_SHARED OFF)
153 set(LWS_WITH_SSL OFF)
154 set(LWS_WITH_ZLIB OFF)
155 set(LWS_WITHOUT_CLIENT ON)
156 set(LWS_WITHOUT_TESTAPPS ON)
157 set(LWS_WITHOUT_EXTENSIONS ON)
158 set(LWS_WITH_PLUGINS OFF)
159 # this implies no pthreads in the lib
161 set(LWS_HAVE_MALLOC 1)
162 set(LWS_HAVE_REALLOC 1)
163 set(LWS_HAVE_GETIFADDRS 1)
168 # this implies no pthreads in the lib
173 if (LWS_WITHOUT_SERVER)
174 set(LWS_WITH_LWSWS OFF)
177 if (LWS_WITH_HTTP_PROXY AND (LWS_WITHOUT_CLIENT OR LWS_WITHOUT_SERVER))
178 message(FATAL_ERROR "You have to enable both client and server for http proxy")
181 # Allow the user to override installation directories.
182 set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
183 set(LWS_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
184 set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
185 set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files")
187 # Allow the user to use the old CyaSSL options/library in stead of wolfSSL
188 if (LWS_USE_CYASSL AND LWS_USE_WOLFSSL)
189 message(FATAL_ERROR "LWS_USE_CYASSL and LWS_USE_WOLFSSL are mutually exclusive!")
192 # Copy CyaSSL options to the wolfSSL options
193 set(LWS_USE_WOLFSSL ${LWS_USE_CYASSL} CACHE BOOL "Use wolfSSL/CyaSSL instead of OpenSSL" FORCE)
194 set(LWS_WOLFSSL_LIBRARIES ${LWS_CYASSL_LIBRARIES} CACHE PATH "Path to wolfSSL/CyaSSL libraries" FORCE)
195 set(LWS_WOLFSSL_INCLUDE_DIRS ${LWS_CYASSL_INCLUDE_DIRS} CACHE PATH "Path to wolfSSL/CyaSSL header files" FORCE)
198 if (LWS_WITHOUT_CLIENT AND LWS_WITHOUT_SERVER)
199 message(FATAL_ERROR "Makes no sense to compile with neither client nor server.")
202 if (NOT (LWS_WITH_STATIC OR LWS_WITH_SHARED))
203 message(FATAL_ERROR "Makes no sense to compile with neither static nor shared libraries.")
206 if (NOT LWS_WITHOUT_EXTENSIONS)
207 if (NOT LWS_WITH_ZLIB)
208 message(FATAL_ERROR "zlib is required for extensions.")
212 set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib library")
213 set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib include directory")
214 set(LWS_OPENSSL_LIBRARIES CACHE PATH "Path to the OpenSSL library")
215 set(LWS_OPENSSL_INCLUDE_DIRS CACHE PATH "Path to the OpenSSL include directory")
216 set(LWS_WOLFSSL_LIBRARIES CACHE PATH "Path to the wolfSSL library")
217 set(LWS_WOLFSSL_INCLUDE_DIRS CACHE PATH "Path to the wolfSSL include directory")
218 set( CACHE PATH "Path to the libev library")
219 set(LWS_LIBEV_INCLUDE_DIRS CACHE PATH "Path to the libev include directory")
220 set(LWS_LIBUV_LIBRARIES CACHE PATH "Path to the libuv library")
221 set(LWS_LIBUV_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory")
222 set(LWS_SQLITE3_LIBRARIES CACHE PATH "Path to the libuv library")
223 set(LWS_SQLITE3_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory")
226 if (NOT LWS_WITH_SSL)
227 set(LWS_WITHOUT_BUILTIN_SHA1 OFF)
230 if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL)
231 if ("${LWS_OPENSSL_LIBRARIES}" STREQUAL "" OR "${LWS_OPENSSL_INCLUDE_DIRS}" STREQUAL "")
233 set(OPENSSL_LIBRARIES ${LWS_OPENSSL_LIBRARIES})
234 set(OPENSSL_INCLUDE_DIRS ${LWS_OPENSSL_INCLUDE_DIRS})
239 if (LWS_WITH_SSL AND LWS_USE_WOLFSSL)
240 if ("${LWS_WOLFSSL_LIBRARIES}" STREQUAL "" OR "${LWS_WOLFSSL_INCLUDE_DIRS}" STREQUAL "")
241 if (NOT WOLFSSL_FOUND)
243 message(FATAL_ERROR "You must set LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS when LWS_USE_CYASSL is turned on.")
245 message(FATAL_ERROR "You must set LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS when LWS_USE_WOLFSSL is turned on.")
249 set(WOLFSSL_LIBRARIES ${LWS_WOLFSSL_LIBRARIES})
250 set(WOLFSSL_INCLUDE_DIRS ${LWS_WOLFSSL_INCLUDE_DIRS})
255 set(USE_OLD_CYASSL 1)
259 if (LWS_WITH_SSL AND LWS_USE_MBEDTLS)
260 if ("${LWS_MBEDTLS_LIBRARIES}" STREQUAL "" OR "${LWS_MBEDTLS_INCLUDE_DIRS}" STREQUAL "")
261 if (NOT MBEDTLS_FOUND)
262 message(FATAL_ERROR "You must set LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS when LWS_USE_MBEDTLS is turned on.")
265 set(MBEDTLS_LIBRARIES ${LWS_MBEDTLS_LIBRARIES})
266 set(MBEDTLS_INCLUDE_DIRS ${LWS_MBEDTLS_INCLUDE_DIRS})
272 if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB)
273 if ("${LWS_ZLIB_LIBRARIES}" STREQUAL "" OR "${LWS_ZLIB_INCLUDE_DIRS}" STREQUAL "")
275 set(ZLIB_LIBRARIES ${LWS_ZLIB_LIBRARIES})
276 set(ZLIB_INCLUDE_DIRS ${LWS_ZLIB_INCLUDE_DIRS})
282 if ("${LWS_LIBEV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEV_INCLUDE_DIRS}" STREQUAL "")
284 set(LIBEV_LIBRARIES ${LWS_LIBEV_LIBRARIES})
285 set(LIBEV_INCLUDE_DIRS ${LWS_LIBEV_INCLUDE_DIRS})
291 if ("${LWS_LIBUV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBUV_INCLUDE_DIRS}" STREQUAL "")
293 set(LIBUV_LIBRARIES ${LWS_LIBUV_LIBRARIES})
294 set(LIBUV_INCLUDE_DIRS ${LWS_LIBUV_INCLUDE_DIRS})
299 if (LWS_WITH_SQLITE3)
300 if ("${LWS_SQLITE3_LIBRARIES}" STREQUAL "" OR "${LWS_SQLITE3_INCLUDE_DIRS}" STREQUAL "")
302 set(SQLITE3_LIBRARIES ${LWS_SQLITE3_LIBRARIES})
303 set(SQLITE3_INCLUDE_DIRS ${LWS_SQLITE3_INCLUDE_DIRS})
309 # FIXME: This must be runtime-only option.
310 # The base dir where the test-apps look for the SSL certs.
311 set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory")
313 set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory")
317 message(WARNING "IPv6 does not currently work on Windows!")
320 set(LWS_UNIX_SOCK OFF)
321 message(WARNING "Windows does not support UNIX domain sockets")
324 set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory")
327 if (LWS_WITHOUT_EXTENSIONS)
328 set(LWS_NO_EXTENSIONS 1)
332 set(LWS_OPENSSL_SUPPORT 1)
335 if (LWS_SSL_CLIENT_USE_OS_CA_CERTS)
336 set(LWS_SSL_CLIENT_USE_OS_CA_CERTS 1)
339 if (LWS_WITH_LATENCY)
343 if (LWS_WITHOUT_DAEMONIZE OR WIN32)
344 set(LWS_NO_DAEMONIZE 1)
347 if (LWS_WITHOUT_SERVER)
351 if (LWS_WITHOUT_CLIENT)
368 set(LWS_USE_UNIX_SOCK 1)
375 if ("${LWS_MAX_SMP}" STREQUAL "")
380 if (LWS_WITH_ESP8266)
381 set(CMAKE_C_FLAGS "-nostdlib ${CMAKE_C_FLAGS}")
384 # set(CMAKE_C_FLAGS "-D_DEBUG ${CMAKE_C_FLAGS}")
388 set(LWS_MINGW_SUPPORT 1)
389 set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}")
392 if (LWS_SSL_SERVER_WITH_ECDH_CERT)
393 set(LWS_SSL_SERVER_WITH_ECDH_CERT 1)
396 include_directories("${PROJECT_BINARY_DIR}")
398 include(CheckCSourceCompiles)
400 # Check for different inline keyword versions.
401 foreach(KEYWORD "inline" "__inline__" "__inline")
402 set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}")
403 CHECK_C_SOURCE_COMPILES(
406 static KEYWORD void a() {}
407 int main(int argc, char **argv) { a(); return 0; }
408 " LWS_HAVE_${KEYWORD})
411 if (NOT LWS_HAVE_inline)
412 if (LWS_HAVE___inline__)
413 set(inline __inline__)
414 elseif(LWS_HAVE___inline)
419 # Put the libaries and binaries that get built into directories at the
420 # top of the build tree rather than in hard-to-find leaf directories.
421 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
422 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
423 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
425 SET(LWS_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}")
427 # Put absolute path of dynamic libraries into the object code. Some
428 # architectures, notably Mac OS X, need this.
429 SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}")
431 include(CheckFunctionExists)
432 include(CheckSymbolExists)
433 include(CheckIncludeFile)
434 include(CheckIncludeFiles)
435 include(CheckLibraryExists)
436 include(CheckTypeSize)
438 if (LWS_WITHOUT_BUILTIN_SHA1)
439 set(LWS_SHA1_USE_OPENSSL_NAME 1)
442 CHECK_FUNCTION_EXISTS(bzero LWS_HAVE_BZERO)
443 CHECK_FUNCTION_EXISTS(fork LWS_HAVE_FORK)
444 CHECK_FUNCTION_EXISTS(getenv LWS_HAVE_GETENV)
445 CHECK_FUNCTION_EXISTS(malloc LWS_HAVE_MALLOC)
446 CHECK_FUNCTION_EXISTS(memset LWS_HAVE_MEMSET)
447 CHECK_FUNCTION_EXISTS(realloc LWS_HAVE_REALLOC)
448 CHECK_FUNCTION_EXISTS(socket LWS_HAVE_SOCKET)
449 CHECK_FUNCTION_EXISTS(strerror LWS_HAVE_STRERROR)
450 CHECK_FUNCTION_EXISTS(vfork LWS_HAVE_VFORK)
451 CHECK_FUNCTION_EXISTS(execvpe LWS_HAVE_EXECVPE)
452 CHECK_FUNCTION_EXISTS(getifaddrs LWS_HAVE_GETIFADDRS)
453 CHECK_FUNCTION_EXISTS(snprintf LWS_HAVE_SNPRINTF)
454 CHECK_FUNCTION_EXISTS(_snprintf LWS_HAVE__SNPRINTF)
455 CHECK_FUNCTION_EXISTS(_vsnprintf LWS_HAVE__VSNPRINTF)
456 CHECK_FUNCTION_EXISTS(getloadavg LWS_HAVE_GETLOADAVG)
458 if (NOT LWS_HAVE_GETIFADDRS)
459 if (LWS_WITHOUT_BUILTIN_GETIFADDRS)
460 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.")
462 set(LWS_BUILTIN_GETIFADDRS 1)
465 CHECK_INCLUDE_FILE(dlfcn.h LWS_HAVE_DLFCN_H)
466 CHECK_INCLUDE_FILE(fcntl.h LWS_HAVE_FCNTL_H)
467 CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H)
468 CHECK_INCLUDE_FILE(inttypes.h LWS_HAVE_INTTYPES_H)
469 CHECK_INCLUDE_FILE(memory.h LWS_HAVE_MEMORY_H)
470 CHECK_INCLUDE_FILE(netinet/in.h LWS_HAVE_NETINET_IN_H)
471 CHECK_INCLUDE_FILE(stdint.h LWS_HAVE_STDINT_H)
472 CHECK_INCLUDE_FILE(stdlib.h LWS_HAVE_STDLIB_H)
473 CHECK_INCLUDE_FILE(strings.h LWS_HAVE_STRINGS_H)
474 CHECK_INCLUDE_FILE(string.h LWS_HAVE_STRING_H)
475 CHECK_INCLUDE_FILE(sys/prctl.h LWS_HAVE_SYS_PRCTL_H)
476 CHECK_INCLUDE_FILE(sys/socket.h LWS_HAVE_SYS_SOCKET_H)
477 CHECK_INCLUDE_FILE(sys/stat.h LWS_HAVE_SYS_STAT_H)
478 CHECK_INCLUDE_FILE(sys/types.h LWS_HAVE_SYS_TYPES_H)
479 CHECK_INCLUDE_FILE(unistd.h LWS_HAVE_UNISTD_H)
480 CHECK_INCLUDE_FILE(vfork.h LWS_HAVE_VFORK_H)
482 if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB)
483 CHECK_INCLUDE_FILE(zlib.h LWS_HAVE_ZLIB_H)
486 # TODO: These can also be tested to see whether they actually work...
487 set(LWS_HAVE_WORKING_FORK LWS_HAVE_FORK)
488 set(LWS_HAVE_WORKING_VFORK LWS_HAVE_VFORK)
490 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
492 # These don't work Cross...
493 #CHECK_TYPE_SIZE(pid_t PID_T_SIZE)
494 #CHECK_TYPE_SIZE(size_t SIZE_T_SIZE)
495 #CHECK_TYPE_SIZE("void *" LWS_SIZEOFPTR LANGUAGE C)
502 set(size_t "unsigned int")
505 if (NOT LWS_HAVE_MALLOC)
506 set(malloc rpl_malloc)
509 if (NOT LWS_HAVE_REALLOC)
510 set(realloc rpl_realloc)
515 # Turn off stupid microsoft security warnings.
516 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
519 include_directories("${PROJECT_SOURCE_DIR}/lib")
521 # Group headers and sources.
522 # Some IDEs use this for nicer file structure.
524 lib/private-libwebsockets.h)
527 "${PROJECT_SOURCE_DIR}/lib/libwebsockets.h"
528 "${PROJECT_BINARY_DIR}/lws_config.h")
542 if (NOT LWS_WITHOUT_CLIENT)
545 lib/client-handshake.c
553 if (NOT LWS_WITHOUT_SERVER)
557 if (NOT LWS_WITHOUT_CLIENT)
563 if (NOT LWS_WITHOUT_BUILTIN_SHA1)
574 # select the active platform files
582 lib/lws-plat-mbed3.cpp
583 lib/lws-plat-mbed3.c)
585 if (LWS_WITH_ESP8266)
587 lib/lws-plat-esp8266.c)
595 if (NOT LWS_WITHOUT_SERVER)
598 lib/server-handshake.c)
601 if (NOT LWS_WITHOUT_EXTENSIONS)
602 list(APPEND HDR_PRIVATE
603 lib/extension-permessage-deflate.h)
606 lib/extension-permessage-deflate.c)
609 if (LWS_WITH_HTTP_PROXY)
627 list(APPEND HDR_PUBLIC
630 if (LWS_WITH_LEJP_CONF)
641 # Add helper files for Windows.
643 set(WIN32_HELPERS_PATH win32port/win32helpers)
644 include_directories(${WIN32_HELPERS_PATH})
648 ${WIN32_HELPERS_PATH}/gettimeofday.c
651 list(APPEND HDR_PRIVATE
652 ${WIN32_HELPERS_PATH}/gettimeofday.h
658 if (NOT LWS_WITHOUT_DAEMONIZE)
665 if (NOT LWS_HAVE_GETIFADDRS)
666 list(APPEND HDR_PRIVATE lib/getifaddrs.h)
667 list(APPEND SOURCES lib/getifaddrs.c)
671 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
672 include (CheckCCompilerFlag)
673 CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY)
674 if (LWS_HAVE_VISIBILITY)
675 set(VISIBILITY_FLAG -fvisibility=hidden)
677 if (UNIX OR LWS_WITH_ESP8266)
678 set(CMAKE_C_FLAGS "-Wall -Werror ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
680 set(CMAKE_C_FLAGS "-Wall ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
684 if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS)
686 # jeez clang understands -pthread but dies if he sees it at link time!
687 # http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang
688 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
692 if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
693 # otherwise osx blows a bunch of openssl deprecated api errors
694 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" )
697 source_group("Headers Private" FILES ${HDR_PRIVATE})
698 source_group("Headers Public" FILES ${HDR_PUBLIC})
699 source_group("Sources" FILES ${SOURCES})
707 add_library(websockets STATIC
711 list(APPEND LWS_LIBRARIES websockets)
714 # Windows uses the same .lib ending for static libraries and shared
715 # library linker files, so rename the static library.
716 set_target_properties(websockets
718 OUTPUT_NAME websockets_static)
723 add_library(websockets_shared SHARED
727 list(APPEND LWS_LIBRARIES websockets_shared)
729 # We want the shared lib to be named "libwebsockets"
730 # not "libwebsocket_shared".
731 set_target_properties(websockets_shared
733 OUTPUT_NAME websockets)
736 # Compile as DLL (export function declarations)
738 TARGET websockets_shared
739 PROPERTY COMPILE_DEFINITIONS
745 set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES)
749 # Set the so version of the lib.
750 # Equivalent to LDFLAGS=-version-info x:x:x
751 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
752 foreach(lib ${LWS_LIBRARIES})
753 set_target_properties(${lib}
755 SOVERSION ${SOVERSION})
766 # ZLIB (Only needed for deflate extensions).
769 if (LWS_USE_BUNDLED_ZLIB)
771 set(WIN32_ZLIB_PATH "win32port/zlib")
773 ${WIN32_ZLIB_PATH}/adler32.c
774 ${WIN32_ZLIB_PATH}/compress.c
775 ${WIN32_ZLIB_PATH}/crc32.c
776 ${WIN32_ZLIB_PATH}/deflate.c
777 ${WIN32_ZLIB_PATH}/gzclose.c
778 ${WIN32_ZLIB_PATH}/gzio.c
779 ${WIN32_ZLIB_PATH}/gzlib.c
780 ${WIN32_ZLIB_PATH}/gzread.c
781 ${WIN32_ZLIB_PATH}/gzwrite.c
782 ${WIN32_ZLIB_PATH}/infback.c
783 ${WIN32_ZLIB_PATH}/inffast.c
784 ${WIN32_ZLIB_PATH}/inflate.c
785 ${WIN32_ZLIB_PATH}/inftrees.c
786 ${WIN32_ZLIB_PATH}/trees.c
787 ${WIN32_ZLIB_PATH}/uncompr.c
788 ${WIN32_ZLIB_PATH}/zutil.c)
789 add_library(zlib_internal STATIC ${ZLIB_SRCS})
790 set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
791 get_property(ZLIB_LIBRARIES TARGET zlib_internal PROPERTY LOCATION)
793 # Make sure zlib_internal is compiled before the libs.
794 foreach (lib ${LWS_LIBRARIES})
795 add_dependencies(${lib} zlib_internal)
798 message(FATAL_ERROR "Don't have bundled zlib for that platform")
800 elseif (NOT ZLIB_FOUND)
801 find_package(ZLIB REQUIRED)
803 message("zlib include dirs: ${ZLIB_INCLUDE_DIRS}")
804 message("zlib libraries: ${ZLIB_LIBRARIES}")
805 include_directories(${ZLIB_INCLUDE_DIRS})
806 list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
813 message("Compiling with SSL support")
816 # Use wolfSSL as OpenSSL replacement.
817 # TODO: Add a find_package command for this also.
818 message("wolfSSL include dir: ${WOLFSSL_INCLUDE_DIRS}")
819 message("wolfSSL libraries: ${WOLFSSL_LIBRARIES}")
821 # Additional to the root directory we need to include
822 # the wolfssl/ subdirectory which contains the OpenSSL
823 # compatibility layer headers.
826 foreach(inc ${WOLFSSL_INCLUDE_DIRS})
827 include_directories("${inc}" "${inc}/cyassl")
830 foreach(inc ${WOLFSSL_INCLUDE_DIRS})
831 include_directories("${inc}" "${inc}/wolfssl")
835 list(APPEND LIB_LIST "${WOLFSSL_LIBRARIES}")
840 if (NOT OPENSSL_FOUND)
841 # TODO: Add support for STATIC also.
842 find_package(OpenSSL REQUIRED)
843 set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}")
846 message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}")
847 message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
849 include_directories("${OPENSSL_INCLUDE_DIRS}")
850 list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
852 # older (0.98) Openssl lacks this
853 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
854 check_include_file(openssl/ecdh.h LWS_HAVE_OPENSSL_ECDH_H)
856 if (LWS_SSL_SERVER_WITH_ECDH_CERT AND NOT LWS_HAVE_OPENSSL_ECDH_H)
857 message(FATAL_ERROR "Missing openssl/ecdh.h, so cannot use LWS_SSL_SERVER_WITH_ECDH_CERT")
865 find_path(LIBEV_INCLUDE_DIRS NAMES ev.h)
866 find_library(LIBEV_LIBRARIES NAMES ev)
867 if(LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES)
871 message("libev include dir: ${LIBEV_INCLUDE_DIRS}")
872 message("libev libraries: ${LIBEV_LIBRARIES}")
873 include_directories("${LIBEV_INCLUDE_DIRS}")
874 list(APPEND LIB_LIST ${LIBEV_LIBRARIES})
875 endif(LWS_WITH_LIBEV)
879 find_path(LIBUV_INCLUDE_DIRS NAMES uv.h)
880 find_library(LIBUV_LIBRARIES NAMES uv)
881 if(LIBUV_INCLUDE_DIRS AND LIBUV_LIBRARIES)
885 message("libuv include dir: ${LIBUV_INCLUDE_DIRS}")
886 message("libuv libraries: ${LIBUV_LIBRARIES}")
887 include_directories("${LIBUV_INCLUDE_DIRS}")
888 list(APPEND LIB_LIST ${LIBUV_LIBRARIES})
891 if (LWS_WITH_SQLITE3)
892 if (NOT SQLITE3_FOUND)
893 find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h)
894 find_library(SQLITE3_LIBRARIES NAMES sqlite3)
895 if(SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
899 message("sqlite3 include dir: ${SQLITE3_INCLUDE_DIRS}")
900 message("sqlite3 libraries: ${SQLITE3_LIBRARIES}")
901 include_directories("${SQLITE3_INCLUDE_DIRS}")
902 list(APPEND LIB_LIST ${SQLITE3_LIBRARIES})
906 if (LWS_WITH_HTTP_PROXY)
907 find_library(LIBHUBBUB_LIBRARIES NAMES libhubbub)
908 list(APPEND LIB_LIST ${LIBHUBBUB_LIBRARIES} )
913 # Platform specific libs.
916 list(APPEND LIB_LIST ws2.lib)
918 list(APPEND LIB_LIST ws2_32.lib)
922 list(APPEND LIB_LIST m)
925 # Setup the linking for all libs.
926 foreach (lib ${LWS_LIBRARIES})
927 target_link_libraries(${lib} ${LIB_LIST})
930 set (temp ${CMAKE_REQUIRED_LIBRARIES})
931 set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST})
932 CHECK_FUNCTION_EXISTS(SSL_CTX_set1_param LWS_HAVE_SSL_CTX_set1_param)
933 CHECK_FUNCTION_EXISTS(X509_VERIFY_PARAM_set1_host LWS_HAVE_X509_VERIFY_PARAM_set1_host)
934 set(CMAKE_REQUIRED_LIBRARIES ${temp})
935 # Generate the lws_config.h that includes all the public compilation settings.
937 "${PROJECT_SOURCE_DIR}/lws_config.h.in"
938 "${PROJECT_BINARY_DIR}/lws_config.h")
940 # Generate the lws_config.h that includes all the private compilation settings.
942 "${PROJECT_SOURCE_DIR}/lws_config_private.h.in"
943 "${PROJECT_BINARY_DIR}/lws_config_private.h")
951 if (NOT LWS_WITHOUT_TESTAPPS)
953 # Helper function for adding a test app.
955 macro(create_test_app TEST_NAME MAIN_SRC S2 S3 S4 S5 S6)
957 set(TEST_SRCS ${MAIN_SRC})
959 if ("${S2}" STREQUAL "")
961 list(APPEND TEST_SRCS ${S2})
963 if ("${S3}" STREQUAL "")
965 list(APPEND TEST_SRCS ${S3})
967 if ("${S4}" STREQUAL "")
969 list(APPEND TEST_SRCS ${S4})
971 if ("${S5}" STREQUAL "")
973 list(APPEND TEST_SRCS ${S5})
975 if ("${S6}" STREQUAL "")
977 list(APPEND TEST_SRCS ${S6})
980 list(APPEND TEST_SRCS
981 ${WIN32_HELPERS_PATH}/getopt.c
982 ${WIN32_HELPERS_PATH}/getopt_long.c
983 ${WIN32_HELPERS_PATH}/gettimeofday.c
987 ${WIN32_HELPERS_PATH}/getopt.h
988 ${WIN32_HELPERS_PATH}/gettimeofday.h
992 source_group("Headers Private" FILES ${TEST_HDR})
993 source_group("Sources" FILES ${TEST_SRCS})
994 add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
996 if (LWS_LINK_TESTAPPS_DYNAMIC)
997 if (NOT LWS_WITH_SHARED)
998 message(FATAL_ERROR "Build of the shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.")
1000 target_link_libraries(${TEST_NAME} websockets_shared)
1001 add_dependencies(${TEST_NAME} websockets_shared)
1003 if (NOT LWS_WITH_STATIC)
1004 message(FATAL_ERROR "Build of the static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.")
1006 target_link_libraries(${TEST_NAME} websockets)
1007 add_dependencies(${TEST_NAME} websockets)
1010 # Set test app specific defines.
1011 set_property(TARGET ${TEST_NAME}
1012 PROPERTY COMPILE_DEFINITIONS
1013 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1016 # Prefix the binary names with libwebsockets.
1017 set_target_properties(${TEST_NAME}
1019 OUTPUT_NAME libwebsockets-${TEST_NAME})
1021 # Add to the list of tests.
1022 list(APPEND TEST_APP_LIST ${TEST_NAME})
1025 if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL)
1026 message("Searching for OpenSSL executable and dlls")
1027 find_package(OpenSSLbins)
1028 message("OpenSSL executable: ${OPENSSL_EXECUTABLE}")
1031 if (UNIX AND LWS_WITH_PLUGINS)
1032 set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
1033 target_link_libraries(websockets dl)
1036 if (NOT LWS_WITHOUT_SERVER)
1040 if (NOT LWS_WITHOUT_TEST_SERVER)
1041 create_test_app(test-server "test-server/test-server.c"
1042 "test-server/test-server-http.c"
1043 "test-server/test-server-dumb-increment.c"
1044 "test-server/test-server-mirror.c"
1045 "test-server/test-server-status.c"
1046 "test-server/test-server-echogen.c")
1048 create_test_app(test-fuzxy "test-server/fuzxy.c"
1055 if (UNIX AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")))
1056 create_test_app(test-server-pthreads
1057 "test-server/test-server-pthreads.c"
1058 "test-server/test-server-http.c"
1059 "test-server/test-server-dumb-increment.c"
1060 "test-server/test-server-mirror.c"
1061 "test-server/test-server-status.c"
1062 "test-server/test-server-echogen.c")
1064 if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
1066 create_test_app(test-server-libev
1067 "test-server/test-server-libev.c"
1068 "test-server/test-server-http.c"
1069 "test-server/test-server-dumb-increment.c"
1070 "test-server/test-server-mirror.c"
1071 "test-server/test-server-status.c"
1072 "test-server/test-server-echogen.c")
1074 if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
1076 create_test_app(test-server-libuv
1077 "test-server/test-server-libuv.c"
1078 "test-server/test-server-http.c"
1079 "test-server/test-server-dumb-increment.c"
1080 "test-server/test-server-mirror.c"
1081 "test-server/test-server-status.c"
1082 "test-server/test-server-echogen.c")
1087 # test-server-extpoll
1089 if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL)
1090 create_test_app(test-server-extpoll "test-server/test-server.c"
1091 "test-server/test-server-http.c"
1092 "test-server/test-server-dumb-increment.c"
1093 "test-server/test-server-mirror.c"
1094 "test-server/test-server-status.c"
1095 "test-server/test-server-echogen.c")
1096 # Set defines for this executable only.
1098 TARGET test-server-extpoll
1099 PROPERTY COMPILE_DEFINITIONS
1101 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1104 # We need to link against winsock code.
1106 target_link_libraries(test-server-extpoll ws2_32.lib)
1113 if (LWS_WITH_PLUGINS)
1116 "test-server/test-server-v2.0.c"
1124 # Data files for running the test server.
1125 set(TEST_SERVER_DATA
1126 "${PROJECT_SOURCE_DIR}/test-server/favicon.ico"
1127 "${PROJECT_SOURCE_DIR}/test-server/leaf.jpg"
1128 "${PROJECT_SOURCE_DIR}/test-server/libwebsockets.org-logo.png"
1129 "${PROJECT_SOURCE_DIR}/test-server/lws-common.js"
1130 "${PROJECT_SOURCE_DIR}/test-server/test.html")
1132 # Generate self-signed SSL certs for the test-server.
1133 if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER)
1134 message("Generating SSL Certificates for the test-server...")
1136 set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem")
1137 set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem")
1141 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}\"")
1143 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}"
1144 RESULT_VARIABLE OPENSSL_RETURN_CODE)
1146 file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt"
1150 "libwebsockets-test\n"
1152 "none@invalid.org\n\n"
1155 # The "type" command is a bit picky with paths.
1156 file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
1157 message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
1158 message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
1161 COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
1162 COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1163 RESULT_VARIABLE OPENSSL_RETURN_CODE
1164 OUTPUT_QUIET ERROR_QUIET)
1169 if (OPENSSL_RETURN_CODE)
1170 message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
1172 message("SUCCSESFULLY generated SSL certificate")
1177 COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n"
1178 COMMAND "${OPENSSL_EXECUTABLE}"
1179 req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1180 RESULT_VARIABLE OPENSSL_RETURN_CODE
1181 OUTPUT_QUIET ERROR_QUIET)
1183 if (OPENSSL_RETURN_CODE)
1184 message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
1186 message("SUCCESSFULLY generated SSL certificate")
1190 list(APPEND TEST_SERVER_DATA
1191 "${TEST_SERVER_SSL_KEY}"
1192 "${TEST_SERVER_SSL_CERT}")
1195 add_custom_command(TARGET test-server
1197 COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server")
1199 # Copy the file needed to run the server so that the test apps can
1200 # reach them from their default output location
1201 foreach (TEST_FILE ${TEST_SERVER_DATA})
1202 if (EXISTS ${TEST_FILE})
1203 add_custom_command(TARGET test-server
1205 COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM)
1208 endif(NOT LWS_WITHOUT_SERVER)
1210 if (NOT LWS_WITHOUT_CLIENT)
1214 if (NOT LWS_WITHOUT_TEST_CLIENT)
1215 create_test_app(test-client "test-server/test-client.c" "" "" "" "" "")
1221 if (NOT LWS_WITHOUT_TEST_FRAGGLE)
1222 create_test_app(test-fraggle "test-server/test-fraggle.c" "" "" "" "" "")
1228 if (NOT LWS_WITHOUT_TEST_PING)
1229 create_test_app(test-ping "test-server/test-ping.c" "" "" "" "" "")
1234 if (NOT LWS_WITHOUT_TEST_ECHO)
1235 create_test_app(test-echo "test-server/test-echo.c" "" "" "" "" "")
1238 endif(NOT LWS_WITHOUT_CLIENT)
1241 if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
1242 macro(create_plugin PLUGIN_NAME MAIN_SRC S2 S3)
1244 set(PLUGIN_SRCS ${MAIN_SRC})
1246 if ("${S2}" STREQUAL "")
1248 list(APPEND PLUGIN_SRCS ${S2})
1250 if ("${S3}" STREQUAL "")
1252 list(APPEND PLUGIN_SRCS ${S3})
1256 list(APPEND PLUGIN_SRCS
1257 ${WIN32_HELPERS_PATH}/getopt.c
1258 ${WIN32_HELPERS_PATH}/getopt_long.c
1259 ${WIN32_HELPERS_PATH}/gettimeofday.c
1262 list(APPEND PLUGIN_HDR
1263 ${WIN32_HELPERS_PATH}/getopt.h
1264 ${WIN32_HELPERS_PATH}/gettimeofday.h
1268 source_group("Headers Private" FILES ${PLUGIN_HDR})
1269 source_group("Sources" FILES ${PLUGIN_SRCS})
1270 add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR})
1272 target_link_libraries(${PLUGIN_NAME} websockets_shared)
1273 add_dependencies(${PLUGIN_NAME} websockets_shared)
1275 # Set test app specific defines.
1276 set_property(TARGET ${PLUGIN_NAME}
1277 PROPERTY COMPILE_DEFINITIONS
1278 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
1281 # set_target_properties(${PLUGIN_NAME}
1283 # OUTPUT_NAME ${PLUGIN_NAME})
1285 list(APPEND PLUGINS_LIST ${PLUGIN_NAME})
1290 create_plugin(protocol_dumb_increment
1291 "plugins/protocol_dumb_increment.c" "" "")
1292 create_plugin(protocol_lws_mirror
1293 "plugins/protocol_lws_mirror.c" "" "")
1294 create_plugin(protocol_lws_status
1295 "plugins/protocol_lws_status.c" "" "")
1296 create_plugin(protocol_post_demo
1297 "plugins/protocol_post_demo.c" "" "")
1298 create_plugin(protocol_lws_table_dirlisting
1299 "plugins/generic-table/protocol_table_dirlisting.c" "" "")
1301 if (LWS_WITH_SERVER_STATUS)
1302 create_plugin(protocol_lws_server_status
1303 "plugins/protocol_lws_server_status.c" "" "")
1306 if (NOT LWS_WITHOUT_CLIENT)
1307 create_plugin(protocol_client_loopback_test
1308 "plugins/protocol_client_loopback_test.c" "" "")
1309 endif(NOT LWS_WITHOUT_CLIENT)
1311 if (LWS_WITH_GENERIC_SESSIONS)
1312 create_plugin(protocol_generic_sessions
1313 "plugins/generic-sessions/protocol_generic_sessions.c"
1314 "plugins/generic-sessions/utils.c"
1315 "plugins/generic-sessions/handlers.c")
1318 target_link_libraries(protocol_generic_sessions ${LWS_SQLITE3_LIBRARIES})
1320 target_link_libraries(protocol_generic_sessions sqlite3 )
1323 create_plugin(protocol_lws_messageboard
1324 "plugins/generic-sessions/protocol_lws_messageboard.c" "" "")
1326 target_link_libraries(protocol_lws_messageboard ${LWS_SQLITE3_LIBRARIES})
1328 target_link_libraries(protocol_lws_messageboard sqlite3 )
1331 endif(LWS_WITH_GENERIC_SESSIONS)
1334 endif(LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
1337 # Copy OpenSSL dlls to the output directory on Windows.
1338 # (Otherwise we'll get an error when trying to run)
1340 if (WIN32 AND LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL)
1341 if(OPENSSL_BIN_FOUND)
1342 message("OpenSSL dlls found:")
1343 message(" Libeay: ${LIBEAY_BIN}")
1344 message(" SSLeay: ${SSLEAY_BIN}")
1346 foreach(TARGET_BIN ${TEST_APP_LIST})
1347 add_custom_command(TARGET ${TARGET_BIN}
1349 COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
1350 add_custom_command(TARGET ${TARGET_BIN}
1352 COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
1356 endif(NOT LWS_WITHOUT_TESTAPPS)
1359 list(APPEND LWSWS_SRCS
1364 list(APPEND LWSWS_SRCS
1365 ${WIN32_HELPERS_PATH}/getopt.c
1366 ${WIN32_HELPERS_PATH}/getopt_long.c
1367 ${WIN32_HELPERS_PATH}/gettimeofday.c
1370 list(APPEND LWSWS_HDR
1371 ${WIN32_HELPERS_PATH}/getopt.h
1372 ${WIN32_HELPERS_PATH}/gettimeofday.h
1376 source_group("Headers Private" FILES ${LWSWS_HDR})
1377 source_group("Sources" FILES ${LWSWS_SRCS})
1378 add_executable("lwsws" ${LWSWS_SRCS} ${LWSWS_HDR})
1380 target_link_libraries("lwsws" websockets_shared)
1381 add_dependencies("lwsws" websockets_shared)
1383 # Set test app specific defines.
1384 set_property(TARGET "lwsws"
1385 PROPERTY COMPILE_DEFINITIONS
1386 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1388 endif (LWS_WITH_LWSWS)
1392 # Generate and install pkgconfig.
1393 # (This is not indented, because the tabs will be part of the output)
1394 file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc"
1395 "prefix=\"${CMAKE_INSTALL_PREFIX}\"
1396 exec_prefix=\${prefix}
1397 libdir=\${exec_prefix}/lib${LIB_SUFFIX}
1398 includedir=\${prefix}/include
1401 Description: Websockets server and client library
1402 Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
1404 Libs: -L\${libdir} -lwebsockets
1405 Cflags: -I\${includedir}"
1408 install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc"
1409 DESTINATION lib${LIB_SUFFIX}/pkgconfig)
1413 # Installation preparations.
1416 if(WIN32 AND NOT CYGWIN)
1417 set(DEF_INSTALL_CMAKE_DIR cmake)
1419 set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets)
1422 set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
1424 # Export targets (This is used for other CMake projects to easily find the libraries and include files).
1425 export(TARGETS ${LWS_LIBRARIES}
1426 FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
1427 export(PACKAGE libwebsockets)
1429 # Generate the config file for the build-tree.
1430 set(LWS__INCLUDE_DIRS
1431 "${PROJECT_SOURCE_DIR}/lib"
1432 "${PROJECT_BINARY_DIR}")
1433 set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories")
1434 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
1435 ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake
1438 # Generate the config file for the installation tree.
1439 get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE)
1440 get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE)
1443 "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}"
1444 "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir.
1446 # Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in,
1447 # we escape it here so it's evaluated when it is included instead
1448 # so that the include dirs are given relative to where the
1449 # config file is located.
1450 set(LWS__INCLUDE_DIRS
1451 "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}")
1452 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
1453 ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake
1456 # Generate version info for both build-tree and install-tree.
1457 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in
1458 ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake
1461 set_target_properties(${LWS_LIBRARIES}
1462 PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
1468 # Install libs and headers.
1469 install(TARGETS ${LWS_LIBRARIES}
1470 EXPORT LibwebsocketsTargets
1471 LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
1472 ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
1473 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT libraries # Windows DLLs
1474 PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
1475 set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
1476 set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files")
1478 # Install test apps.
1479 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_CLIENT)
1480 install(TARGETS test-client ${TEST_APP_LIST}
1481 RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR}
1483 set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files")
1488 install(TARGETS lwsws
1489 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT lwsws )
1492 # Programs shared files used by the test-server.
1493 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_SERVER)
1494 install(FILES ${TEST_SERVER_DATA}
1495 DESTINATION share/libwebsockets-test-server
1498 set(CGI_TEST_SCRIPT "${PROJECT_SOURCE_DIR}/test-server/lws-cgi-test.sh")
1499 install(FILES ${CGI_TEST_SCRIPT}
1500 PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
1501 DESTINATION share/libwebsockets-test-server
1508 if (LWS_WITH_PLUGINS)
1509 install(TARGETS ${PLUGINS_LIST}
1510 PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
1511 DESTINATION share/libwebsockets-test-server/plugins
1513 if (LWS_WITH_SERVER_STATUS)
1514 install(FILES plugins/server-status.html;plugins/lwsws-logo.png
1515 DESTINATION share/libwebsockets-test-server/server-status
1518 if (LWS_WITH_GENERIC_SESSIONS)
1520 plugins/generic-sessions/assets/lwsgs-logo.png
1521 plugins/generic-sessions/assets/seats.jpg
1522 plugins/generic-sessions/assets/failed-login.html
1523 plugins/generic-sessions/assets/lwsgs.js
1524 plugins/generic-sessions/assets/post-register-fail.html
1525 plugins/generic-sessions/assets/post-register-ok.html
1526 plugins/generic-sessions/assets/post-verify-ok.html
1527 plugins/generic-sessions/assets/post-verify-fail.html
1528 plugins/generic-sessions/assets/sent-forgot-ok.html
1529 plugins/generic-sessions/assets/sent-forgot-fail.html
1530 plugins/generic-sessions/assets/post-forgot-ok.html
1531 plugins/generic-sessions/assets/post-forgot-fail.html
1532 plugins/generic-sessions/assets/index.html
1533 DESTINATION share/libwebsockets-test-server/generic-sessions
1535 install(FILES plugins/generic-sessions/assets/successful-login.html
1536 DESTINATION share/libwebsockets-test-server/generic-sessions/needauth
1538 install(FILES plugins/generic-sessions/assets/admin-login.html
1539 DESTINATION share/libwebsockets-test-server/generic-sessions/needadmin
1544 plugins/generic-table/assets/lwsgt.js
1545 plugins/generic-table/assets/index.html
1546 DESTINATION share/libwebsockets-test-server/generic-table
1551 # Install the LibwebsocketsConfig.cmake and LibwebsocketsConfigVersion.cmake
1553 "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake"
1554 "${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake"
1555 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
1557 # Install exports for the install-tree.
1558 install(EXPORT LibwebsocketsTargets
1559 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
1561 # build subdir is not part of sources
1562 set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) ".git" "build" "tgz" "tar.gz")
1564 # Most people are more used to "make dist" compared to "make package_source"
1565 add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source)
1567 include(UseRPMTools)
1569 RPMTools_ADD_RPM_TARGETS(libwebsockets libwebsockets.spec)
1572 message("---------------------------------------------------------------------")
1573 message(" Settings: (For more help do cmake -LH <srcpath>)")
1574 message("---------------------------------------------------------------------")
1575 message(" LWS_WITH_STATIC = ${LWS_WITH_STATIC}")
1576 message(" LWS_WITH_SHARED = ${LWS_WITH_SHARED}")
1577 message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)")
1578 message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}")
1579 message(" LWS_USE_WOLFSSL = ${LWS_USE_WOLFSSL} (wolfSSL/CyaSSL replacement for OpenSSL)")
1580 if (LWS_USE_WOLFSSL)
1581 message(" LWS_WOLFSSL_LIBRARIES = ${LWS_WOLFSSL_LIBRARIES}")
1582 message(" LWS_WOLFSSL_INCLUDE_DIRS = ${LWS_WOLFSSL_INCLUDE_DIRS}")
1584 message(" LWS_WITHOUT_BUILTIN_SHA1 = ${LWS_WITHOUT_BUILTIN_SHA1}")
1585 message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}")
1586 message(" LWS_WITHOUT_CLIENT = ${LWS_WITHOUT_CLIENT}")
1587 message(" LWS_WITHOUT_SERVER = ${LWS_WITHOUT_SERVER}")
1588 message(" LWS_LINK_TESTAPPS_DYNAMIC = ${LWS_LINK_TESTAPPS_DYNAMIC}")
1589 message(" LWS_WITHOUT_TESTAPPS = ${LWS_WITHOUT_TESTAPPS}")
1590 message(" LWS_WITHOUT_TEST_SERVER = ${LWS_WITHOUT_TEST_SERVER}")
1591 message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}")
1592 message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}")
1593 message(" LWS_WITHOUT_TEST_ECHO = ${LWS_WITHOUT_TEST_ECHO}")
1594 message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}")
1595 message(" LWS_WITHOUT_TEST_FRAGGLE = ${LWS_WITHOUT_TEST_FRAGGLE}")
1596 message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}")
1597 message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}")
1598 message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}")
1599 message(" LWS_USE_LIBEV = ${LWS_USE_LIBEV}")
1600 message(" LWS_USE_LIBUV = ${LWS_USE_LIBUV}")
1601 message(" LWS_IPV6 = ${LWS_IPV6}")
1602 message(" LWS_UNIX_SOCK = ${LWS_UNIX_SOCK}")
1603 message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}")
1604 message(" LWS_MBED3 = ${LWS_MBED3}")
1605 message(" LWS_SSL_SERVER_WITH_ECDH_CERT = ${LWS_SSL_SERVER_WITH_ECDH_CERT}")
1606 message(" LWS_MAX_SMP = ${LWS_MAX_SMP}")
1607 message(" LWS_WITH_CGI = ${LWS_WITH_CGI}")
1608 message(" LWS_HAVE_OPENSSL_ECDH_H = ${LWS_HAVE_OPENSSL_ECDH_H}")
1609 message(" LWS_HAVE_SSL_CTX_set1_param = ${LWS_HAVE_SSL_CTX_set1_param}")
1610 message(" LWS_WITH_HTTP_PROXY = ${LWS_WITH_HTTP_PROXY}")
1611 message(" LIBHUBBUB_LIBRARIES = ${LIBHUBBUB_LIBRARIES}")
1612 message(" PLUGINS = ${PLUGINS_LIST}")
1613 message(" LWS_WITH_ACCESS_LOG = ${LWS_WITH_ACCESS_LOG}")
1614 message(" LWS_WITH_SERVER_STATUS = ${LWS_WITH_SERVER_STATUS}")
1615 message(" LWS_WITH_LEJP = ${LWS_WITH_LEJP}")
1616 message(" LWS_WITH_LEJP_CONF = ${LWS_WITH_LEJP_CONF}")
1617 message(" LWS_WITH_SMTP = ${LWS_WITH_SMTP}")
1618 message(" LWS_WITH_GENERIC_SESSIONS = ${LWS_WITH_GENERIC_SESSIONS}")
1621 message("---------------------------------------------------------------------")
1623 # These will be available to parent projects including libwebsockets using add_subdirectory()
1624 set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries")
1625 if (LWS_WITH_STATIC)
1626 set(LIBWEBSOCKETS_LIBRARIES_STATIC websocket CACHE STRING "Libwebsocket static library")
1628 if (LWS_WITH_SHARED)
1629 set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library")
1632 # This must always be last!