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_USE_POLARSSL "Use Polarssl (or mbedtls < 2.0) replacement for OpenSSL. When setting this, you also need to specify LWS_POLARSSL_LIBRARIES and LWS_POLARSSL_INCLUDE_DIRS" OFF)
68 option(LWS_USE_MBEDTLS "Use mbedTLS (>=2.0) replacement for OpenSSL. When setting this, you also need to specify LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS" OFF)
69 option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" ON)
70 option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
71 option(LWS_WITH_LIBUV "Compile with support for libuv" OFF)
72 option(LWS_USE_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_USE_BUNDLED_ZLIB_DEFAULT})
73 option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of the OS-installed CA root certs" ON)
74 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)
75 option(LWS_WITHOUT_BUILTIN_SHA1 "Don't build the lws sha-1 (eg, because openssl will provide it" OFF)
76 option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF)
77 option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF)
78 option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF)
79 option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
80 option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF)
81 option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF)
82 option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF)
83 option(LWS_WITHOUT_TEST_ECHO "Don't build the echo test application" OFF)
84 option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
85 option(LWS_WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF)
86 option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" OFF)
87 option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF)
88 option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON)
89 option(LWS_IPV6 "Compile with support for ipv6" OFF)
90 option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket" OFF)
91 option(LWS_WITH_HTTP2 "Compile with support for http2" OFF)
92 option(LWS_MBED3 "Platform is MBED3" OFF)
93 option(LWS_SSL_SERVER_WITH_ECDH_CERT "Include SSL server use ECDH certificate" OFF)
94 option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out/err) APIs" OFF)
95 option(LWS_WITH_HTTP_PROXY "Support for rewriting HTTP proxying" OFF)
96 option(LWS_WITH_LWSWS "Libwebsockets Webserver" OFF)
97 option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions" OFF)
98 option(LWS_WITH_ACCESS_LOG "Support generating Apache-compatible access logs" OFF)
99 option(LWS_WITH_SERVER_STATUS "Support json + jscript server monitoring" OFF)
100 option(LWS_WITH_LEJP "With the Lightweight JSON Parser" OFF)
101 option(LWS_WITH_LEJP_CONF "With LEJP configuration parser as used by lwsws" OFF)
102 option(LWS_WITH_GENERIC_SESSIONS "With the Generic Sessions plugin" OFF)
103 option(LWS_WITH_SQLITE3 "Require SQLITE3 support" OFF)
104 option(LWS_WITH_SMTP "Provide SMTP support" 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
152 # this implies no pthreads in the lib
157 if (LWS_WITHOUT_SERVER)
158 set(LWS_WITH_LWSWS OFF)
161 if (LWS_WITH_HTTP_PROXY AND (LWS_WITHOUT_CLIENT OR LWS_WITHOUT_SERVER))
162 message(FATAL_ERROR "You have to enable both client and server for http proxy")
165 # Allow the user to override installation directories.
166 set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
167 set(LWS_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
168 set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
169 set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files")
171 # Allow the user to use the old CyaSSL options/library in stead of wolfSSL
172 if (LWS_USE_CYASSL AND LWS_USE_WOLFSSL)
173 message(FATAL_ERROR "LWS_USE_CYASSL and LWS_USE_WOLFSSL are mutually exclusive!")
176 # Copy CyaSSL options to the wolfSSL options
177 set(LWS_USE_WOLFSSL ${LWS_USE_CYASSL} CACHE BOOL "Use wolfSSL/CyaSSL instead of OpenSSL" FORCE)
178 set(LWS_WOLFSSL_LIBRARIES ${LWS_CYASSL_LIBRARIES} CACHE PATH "Path to wolfSSL/CyaSSL libraries" FORCE)
179 set(LWS_WOLFSSL_INCLUDE_DIRS ${LWS_CYASSL_INCLUDE_DIRS} CACHE PATH "Path to wolfSSL/CyaSSL header files" FORCE)
182 if (LWS_WITHOUT_CLIENT AND LWS_WITHOUT_SERVER)
183 message(FATAL_ERROR "Makes no sense to compile with neither client nor server.")
186 if (NOT (LWS_WITH_STATIC OR LWS_WITH_SHARED))
187 message(FATAL_ERROR "Makes no sense to compile with neither static nor shared libraries.")
190 if (NOT LWS_WITHOUT_EXTENSIONS)
191 if (NOT LWS_WITH_ZLIB)
192 message(FATAL_ERROR "zlib is required for extensions.")
196 set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib library")
197 set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib include directory")
198 set(LWS_OPENSSL_LIBRARIES CACHE PATH "Path to the OpenSSL library")
199 set(LWS_OPENSSL_INCLUDE_DIRS CACHE PATH "Path to the OpenSSL include directory")
200 set(LWS_WOLFSSL_LIBRARIES CACHE PATH "Path to the wolfSSL library")
201 set(LWS_WOLFSSL_INCLUDE_DIRS CACHE PATH "Path to the wolfSSL include directory")
202 set(LWS_POLARSSL_LIBRARIES CACHE PATH "Path to the PolarSSL library")
203 set(LWS_POLARSSL_INCLUDE_DIRS CACHE PATH "Path to the PolarSSL include directory")
204 set( CACHE PATH "Path to the libev library")
205 set(LWS_LIBEV_INCLUDE_DIRS CACHE PATH "Path to the libev include directory")
206 set(LWS_LIBUV_LIBRARIES CACHE PATH "Path to the libuv library")
207 set(LWS_LIBUV_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory")
208 set(LWS_SQLITE3_LIBRARIES CACHE PATH "Path to the libuv library")
209 set(LWS_SQLITE3_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory")
212 if (NOT LWS_WITH_SSL)
213 set(LWS_WITHOUT_BUILTIN_SHA1 OFF)
216 if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL AND NOT LWS_USE_POLARSSL AND NOT LWS_USE_MBEDTLS)
217 if ("${LWS_OPENSSL_LIBRARIES}" STREQUAL "" OR "${LWS_OPENSSL_INCLUDE_DIRS}" STREQUAL "")
219 set(OPENSSL_LIBRARIES ${LWS_OPENSSL_LIBRARIES})
220 set(OPENSSL_INCLUDE_DIRS ${LWS_OPENSSL_INCLUDE_DIRS})
225 if (LWS_WITH_SSL AND LWS_USE_WOLFSSL)
226 if ("${LWS_WOLFSSL_LIBRARIES}" STREQUAL "" OR "${LWS_WOLFSSL_INCLUDE_DIRS}" STREQUAL "")
227 if (NOT WOLFSSL_FOUND)
229 message(FATAL_ERROR "You must set LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS when LWS_USE_CYASSL is turned on.")
231 message(FATAL_ERROR "You must set LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS when LWS_USE_WOLFSSL is turned on.")
235 set(WOLFSSL_LIBRARIES ${LWS_WOLFSSL_LIBRARIES})
236 set(WOLFSSL_INCLUDE_DIRS ${LWS_WOLFSSL_INCLUDE_DIRS})
241 set(USE_OLD_CYASSL 1)
245 if (LWS_WITH_SSL AND LWS_USE_POLARSSL)
246 if ("${LWS_POLARSSL_LIBRARIES}" STREQUAL "" OR "${LWS_POLARSSL_INCLUDE_DIRS}" STREQUAL "")
247 if (NOT POLARSSL_FOUND)
248 message(FATAL_ERROR "You must set LWS_POLARSSL_LIBRARIES and LWS_POLARSSL_INCLUDE_DIRS when LWS_USE_POLARSSL is turned on.")
251 set(POLARSSL_LIBRARIES ${LWS_POLARSSL_LIBRARIES})
252 set(POLARSSL_INCLUDE_DIRS ${LWS_POLARSSL_INCLUDE_DIRS})
253 set(POLARSSL_FOUND 1)
258 if (LWS_WITH_SSL AND LWS_USE_MBEDTLS)
259 if ("${LWS_MBEDTLS_LIBRARIES}" STREQUAL "" OR "${LWS_MBEDTLS_INCLUDE_DIRS}" STREQUAL "")
260 if (NOT MBEDTLS_FOUND)
261 message(FATAL_ERROR "You must set LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS when LWS_USE_MBEDTLS is turned on.")
264 set(MBEDTLS_LIBRARIES ${LWS_MBEDTLS_LIBRARIES})
265 set(MBEDTLS_INCLUDE_DIRS ${LWS_MBEDTLS_INCLUDE_DIRS})
271 if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB)
272 if ("${LWS_ZLIB_LIBRARIES}" STREQUAL "" OR "${LWS_ZLIB_INCLUDE_DIRS}" STREQUAL "")
274 set(ZLIB_LIBRARIES ${LWS_ZLIB_LIBRARIES})
275 set(ZLIB_INCLUDE_DIRS ${LWS_ZLIB_INCLUDE_DIRS})
281 if ("${LWS_LIBEV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEV_INCLUDE_DIRS}" STREQUAL "")
283 set(LIBEV_LIBRARIES ${LWS_LIBEV_LIBRARIES})
284 set(LIBEV_INCLUDE_DIRS ${LWS_LIBEV_INCLUDE_DIRS})
290 if ("${LWS_LIBUV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBUV_INCLUDE_DIRS}" STREQUAL "")
292 set(LIBUV_LIBRARIES ${LWS_LIBUV_LIBRARIES})
293 set(LIBUV_INCLUDE_DIRS ${LWS_LIBUV_INCLUDE_DIRS})
298 if (LWS_WITH_SQLITE3)
299 if ("${LWS_SQLITE3_LIBRARIES}" STREQUAL "" OR "${LWS_SQLITE3_INCLUDE_DIRS}" STREQUAL "")
301 set(SQLITE3_LIBRARIES ${LWS_SQLITE3_LIBRARIES})
302 set(SQLITE3_INCLUDE_DIRS ${LWS_SQLITE3_INCLUDE_DIRS})
308 # FIXME: This must be runtime-only option.
309 # The base dir where the test-apps look for the SSL certs.
310 set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory")
312 set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory")
316 message(WARNING "IPv6 does not currently work on Windows!")
319 set(LWS_UNIX_SOCK OFF)
320 message(WARNING "Windows does not support UNIX domain sockets")
323 set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory")
326 if (LWS_WITHOUT_EXTENSIONS)
327 set(LWS_NO_EXTENSIONS 1)
331 set(LWS_OPENSSL_SUPPORT 1)
334 if (LWS_SSL_CLIENT_USE_OS_CA_CERTS)
335 set(LWS_SSL_CLIENT_USE_OS_CA_CERTS 1)
338 if (LWS_WITH_LATENCY)
342 if (LWS_WITHOUT_DAEMONIZE OR WIN32)
343 set(LWS_NO_DAEMONIZE 1)
346 if (LWS_WITHOUT_SERVER)
350 if (LWS_WITHOUT_CLIENT)
367 set(LWS_USE_UNIX_SOCK 1)
374 if ("${LWS_MAX_SMP}" STREQUAL "")
380 # set(CMAKE_C_FLAGS "-D_DEBUG ${CMAKE_C_FLAGS}")
384 set(LWS_MINGW_SUPPORT 1)
385 set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}")
388 if (LWS_SSL_SERVER_WITH_ECDH_CERT)
389 set(LWS_SSL_SERVER_WITH_ECDH_CERT 1)
392 include_directories("${PROJECT_BINARY_DIR}")
394 include(CheckCSourceCompiles)
396 # Check for different inline keyword versions.
397 foreach(KEYWORD "inline" "__inline__" "__inline")
398 set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}")
399 CHECK_C_SOURCE_COMPILES(
402 static KEYWORD void a() {}
403 int main(int argc, char **argv) { a(); return 0; }
404 " LWS_HAVE_${KEYWORD})
407 if (NOT LWS_HAVE_inline)
408 if (LWS_HAVE___inline__)
409 set(inline __inline__)
410 elseif(LWS_HAVE___inline)
415 # Put the libaries and binaries that get built into directories at the
416 # top of the build tree rather than in hard-to-find leaf directories.
417 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
418 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
419 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
421 # Put absolute path of dynamic libraries into the object code. Some
422 # architectures, notably Mac OS X, need this.
423 SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}")
425 include(CheckFunctionExists)
426 include(CheckSymbolExists)
427 include(CheckIncludeFile)
428 include(CheckIncludeFiles)
429 include(CheckLibraryExists)
430 include(CheckTypeSize)
432 if (LWS_WITHOUT_BUILTIN_SHA1)
433 set(LWS_SHA1_USE_OPENSSL_NAME 1)
436 CHECK_FUNCTION_EXISTS(bzero LWS_HAVE_BZERO)
437 CHECK_FUNCTION_EXISTS(fork LWS_HAVE_FORK)
438 CHECK_FUNCTION_EXISTS(getenv LWS_HAVE_GETENV)
439 CHECK_FUNCTION_EXISTS(malloc LWS_HAVE_MALLOC)
440 CHECK_FUNCTION_EXISTS(memset LWS_HAVE_MEMSET)
441 CHECK_FUNCTION_EXISTS(realloc LWS_HAVE_REALLOC)
442 CHECK_FUNCTION_EXISTS(socket LWS_HAVE_SOCKET)
443 CHECK_FUNCTION_EXISTS(strerror LWS_HAVE_STRERROR)
444 CHECK_FUNCTION_EXISTS(vfork LWS_HAVE_VFORK)
445 CHECK_FUNCTION_EXISTS(execvpe LWS_HAVE_EXECVPE)
446 CHECK_FUNCTION_EXISTS(getifaddrs LWS_HAVE_GETIFADDRS)
447 CHECK_FUNCTION_EXISTS(snprintf LWS_HAVE_SNPRINTF)
448 CHECK_FUNCTION_EXISTS(_snprintf LWS_HAVE__SNPRINTF)
449 CHECK_FUNCTION_EXISTS(_vsnprintf LWS_HAVE__VSNPRINTF)
450 CHECK_FUNCTION_EXISTS(getloadavg LWS_HAVE_GETLOADAVG)
452 if (NOT LWS_HAVE_GETIFADDRS)
453 if (LWS_WITHOUT_BUILTIN_GETIFADDRS)
454 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.")
456 set(LWS_BUILTIN_GETIFADDRS 1)
459 CHECK_INCLUDE_FILE(dlfcn.h LWS_HAVE_DLFCN_H)
460 CHECK_INCLUDE_FILE(fcntl.h LWS_HAVE_FCNTL_H)
461 CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H)
462 CHECK_INCLUDE_FILE(inttypes.h LWS_HAVE_INTTYPES_H)
463 CHECK_INCLUDE_FILE(memory.h LWS_HAVE_MEMORY_H)
464 CHECK_INCLUDE_FILE(netinet/in.h LWS_HAVE_NETINET_IN_H)
465 CHECK_INCLUDE_FILE(stdint.h LWS_HAVE_STDINT_H)
466 CHECK_INCLUDE_FILE(stdlib.h LWS_HAVE_STDLIB_H)
467 CHECK_INCLUDE_FILE(strings.h LWS_HAVE_STRINGS_H)
468 CHECK_INCLUDE_FILE(string.h LWS_HAVE_STRING_H)
469 CHECK_INCLUDE_FILE(sys/prctl.h LWS_HAVE_SYS_PRCTL_H)
470 CHECK_INCLUDE_FILE(sys/socket.h LWS_HAVE_SYS_SOCKET_H)
471 CHECK_INCLUDE_FILE(sys/stat.h LWS_HAVE_SYS_STAT_H)
472 CHECK_INCLUDE_FILE(sys/types.h LWS_HAVE_SYS_TYPES_H)
473 CHECK_INCLUDE_FILE(unistd.h LWS_HAVE_UNISTD_H)
474 CHECK_INCLUDE_FILE(vfork.h LWS_HAVE_VFORK_H)
476 if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB)
477 CHECK_INCLUDE_FILE(zlib.h LWS_HAVE_ZLIB_H)
480 # TODO: These can also be tested to see whether they actually work...
481 set(LWS_HAVE_WORKING_FORK LWS_HAVE_FORK)
482 set(LWS_HAVE_WORKING_VFORK LWS_HAVE_VFORK)
484 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
486 # These don't work Cross...
487 #CHECK_TYPE_SIZE(pid_t PID_T_SIZE)
488 #CHECK_TYPE_SIZE(size_t SIZE_T_SIZE)
489 #CHECK_TYPE_SIZE("void *" LWS_SIZEOFPTR LANGUAGE C)
496 set(size_t "unsigned int")
499 if (NOT LWS_HAVE_MALLOC)
500 set(malloc rpl_malloc)
503 if (NOT LWS_HAVE_REALLOC)
504 set(realloc rpl_realloc)
509 # Turn off stupid microsoft security warnings.
510 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
513 include_directories("${PROJECT_SOURCE_DIR}/lib")
515 # Group headers and sources.
516 # Some IDEs use this for nicer file structure.
518 lib/private-libwebsockets.h)
521 "${PROJECT_SOURCE_DIR}/lib/libwebsockets.h"
522 "${PROJECT_BINARY_DIR}/lws_config.h")
536 if (NOT LWS_WITHOUT_CLIENT)
539 lib/client-handshake.c
547 if (NOT LWS_WITHOUT_SERVER)
551 if (NOT LWS_WITHOUT_CLIENT)
557 if (NOT LWS_WITHOUT_BUILTIN_SHA1)
568 # select the active platform files
576 lib/lws-plat-mbed3.cpp
577 lib/lws-plat-mbed3.c)
584 if (NOT LWS_WITHOUT_SERVER)
587 lib/server-handshake.c)
590 if (NOT LWS_WITHOUT_EXTENSIONS)
591 list(APPEND HDR_PRIVATE
592 lib/extension-permessage-deflate.h)
595 lib/extension-permessage-deflate.c)
598 if (LWS_WITH_HTTP_PROXY)
616 list(APPEND HDR_PUBLIC
619 if (LWS_WITH_LEJP_CONF)
630 # Add helper files for Windows.
632 set(WIN32_HELPERS_PATH win32port/win32helpers)
633 include_directories(${WIN32_HELPERS_PATH})
637 ${WIN32_HELPERS_PATH}/gettimeofday.c
640 list(APPEND HDR_PRIVATE
641 ${WIN32_HELPERS_PATH}/gettimeofday.h
647 if (NOT LWS_WITHOUT_DAEMONIZE)
654 if (NOT LWS_HAVE_GETIFADDRS)
655 list(APPEND HDR_PRIVATE lib/getifaddrs.h)
656 list(APPEND SOURCES lib/getifaddrs.c)
660 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
661 include (CheckCCompilerFlag)
662 CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY)
663 if (LWS_HAVE_VISIBILITY)
664 set(VISIBILITY_FLAG -fvisibility=hidden)
667 set(CMAKE_C_FLAGS "-Wall -Werror ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
669 set(CMAKE_C_FLAGS "-Wall ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
673 if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS)
675 # jeez clang understands -pthread but dies if he sees it at link time!
676 # http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang
677 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
681 if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
682 # otherwise osx blows a bunch of openssl deprecated api errors
683 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" )
686 source_group("Headers Private" FILES ${HDR_PRIVATE})
687 source_group("Headers Public" FILES ${HDR_PUBLIC})
688 source_group("Sources" FILES ${SOURCES})
696 add_library(websockets STATIC
700 list(APPEND LWS_LIBRARIES websockets)
703 # Windows uses the same .lib ending for static libraries and shared
704 # library linker files, so rename the static library.
705 set_target_properties(websockets
707 OUTPUT_NAME websockets_static)
712 add_library(websockets_shared SHARED
716 list(APPEND LWS_LIBRARIES websockets_shared)
718 # We want the shared lib to be named "libwebsockets"
719 # not "libwebsocket_shared".
720 set_target_properties(websockets_shared
722 OUTPUT_NAME websockets)
725 # Compile as DLL (export function declarations)
727 TARGET websockets_shared
728 PROPERTY COMPILE_DEFINITIONS
734 set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES)
738 # Set the so version of the lib.
739 # Equivalent to LDFLAGS=-version-info x:x:x
740 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
741 foreach(lib ${LWS_LIBRARIES})
742 set_target_properties(${lib}
744 SOVERSION ${SOVERSION})
755 # ZLIB (Only needed for deflate extensions).
758 if (LWS_USE_BUNDLED_ZLIB)
760 set(WIN32_ZLIB_PATH "win32port/zlib")
762 ${WIN32_ZLIB_PATH}/adler32.c
763 ${WIN32_ZLIB_PATH}/compress.c
764 ${WIN32_ZLIB_PATH}/crc32.c
765 ${WIN32_ZLIB_PATH}/deflate.c
766 ${WIN32_ZLIB_PATH}/gzclose.c
767 ${WIN32_ZLIB_PATH}/gzio.c
768 ${WIN32_ZLIB_PATH}/gzlib.c
769 ${WIN32_ZLIB_PATH}/gzread.c
770 ${WIN32_ZLIB_PATH}/gzwrite.c
771 ${WIN32_ZLIB_PATH}/infback.c
772 ${WIN32_ZLIB_PATH}/inffast.c
773 ${WIN32_ZLIB_PATH}/inflate.c
774 ${WIN32_ZLIB_PATH}/inftrees.c
775 ${WIN32_ZLIB_PATH}/trees.c
776 ${WIN32_ZLIB_PATH}/uncompr.c
777 ${WIN32_ZLIB_PATH}/zutil.c)
778 add_library(zlib_internal STATIC ${ZLIB_SRCS})
779 set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
780 get_property(ZLIB_LIBRARIES TARGET zlib_internal PROPERTY LOCATION)
782 # Make sure zlib_internal is compiled before the libs.
783 foreach (lib ${LWS_LIBRARIES})
784 add_dependencies(${lib} zlib_internal)
787 message(FATAL_ERROR "Don't have bundled zlib for that platform")
789 elseif (NOT ZLIB_FOUND)
790 find_package(ZLIB REQUIRED)
792 message("zlib include dirs: ${ZLIB_INCLUDE_DIRS}")
793 message("zlib libraries: ${ZLIB_LIBRARIES}")
794 include_directories(${ZLIB_INCLUDE_DIRS})
795 list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
802 message("Compiling with SSL support")
805 # Use wolfSSL as OpenSSL replacement.
806 # TODO: Add a find_package command for this also.
807 message("wolfSSL include dir: ${WOLFSSL_INCLUDE_DIRS}")
808 message("wolfSSL libraries: ${WOLFSSL_LIBRARIES}")
810 # Additional to the root directory we need to include
811 # the wolfssl/ subdirectory which contains the OpenSSL
812 # compatibility layer headers.
815 foreach(inc ${WOLFSSL_INCLUDE_DIRS})
816 include_directories("${inc}" "${inc}/cyassl")
819 foreach(inc ${WOLFSSL_INCLUDE_DIRS})
820 include_directories("${inc}" "${inc}/wolfssl")
824 list(APPEND LIB_LIST "${WOLFSSL_LIBRARIES}")
828 if (LWS_USE_POLARSSL)
829 message("POLARSSL include dir: ${POLARSSL_INCLUDE_DIRS}")
830 message("POLARSSL libraries: ${POLARSSL_LIBRARIES}")
832 foreach(inc ${POLARSSL_INCLUDE_DIRS})
833 include_directories("${inc}" "${inc}/polarssl")
836 list(APPEND LIB_LIST "${POLARSSL_LIBRARIES}")
841 message("MBEDTLS include dir: ${MBEDTLS_INCLUDE_DIRS}")
842 message("MBEDTLS libraries: ${MBEDTLS_LIBRARIES}")
844 foreach(inc ${MBEDTLS_INCLUDE_DIRS})
845 include_directories("${inc}" "${inc}/mbedtls")
848 list(APPEND LIB_LIST "${MBEDTLS_LIBRARIES}")
853 if (NOT OPENSSL_FOUND)
854 # TODO: Add support for STATIC also.
855 find_package(OpenSSL REQUIRED)
856 set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}")
859 message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}")
860 message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
862 include_directories("${OPENSSL_INCLUDE_DIRS}")
863 list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
865 # older (0.98) Openssl lacks this
866 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
867 check_include_file(openssl/ecdh.h LWS_HAVE_OPENSSL_ECDH_H)
869 if (LWS_SSL_SERVER_WITH_ECDH_CERT AND NOT LWS_HAVE_OPENSSL_ECDH_H)
870 message(FATAL_ERROR "Missing openssl/ecdh.h, so cannot use LWS_SSL_SERVER_WITH_ECDH_CERT")
878 find_path(LIBEV_INCLUDE_DIRS NAMES ev.h)
879 find_library(LIBEV_LIBRARIES NAMES ev)
880 if(LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES)
884 message("libev include dir: ${LIBEV_INCLUDE_DIRS}")
885 message("libev libraries: ${LIBEV_LIBRARIES}")
886 include_directories("${LIBEV_INCLUDE_DIRS}")
887 list(APPEND LIB_LIST ${LIBEV_LIBRARIES})
888 endif(LWS_WITH_LIBEV)
892 find_path(LIBUV_INCLUDE_DIRS NAMES uv.h)
893 find_library(LIBUV_LIBRARIES NAMES uv)
894 if(LIBUV_INCLUDE_DIRS AND LIBUV_LIBRARIES)
898 message("libuv include dir: ${LIBUV_INCLUDE_DIRS}")
899 message("libuv libraries: ${LIBUV_LIBRARIES}")
900 include_directories("${LIBUV_INCLUDE_DIRS}")
901 list(APPEND LIB_LIST ${LIBUV_LIBRARIES})
904 if (LWS_WITH_SQLITE3)
905 if (NOT SQLITE3_FOUND)
906 find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h)
907 find_library(SQLITE3_LIBRARIES NAMES sqlite3)
908 if(SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
912 message("sqlite3 include dir: ${SQLITE3_INCLUDE_DIRS}")
913 message("sqlite3 libraries: ${SQLITE3_LIBRARIES}")
914 include_directories("${SQLITE3_INCLUDE_DIRS}")
915 list(APPEND LIB_LIST ${SQLITE3_LIBRARIES})
919 if (LWS_WITH_HTTP_PROXY)
920 find_library(LIBHUBBUB_LIBRARIES NAMES libhubbub)
921 list(APPEND LIB_LIST ${LIBHUBBUB_LIBRARIES} )
926 # Platform specific libs.
929 list(APPEND LIB_LIST ws2.lib)
931 list(APPEND LIB_LIST ws2_32.lib)
935 list(APPEND LIB_LIST m)
938 # Setup the linking for all libs.
939 foreach (lib ${LWS_LIBRARIES})
940 target_link_libraries(${lib} ${LIB_LIST})
943 set (temp ${CMAKE_REQUIRED_LIBRARIES})
944 set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST})
945 CHECK_FUNCTION_EXISTS(SSL_CTX_set1_param LWS_HAVE_SSL_CTX_set1_param)
946 set(CMAKE_REQUIRED_LIBRARIES ${temp})
947 # Generate the lws_config.h that includes all the public compilation settings.
949 "${PROJECT_SOURCE_DIR}/lws_config.h.in"
950 "${PROJECT_BINARY_DIR}/lws_config.h")
952 # Generate the lws_config.h that includes all the private compilation settings.
954 "${PROJECT_SOURCE_DIR}/lws_config_private.h.in"
955 "${PROJECT_BINARY_DIR}/lws_config_private.h")
963 if (NOT LWS_WITHOUT_TESTAPPS)
965 # Helper function for adding a test app.
967 macro(create_test_app TEST_NAME MAIN_SRC S2 S3 S4 S5 S6)
969 set(TEST_SRCS ${MAIN_SRC})
971 if ("${S2}" STREQUAL "")
973 list(APPEND TEST_SRCS ${S2})
975 if ("${S3}" STREQUAL "")
977 list(APPEND TEST_SRCS ${S3})
979 if ("${S4}" STREQUAL "")
981 list(APPEND TEST_SRCS ${S4})
983 if ("${S5}" STREQUAL "")
985 list(APPEND TEST_SRCS ${S5})
987 if ("${S6}" STREQUAL "")
989 list(APPEND TEST_SRCS ${S6})
992 list(APPEND TEST_SRCS
993 ${WIN32_HELPERS_PATH}/getopt.c
994 ${WIN32_HELPERS_PATH}/getopt_long.c
995 ${WIN32_HELPERS_PATH}/gettimeofday.c
999 ${WIN32_HELPERS_PATH}/getopt.h
1000 ${WIN32_HELPERS_PATH}/gettimeofday.h
1004 source_group("Headers Private" FILES ${TEST_HDR})
1005 source_group("Sources" FILES ${TEST_SRCS})
1006 add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
1008 if (LWS_LINK_TESTAPPS_DYNAMIC)
1009 if (NOT LWS_WITH_SHARED)
1010 message(FATAL_ERROR "Build of the shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.")
1012 target_link_libraries(${TEST_NAME} websockets_shared)
1013 add_dependencies(${TEST_NAME} websockets_shared)
1015 if (NOT LWS_WITH_STATIC)
1016 message(FATAL_ERROR "Build of the static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.")
1018 target_link_libraries(${TEST_NAME} websockets)
1019 add_dependencies(${TEST_NAME} websockets)
1022 # Set test app specific defines.
1023 set_property(TARGET ${TEST_NAME}
1024 PROPERTY COMPILE_DEFINITIONS
1025 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1028 # Prefix the binary names with libwebsockets.
1029 set_target_properties(${TEST_NAME}
1031 OUTPUT_NAME libwebsockets-${TEST_NAME})
1033 # Add to the list of tests.
1034 list(APPEND TEST_APP_LIST ${TEST_NAME})
1037 if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL AND NOT LWS_USE_POLARSSL AND NOT LWS_USE_MBEDTLS)
1038 message("Searching for OpenSSL executable and dlls")
1039 find_package(OpenSSLbins)
1040 message("OpenSSL executable: ${OPENSSL_EXECUTABLE}")
1043 if (UNIX AND LWS_WITH_PLUGINS)
1044 set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
1045 target_link_libraries(websockets dl)
1048 if (NOT LWS_WITHOUT_SERVER)
1052 if (NOT LWS_WITHOUT_TEST_SERVER)
1053 create_test_app(test-server "test-server/test-server.c"
1054 "test-server/test-server-http.c"
1055 "test-server/test-server-dumb-increment.c"
1056 "test-server/test-server-mirror.c"
1057 "test-server/test-server-status.c"
1058 "test-server/test-server-echogen.c")
1060 create_test_app(test-fuzxy "test-server/fuzxy.c"
1067 if (UNIX AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")))
1068 create_test_app(test-server-pthreads
1069 "test-server/test-server-pthreads.c"
1070 "test-server/test-server-http.c"
1071 "test-server/test-server-dumb-increment.c"
1072 "test-server/test-server-mirror.c"
1073 "test-server/test-server-status.c"
1074 "test-server/test-server-echogen.c")
1076 if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
1078 create_test_app(test-server-libev
1079 "test-server/test-server-libev.c"
1080 "test-server/test-server-http.c"
1081 "test-server/test-server-dumb-increment.c"
1082 "test-server/test-server-mirror.c"
1083 "test-server/test-server-status.c"
1084 "test-server/test-server-echogen.c")
1086 if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
1088 create_test_app(test-server-libuv
1089 "test-server/test-server-libuv.c"
1090 "test-server/test-server-http.c"
1091 "test-server/test-server-dumb-increment.c"
1092 "test-server/test-server-mirror.c"
1093 "test-server/test-server-status.c"
1094 "test-server/test-server-echogen.c")
1099 # test-server-extpoll
1101 if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL)
1102 create_test_app(test-server-extpoll "test-server/test-server.c"
1103 "test-server/test-server-http.c"
1104 "test-server/test-server-dumb-increment.c"
1105 "test-server/test-server-mirror.c"
1106 "test-server/test-server-status.c"
1107 "test-server/test-server-echogen.c")
1108 # Set defines for this executable only.
1110 TARGET test-server-extpoll
1111 PROPERTY COMPILE_DEFINITIONS
1113 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1116 # We need to link against winsock code.
1118 target_link_libraries(test-server-extpoll ws2_32.lib)
1125 if (LWS_WITH_PLUGINS)
1128 "test-server/test-server-v2.0.c"
1136 # Data files for running the test server.
1137 set(TEST_SERVER_DATA
1138 "${PROJECT_SOURCE_DIR}/test-server/favicon.ico"
1139 "${PROJECT_SOURCE_DIR}/test-server/leaf.jpg"
1140 "${PROJECT_SOURCE_DIR}/test-server/libwebsockets.org-logo.png"
1141 "${PROJECT_SOURCE_DIR}/test-server/test.html")
1143 # Generate self-signed SSL certs for the test-server.
1144 if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER)
1145 message("Generating SSL Certificates for the test-server...")
1147 set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem")
1148 set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem")
1152 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}\"")
1154 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}"
1155 RESULT_VARIABLE OPENSSL_RETURN_CODE)
1157 file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt"
1161 "libwebsockets-test\n"
1163 "none@invalid.org\n\n"
1166 # The "type" command is a bit picky with paths.
1167 file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
1168 message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
1169 message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
1172 COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
1173 COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1174 RESULT_VARIABLE OPENSSL_RETURN_CODE
1175 OUTPUT_QUIET ERROR_QUIET)
1180 if (OPENSSL_RETURN_CODE)
1181 message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
1183 message("SUCCSESFULLY generated SSL certificate")
1188 COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n"
1189 COMMAND "${OPENSSL_EXECUTABLE}"
1190 req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1191 RESULT_VARIABLE OPENSSL_RETURN_CODE
1192 OUTPUT_QUIET ERROR_QUIET)
1194 if (OPENSSL_RETURN_CODE)
1195 message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
1197 message("SUCCESSFULLY generated SSL certificate")
1201 list(APPEND TEST_SERVER_DATA
1202 "${TEST_SERVER_SSL_KEY}"
1203 "${TEST_SERVER_SSL_CERT}")
1206 add_custom_command(TARGET test-server
1208 COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server")
1210 # Copy the file needed to run the server so that the test apps can
1211 # reach them from their default output location
1212 foreach (TEST_FILE ${TEST_SERVER_DATA})
1213 if (EXISTS ${TEST_FILE})
1214 add_custom_command(TARGET test-server
1216 COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM)
1219 endif(NOT LWS_WITHOUT_SERVER)
1221 if (NOT LWS_WITHOUT_CLIENT)
1225 if (NOT LWS_WITHOUT_TEST_CLIENT)
1226 create_test_app(test-client "test-server/test-client.c" "" "" "" "" "")
1232 if (NOT LWS_WITHOUT_TEST_FRAGGLE)
1233 create_test_app(test-fraggle "test-server/test-fraggle.c" "" "" "" "" "")
1239 if (NOT LWS_WITHOUT_TEST_PING)
1240 create_test_app(test-ping "test-server/test-ping.c" "" "" "" "" "")
1245 if (NOT LWS_WITHOUT_TEST_ECHO)
1246 create_test_app(test-echo "test-server/test-echo.c" "" "" "" "" "")
1249 endif(NOT LWS_WITHOUT_CLIENT)
1252 if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
1253 macro(create_plugin PLUGIN_NAME MAIN_SRC S2 S3)
1255 set(PLUGIN_SRCS ${MAIN_SRC})
1257 if ("${S2}" STREQUAL "")
1259 list(APPEND PLUGIN_SRCS ${S2})
1261 if ("${S3}" STREQUAL "")
1263 list(APPEND PLUGIN_SRCS ${S3})
1267 list(APPEND PLUGIN_SRCS
1268 ${WIN32_HELPERS_PATH}/getopt.c
1269 ${WIN32_HELPERS_PATH}/getopt_long.c
1270 ${WIN32_HELPERS_PATH}/gettimeofday.c
1273 list(APPEND PLUGIN_HDR
1274 ${WIN32_HELPERS_PATH}/getopt.h
1275 ${WIN32_HELPERS_PATH}/gettimeofday.h
1279 source_group("Headers Private" FILES ${PLUGIN_HDR})
1280 source_group("Sources" FILES ${PLUGIN_SRCS})
1281 add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR})
1283 target_link_libraries(${PLUGIN_NAME} websockets_shared)
1284 add_dependencies(${PLUGIN_NAME} websockets_shared)
1286 # Set test app specific defines.
1287 set_property(TARGET ${PLUGIN_NAME}
1288 PROPERTY COMPILE_DEFINITIONS
1289 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
1292 # set_target_properties(${PLUGIN_NAME}
1294 # OUTPUT_NAME ${PLUGIN_NAME})
1296 list(APPEND PLUGINS_LIST ${PLUGIN_NAME})
1301 create_plugin(protocol_dumb_increment
1302 "plugins/protocol_dumb_increment.c" "" "")
1303 create_plugin(protocol_lws_mirror
1304 "plugins/protocol_lws_mirror.c" "" "")
1305 create_plugin(protocol_lws_status
1306 "plugins/protocol_lws_status.c" "" "")
1307 create_plugin(protocol_post_demo
1308 "plugins/protocol_post_demo.c" "" "")
1309 if (LWS_WITH_SERVER_STATUS)
1310 create_plugin(protocol_lws_server_status
1311 "plugins/protocol_lws_server_status.c" "" "")
1314 if (NOT LWS_WITHOUT_CLIENT)
1315 create_plugin(protocol_client_loopback_test
1316 "plugins/protocol_client_loopback_test.c" "" "")
1317 endif(NOT LWS_WITHOUT_CLIENT)
1319 if (LWS_WITH_GENERIC_SESSIONS)
1320 create_plugin(protocol_generic_sessions
1321 "plugins/generic-sessions/protocol_generic_sessions.c"
1322 "plugins/generic-sessions/utils.c"
1323 "plugins/generic-sessions/handlers.c")
1326 target_link_libraries(protocol_generic_sessions ${LWS_SQLITE3_LIBRARIES})
1328 target_link_libraries(protocol_generic_sessions sqlite3 )
1330 endif(LWS_WITH_GENERIC_SESSIONS)
1333 endif(LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
1336 # Copy OpenSSL dlls to the output directory on Windows.
1337 # (Otherwise we'll get an error when trying to run)
1339 if (WIN32 AND LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL)
1340 if(OPENSSL_BIN_FOUND)
1341 message("OpenSSL dlls found:")
1342 message(" Libeay: ${LIBEAY_BIN}")
1343 message(" SSLeay: ${SSLEAY_BIN}")
1345 foreach(TARGET_BIN ${TEST_APP_LIST})
1346 add_custom_command(TARGET ${TARGET_BIN}
1348 COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
1349 add_custom_command(TARGET ${TARGET_BIN}
1351 COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
1355 endif(NOT LWS_WITHOUT_TESTAPPS)
1358 list(APPEND LWSWS_SRCS
1363 list(APPEND LWSWS_SRCS
1364 ${WIN32_HELPERS_PATH}/getopt.c
1365 ${WIN32_HELPERS_PATH}/getopt_long.c
1366 ${WIN32_HELPERS_PATH}/gettimeofday.c
1369 list(APPEND LWSWS_HDR
1370 ${WIN32_HELPERS_PATH}/getopt.h
1371 ${WIN32_HELPERS_PATH}/gettimeofday.h
1375 source_group("Headers Private" FILES ${LWSWS_HDR})
1376 source_group("Sources" FILES ${LWSWS_SRCS})
1377 add_executable("lwsws" ${LWSWS_SRCS} ${LWSWS_HDR})
1379 target_link_libraries("lwsws" websockets_shared)
1380 add_dependencies("lwsws" websockets_shared)
1382 # Set test app specific defines.
1383 set_property(TARGET "lwsws"
1384 PROPERTY COMPILE_DEFINITIONS
1385 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1387 endif (LWS_WITH_LWSWS)
1390 # Generate documentation.
1391 # TODO: Fix this on Windows.
1392 message("Generating API documentation")
1393 file(GLOB C_FILES "${PROJECT_SOURCE_DIR}/lib/*.c")
1395 execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${PROJECT_BINARY_DIR}/doc/")
1398 COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -html ${C_FILES} ${HDR_PUBLIC}
1399 OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.html"
1403 COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -text ${C_FILES} ${HDR_PUBLIC}
1404 OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.txt"
1407 # Generate and install pkgconfig.
1408 # (This is not indented, because the tabs will be part of the output)
1409 file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc"
1410 "prefix=\"${CMAKE_INSTALL_PREFIX}\"
1411 exec_prefix=\${prefix}
1412 libdir=\${exec_prefix}/lib${LIB_SUFFIX}
1413 includedir=\${prefix}/include
1416 Description: Websockets server and client library
1417 Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
1419 Libs: -L\${libdir} -lwebsockets
1420 Cflags: -I\${includedir}"
1423 install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc"
1424 DESTINATION lib${LIB_SUFFIX}/pkgconfig)
1428 # Installation preparations.
1431 if(WIN32 AND NOT CYGWIN)
1432 set(DEF_INSTALL_CMAKE_DIR cmake)
1434 set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets)
1437 set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
1439 # Export targets (This is used for other CMake projects to easily find the libraries and include files).
1440 export(TARGETS ${LWS_LIBRARIES}
1441 FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
1442 export(PACKAGE libwebsockets)
1444 # Generate the config file for the build-tree.
1445 set(LWS__INCLUDE_DIRS
1446 "${PROJECT_SOURCE_DIR}/lib"
1447 "${PROJECT_BINARY_DIR}")
1448 set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories")
1449 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
1450 ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake
1453 # Generate the config file for the installation tree.
1454 get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE)
1455 get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE)
1458 "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}"
1459 "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir.
1461 # Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in,
1462 # we escape it here so it's evaluated when it is included instead
1463 # so that the include dirs are given relative to where the
1464 # config file is located.
1465 set(LWS__INCLUDE_DIRS
1466 "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}")
1467 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
1468 ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake
1471 # Generate version info for both build-tree and install-tree.
1472 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in
1473 ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake
1476 set_target_properties(${LWS_LIBRARIES}
1477 PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
1483 # Install libs and headers.
1484 install(TARGETS ${LWS_LIBRARIES}
1485 EXPORT LibwebsocketsTargets
1486 LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
1487 ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
1488 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT libraries # Windows DLLs
1489 PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
1490 set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
1491 set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files")
1493 # Install test apps.
1494 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_CLIENT)
1495 install(TARGETS test-client ${TEST_APP_LIST}
1496 RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR}
1498 set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files")
1503 install(TARGETS lwsws
1504 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT lwsws )
1507 # Programs shared files used by the test-server.
1508 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_SERVER)
1509 install(FILES ${TEST_SERVER_DATA}
1510 DESTINATION share/libwebsockets-test-server
1513 set(CGI_TEST_SCRIPT "${PROJECT_SOURCE_DIR}/test-server/lws-cgi-test.sh")
1514 install(FILES ${CGI_TEST_SCRIPT}
1515 PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
1516 DESTINATION share/libwebsockets-test-server
1523 if (LWS_WITH_PLUGINS)
1524 install(TARGETS ${PLUGINS_LIST}
1525 PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
1526 DESTINATION share/libwebsockets-test-server/plugins
1528 if (LWS_WITH_SERVER_STATUS)
1529 install(FILES plugins/server-status.html;plugins/lwsws-logo.png
1530 DESTINATION share/libwebsockets-test-server/server-status
1533 if (LWS_WITH_GENERIC_SESSIONS)
1535 plugins/generic-sessions/assets/lwsgs-logo.png
1536 plugins/generic-sessions/assets/seats.jpg
1537 plugins/generic-sessions/assets/failed-login.html
1538 plugins/generic-sessions/assets/lwsgs.js
1539 plugins/generic-sessions/assets/post-register-fail.html
1540 plugins/generic-sessions/assets/post-register-ok.html
1541 plugins/generic-sessions/assets/post-verify-ok.html
1542 plugins/generic-sessions/assets/post-verify-fail.html
1543 plugins/generic-sessions/assets/sent-forgot-ok.html
1544 plugins/generic-sessions/assets/sent-forgot-fail.html
1545 plugins/generic-sessions/assets/post-forgot-ok.html
1546 plugins/generic-sessions/assets/post-forgot-fail.html
1547 plugins/generic-sessions/assets/index.html
1548 DESTINATION share/libwebsockets-test-server/generic-sessions
1550 install(FILES plugins/generic-sessions/assets/successful-login.html
1551 DESTINATION share/libwebsockets-test-server/generic-sessions/needauth
1553 install(FILES plugins/generic-sessions/assets/admin-login.html
1554 DESTINATION share/libwebsockets-test-server/generic-sessions/needadmin
1560 # Install the LibwebsocketsConfig.cmake and LibwebsocketsConfigVersion.cmake
1562 "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake"
1563 "${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake"
1564 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
1566 # Install exports for the install-tree.
1567 install(EXPORT LibwebsocketsTargets
1568 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
1570 # build subdir is not part of sources
1571 set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) ".git" "build" "tgz" "tar.gz")
1573 # Most people are more used to "make dist" compared to "make package_source"
1574 add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source)
1576 include(UseRPMTools)
1578 RPMTools_ADD_RPM_TARGETS(libwebsockets libwebsockets.spec)
1581 message("---------------------------------------------------------------------")
1582 message(" Settings: (For more help do cmake -LH <srcpath>)")
1583 message("---------------------------------------------------------------------")
1584 message(" LWS_WITH_STATIC = ${LWS_WITH_STATIC}")
1585 message(" LWS_WITH_SHARED = ${LWS_WITH_SHARED}")
1586 message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)")
1587 message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}")
1588 message(" LWS_USE_WOLFSSL = ${LWS_USE_WOLFSSL} (wolfSSL/CyaSSL replacement for OpenSSL)")
1589 if (LWS_USE_WOLFSSL)
1590 message(" LWS_WOLFSSL_LIBRARIES = ${LWS_WOLFSSL_LIBRARIES}")
1591 message(" LWS_WOLFSSL_INCLUDE_DIRS = ${LWS_WOLFSSL_INCLUDE_DIRS}")
1593 message(" LWS_USE_POLARSSL = ${LWS_USE_POLARSSL} (PolarSSL replacement for OpenSSL)")
1594 message(" LWS_USE_MBEDTLS = ${LWS_USE_MBEDTLS} (mbedtls (nee Polarssl) replacement for OpenSSL)")
1595 message(" LWS_WITHOUT_BUILTIN_SHA1 = ${LWS_WITHOUT_BUILTIN_SHA1}")
1596 message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}")
1597 message(" LWS_WITHOUT_CLIENT = ${LWS_WITHOUT_CLIENT}")
1598 message(" LWS_WITHOUT_SERVER = ${LWS_WITHOUT_SERVER}")
1599 message(" LWS_LINK_TESTAPPS_DYNAMIC = ${LWS_LINK_TESTAPPS_DYNAMIC}")
1600 message(" LWS_WITHOUT_TESTAPPS = ${LWS_WITHOUT_TESTAPPS}")
1601 message(" LWS_WITHOUT_TEST_SERVER = ${LWS_WITHOUT_TEST_SERVER}")
1602 message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}")
1603 message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}")
1604 message(" LWS_WITHOUT_TEST_ECHO = ${LWS_WITHOUT_TEST_ECHO}")
1605 message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}")
1606 message(" LWS_WITHOUT_TEST_FRAGGLE = ${LWS_WITHOUT_TEST_FRAGGLE}")
1607 message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}")
1608 message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}")
1609 message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}")
1610 message(" LWS_USE_LIBEV = ${LWS_USE_LIBEV}")
1611 message(" LWS_USE_LIBUV = ${LWS_USE_LIBUV}")
1612 message(" LWS_IPV6 = ${LWS_IPV6}")
1613 message(" LWS_UNIX_SOCK = ${LWS_UNIX_SOCK}")
1614 message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}")
1615 message(" LWS_MBED3 = ${LWS_MBED3}")
1616 message(" LWS_SSL_SERVER_WITH_ECDH_CERT = ${LWS_SSL_SERVER_WITH_ECDH_CERT}")
1617 message(" LWS_MAX_SMP = ${LWS_MAX_SMP}")
1618 message(" LWS_WITH_CGI = ${LWS_WITH_CGI}")
1619 message(" LWS_HAVE_OPENSSL_ECDH_H = ${LWS_HAVE_OPENSSL_ECDH_H}")
1620 message(" LWS_HAVE_SSL_CTX_set1_param = ${LWS_HAVE_SSL_CTX_set1_param}")
1621 message(" LWS_WITH_HTTP_PROXY = ${LWS_WITH_HTTP_PROXY}")
1622 message(" LIBHUBBUB_LIBRARIES = ${LIBHUBBUB_LIBRARIES}")
1623 message(" PLUGINS = ${PLUGINS_LIST}")
1624 message(" LWS_WITH_ACCESS_LOG = ${LWS_WITH_ACCESS_LOG}")
1625 message(" LWS_WITH_SERVER_STATUS = ${LWS_WITH_SERVER_STATUS}")
1626 message(" LWS_WITH_LEJP = ${LWS_WITH_LEJP}")
1627 message(" LWS_WITH_LEJP_CONF = ${LWS_WITH_LEJP_CONF}")
1628 message(" LWS_WITH_SMTP = ${LWS_WITH_SMTP}")
1629 message(" LWS_WITH_GENERIC_SESSIONS = ${LWS_WITH_GENERIC_SESSIONS}")
1632 message("---------------------------------------------------------------------")
1634 # These will be available to parent projects including libwebsockets using add_subdirectory()
1635 set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries")
1636 if (LWS_WITH_STATIC)
1637 set(LIBWEBSOCKETS_LIBRARIES_STATIC websocket CACHE STRING "Libwebsocket static library")
1639 if (LWS_WITH_SHARED)
1640 set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library")
1643 # This must always be last!