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 "1")
12 set(CPACK_PACKAGE_VERSION_MINOR "7")
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 set(LWS_BUILD_HASH ${GIT_USER}@${GIT_HOST}-${GIT_HASH})
53 message("Git commit hash: ${LWS_BUILD_HASH}")
56 set(LWS_USE_BUNDLED_ZLIB_DEFAULT OFF)
58 set(LWS_USE_BUNDLED_ZLIB_DEFAULT ON)
61 option(LWS_WITH_STATIC "Build the static version of the library" ON)
62 option(LWS_WITH_SHARED "Build the shared version of the library" ON)
63 option(LWS_WITH_SSL "Include SSL support (default OpenSSL, wolfSSL if LWS_USE_WOLFSSL is set)" ON)
64 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)
65 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)
66 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)
67 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)
68 option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" ON)
69 option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
70 option(LWS_WITH_LIBUV "Compile with support for libuv" OFF)
71 option(LWS_USE_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_USE_BUNDLED_ZLIB_DEFAULT})
72 option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of the OS-installed CA root certs" ON)
73 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)
74 option(LWS_WITHOUT_BUILTIN_SHA1 "Don't build the lws sha-1 (eg, because openssl will provide it" OFF)
75 option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF)
76 option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF)
77 option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF)
78 option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
79 option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF)
80 option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF)
81 option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF)
82 option(LWS_WITHOUT_TEST_ECHO "Don't build the echo test application" OFF)
83 option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
84 option(LWS_WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF)
85 option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" OFF)
86 option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF)
87 option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON)
88 option(LWS_IPV6 "Compile with support for ipv6" OFF)
89 option(LWS_UNIX_SOCK "Compile with support for UNIX domain socket" OFF)
90 option(LWS_WITH_HTTP2 "Compile with support for http2" OFF)
91 option(LWS_MBED3 "Platform is MBED3" OFF)
92 option(LWS_SSL_SERVER_WITH_ECDH_CERT "Include SSL server use ECDH certificate" OFF)
93 option(LWS_WITH_CGI "Include CGI (spawn process with network-connected stdin/out/err) APIs" OFF)
94 option(LWS_WITH_HTTP_PROXY "Support for rewriting HTTP proxying" OFF)
95 option(LWS_WITH_LWSWS "Libwebsockets Webserver" OFF)
96 option(LWS_WITH_PLUGINS "Support plugins for protocols and extensions" OFF)
97 option(LWS_WITH_ACCESS_LOG "Support generating Apache-compatible access logs" OFF)
101 message(STATUS "LWS_WITH_LWSWS --> Enabling LWS_WITH_PLUGINS and LWS_WITH_LIBUV")
102 set(LWS_WITH_PLUGINS 1)
103 set(LWS_WITH_LIBUV 1)
104 set(LWS_WITH_ACCESS_LOG 1)
107 if (LWS_WITH_PLUGINS AND NOT LWS_WITH_LIBUV)
108 message(STATUS "LWS_WITH_PLUGINS --> Enabling LWS_WITH_LIBUV")
109 set(LWS_WITH_LIBUV 1)
112 if (DEFINED YOTTA_WEBSOCKETS_VERSION_STRING)
114 set(LWS_WITH_SHARED OFF)
115 set(LWS_WITH_SSL OFF)
116 set(LWS_WITH_ZLIB OFF)
117 set(LWS_WITHOUT_CLIENT ON)
118 set(LWS_WITHOUT_TESTAPPS ON)
119 set(LWS_WITHOUT_EXTENSIONS ON)
120 set(LWS_WITH_PLUGINS OFF)
122 # this implies no pthreads in the lib
128 # this implies no pthreads in the lib
133 if (LWS_WITHOUT_SERVER)
134 set(LWS_WITH_LWSWS OFF)
137 if (LWS_WITH_HTTP_PROXY AND (LWS_WITHOUT_CLIENT OR LWS_WITHOUT_SERVER))
138 message(FATAL_ERROR "You have to enable both client and server for http proxy")
141 # Allow the user to override installation directories.
142 set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
143 set(LWS_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
144 set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
145 set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files")
147 # Allow the user to use the old CyaSSL options/library in stead of wolfSSL
148 if (LWS_USE_CYASSL AND LWS_USE_WOLFSSL)
149 message(FATAL_ERROR "LWS_USE_CYASSL and LWS_USE_WOLFSSL are mutually exclusive!")
152 # Copy CyaSSL options to the wolfSSL options
153 set(LWS_USE_WOLFSSL ${LWS_USE_CYASSL} CACHE BOOL "Use wolfSSL/CyaSSL instead of OpenSSL" FORCE)
154 set(LWS_WOLFSSL_LIBRARIES ${LWS_CYASSL_LIBRARIES} CACHE PATH "Path to wolfSSL/CyaSSL libraries" FORCE)
155 set(LWS_WOLFSSL_INCLUDE_DIRS ${LWS_CYASSL_INCLUDE_DIRS} CACHE PATH "Path to wolfSSL/CyaSSL header files" FORCE)
158 if (LWS_WITHOUT_CLIENT AND LWS_WITHOUT_SERVER)
159 message(FATAL_ERROR "Makes no sense to compile with neither client nor server.")
162 if (NOT (LWS_WITH_STATIC OR LWS_WITH_SHARED))
163 message(FATAL_ERROR "Makes no sense to compile with neither static nor shared libraries.")
166 if (NOT LWS_WITHOUT_EXTENSIONS)
167 if (NOT LWS_WITH_ZLIB)
168 message(FATAL_ERROR "zlib is required for extensions.")
172 set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib library")
173 set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib include directory")
174 set(LWS_OPENSSL_LIBRARIES CACHE PATH "Path to the OpenSSL library")
175 set(LWS_OPENSSL_INCLUDE_DIRS CACHE PATH "Path to the OpenSSL include directory")
176 set(LWS_WOLFSSL_LIBRARIES CACHE PATH "Path to the wolfSSL library")
177 set(LWS_WOLFSSL_INCLUDE_DIRS CACHE PATH "Path to the wolfSSL include directory")
178 set(LWS_POLARSSL_LIBRARIES CACHE PATH "Path to the PolarSSL library")
179 set(LWS_POLARSSL_INCLUDE_DIRS CACHE PATH "Path to the PolarSSL include directory")
180 set( CACHE PATH "Path to the libev library")
181 set(LWS_LIBEV_INCLUDE_DIRS CACHE PATH "Path to the libev include directory")
182 set(LWS_LIBUV_LIBRARIES CACHE PATH "Path to the libuv library")
183 set(LWS_LIBUV_INCLUDE_DIRS CACHE PATH "Path to the libuv include directory")
185 if (NOT LWS_WITH_SSL)
186 set(LWS_WITHOUT_BUILTIN_SHA1 OFF)
189 if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL AND NOT LWS_USE_POLARSSL AND NOT LWS_USE_MBEDTLS)
190 if ("${LWS_OPENSSL_LIBRARIES}" STREQUAL "" OR "${LWS_OPENSSL_INCLUDE_DIRS}" STREQUAL "")
192 set(OPENSSL_LIBRARIES ${LWS_OPENSSL_LIBRARIES})
193 set(OPENSSL_INCLUDE_DIRS ${LWS_OPENSSL_INCLUDE_DIRS})
198 if (LWS_WITH_SSL AND LWS_USE_WOLFSSL)
199 if ("${LWS_WOLFSSL_LIBRARIES}" STREQUAL "" OR "${LWS_WOLFSSL_INCLUDE_DIRS}" STREQUAL "")
200 if (NOT WOLFSSL_FOUND)
202 message(FATAL_ERROR "You must set LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS when LWS_USE_CYASSL is turned on.")
204 message(FATAL_ERROR "You must set LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS when LWS_USE_WOLFSSL is turned on.")
208 set(WOLFSSL_LIBRARIES ${LWS_WOLFSSL_LIBRARIES})
209 set(WOLFSSL_INCLUDE_DIRS ${LWS_WOLFSSL_INCLUDE_DIRS})
214 set(USE_OLD_CYASSL 1)
218 if (LWS_WITH_SSL AND LWS_USE_POLARSSL)
219 if ("${LWS_POLARSSL_LIBRARIES}" STREQUAL "" OR "${LWS_POLARSSL_INCLUDE_DIRS}" STREQUAL "")
220 if (NOT POLARSSL_FOUND)
221 message(FATAL_ERROR "You must set LWS_POLARSSL_LIBRARIES and LWS_POLARSSL_INCLUDE_DIRS when LWS_USE_POLARSSL is turned on.")
224 set(POLARSSL_LIBRARIES ${LWS_POLARSSL_LIBRARIES})
225 set(POLARSSL_INCLUDE_DIRS ${LWS_POLARSSL_INCLUDE_DIRS})
226 set(POLARSSL_FOUND 1)
231 if (LWS_WITH_SSL AND LWS_USE_MBEDTLS)
232 if ("${LWS_MBEDTLS_LIBRARIES}" STREQUAL "" OR "${LWS_MBEDTLS_INCLUDE_DIRS}" STREQUAL "")
233 if (NOT MBEDTLS_FOUND)
234 message(FATAL_ERROR "You must set LWS_MBEDTLS_LIBRARIES and LWS_MBEDTLS_INCLUDE_DIRS when LWS_USE_MBEDTLS is turned on.")
237 set(MBEDTLS_LIBRARIES ${LWS_MBEDTLS_LIBRARIES})
238 set(MBEDTLS_INCLUDE_DIRS ${LWS_MBEDTLS_INCLUDE_DIRS})
244 if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB)
245 if ("${LWS_ZLIB_LIBRARIES}" STREQUAL "" OR "${LWS_ZLIB_INCLUDE_DIRS}" STREQUAL "")
247 set(ZLIB_LIBRARIES ${LWS_ZLIB_LIBRARIES})
248 set(ZLIB_INCLUDE_DIRS ${LWS_ZLIB_INCLUDE_DIRS})
254 if ("${LWS_LIBEV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEV_INCLUDE_DIRS}" STREQUAL "")
256 set(LIBEV_LIBRARIES ${LWS_LIBEV_LIBRARIES})
257 set(LIBEV_INCLUDE_DIRS ${LWS_LIBEV_INCLUDE_DIRS})
263 if ("${LWS_LIBUV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBUV_INCLUDE_DIRS}" STREQUAL "")
265 set(LIBUV_LIBRARIES ${LWS_LIBUV_LIBRARIES})
266 set(LIBUV_INCLUDE_DIRS ${LWS_LIBUV_INCLUDE_DIRS})
272 # FIXME: This must be runtime-only option.
273 # The base dir where the test-apps look for the SSL certs.
274 set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory")
276 set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory")
280 message(WARNING "IPv6 does not currently work on Windows!")
283 set(LWS_UNIX_SOCK OFF)
284 message(WARNING "Windows does not support UNIX domain sockets")
287 set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory")
290 if (LWS_WITHOUT_EXTENSIONS)
291 set(LWS_NO_EXTENSIONS 1)
295 set(LWS_OPENSSL_SUPPORT 1)
298 if (LWS_SSL_CLIENT_USE_OS_CA_CERTS)
299 set(LWS_SSL_CLIENT_USE_OS_CA_CERTS 1)
302 if (LWS_WITH_LATENCY)
306 if (LWS_WITHOUT_DAEMONIZE OR WIN32)
307 set(LWS_NO_DAEMONIZE 1)
310 if (LWS_WITHOUT_SERVER)
314 if (LWS_WITHOUT_CLIENT)
331 set(LWS_USE_UNIX_SOCK 1)
338 if ("${LWS_MAX_SMP}" STREQUAL "")
344 # set(CMAKE_C_FLAGS "-D_DEBUG ${CMAKE_C_FLAGS}")
348 set(LWS_MINGW_SUPPORT 1)
349 set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}")
352 if (LWS_SSL_SERVER_WITH_ECDH_CERT)
353 set(LWS_SSL_SERVER_WITH_ECDH_CERT 1)
356 include_directories("${PROJECT_BINARY_DIR}")
358 include(CheckCSourceCompiles)
360 # Check for different inline keyword versions.
361 foreach(KEYWORD "inline" "__inline__" "__inline")
362 set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}")
363 CHECK_C_SOURCE_COMPILES(
366 static KEYWORD void a() {}
367 int main(int argc, char **argv) { a(); return 0; }
368 " LWS_HAVE_${KEYWORD})
371 if (NOT LWS_HAVE_inline)
372 if (LWS_HAVE___inline__)
373 set(inline __inline__)
374 elseif(LWS_HAVE___inline)
379 # Put the libaries and binaries that get built into directories at the
380 # top of the build tree rather than in hard-to-find leaf directories.
381 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
382 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
383 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
385 # Put absolute path of dynamic libraries into the object code. Some
386 # architectures, notably Mac OS X, need this.
387 SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}")
389 include(CheckFunctionExists)
390 include(CheckSymbolExists)
391 include(CheckIncludeFile)
392 include(CheckIncludeFiles)
393 include(CheckLibraryExists)
394 include(CheckTypeSize)
396 if (LWS_WITHOUT_BUILTIN_SHA1)
397 set(LWS_SHA1_USE_OPENSSL_NAME 1)
400 CHECK_FUNCTION_EXISTS(bzero LWS_HAVE_BZERO)
401 CHECK_FUNCTION_EXISTS(fork LWS_HAVE_FORK)
402 CHECK_FUNCTION_EXISTS(getenv LWS_HAVE_GETENV)
403 CHECK_FUNCTION_EXISTS(malloc LWS_HAVE_MALLOC)
404 CHECK_FUNCTION_EXISTS(memset LWS_HAVE_MEMSET)
405 CHECK_FUNCTION_EXISTS(realloc LWS_HAVE_REALLOC)
406 CHECK_FUNCTION_EXISTS(socket LWS_HAVE_SOCKET)
407 CHECK_FUNCTION_EXISTS(strerror LWS_HAVE_STRERROR)
408 CHECK_FUNCTION_EXISTS(vfork LWS_HAVE_VFORK)
409 CHECK_FUNCTION_EXISTS(execvpe LWS_HAVE_EXECVPE)
410 CHECK_FUNCTION_EXISTS(getifaddrs LWS_HAVE_GETIFADDRS)
411 CHECK_FUNCTION_EXISTS(snprintf LWS_HAVE_SNPRINTF)
412 CHECK_FUNCTION_EXISTS(_snprintf LWS_HAVE__SNPRINTF)
413 CHECK_FUNCTION_EXISTS(_vsnprintf LWS_HAVE__VSNPRINTF)
415 if (NOT LWS_HAVE_GETIFADDRS)
416 if (LWS_WITHOUT_BUILTIN_GETIFADDRS)
417 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.")
419 set(LWS_BUILTIN_GETIFADDRS 1)
422 CHECK_INCLUDE_FILE(dlfcn.h LWS_HAVE_DLFCN_H)
423 CHECK_INCLUDE_FILE(fcntl.h LWS_HAVE_FCNTL_H)
424 CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H)
425 CHECK_INCLUDE_FILE(inttypes.h LWS_HAVE_INTTYPES_H)
426 CHECK_INCLUDE_FILE(memory.h LWS_HAVE_MEMORY_H)
427 CHECK_INCLUDE_FILE(netinet/in.h LWS_HAVE_NETINET_IN_H)
428 CHECK_INCLUDE_FILE(stdint.h LWS_HAVE_STDINT_H)
429 CHECK_INCLUDE_FILE(stdlib.h LWS_HAVE_STDLIB_H)
430 CHECK_INCLUDE_FILE(strings.h LWS_HAVE_STRINGS_H)
431 CHECK_INCLUDE_FILE(string.h LWS_HAVE_STRING_H)
432 CHECK_INCLUDE_FILE(sys/prctl.h LWS_HAVE_SYS_PRCTL_H)
433 CHECK_INCLUDE_FILE(sys/socket.h LWS_HAVE_SYS_SOCKET_H)
434 CHECK_INCLUDE_FILE(sys/stat.h LWS_HAVE_SYS_STAT_H)
435 CHECK_INCLUDE_FILE(sys/types.h LWS_HAVE_SYS_TYPES_H)
436 CHECK_INCLUDE_FILE(unistd.h LWS_HAVE_UNISTD_H)
437 CHECK_INCLUDE_FILE(vfork.h LWS_HAVE_VFORK_H)
439 if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB)
440 CHECK_INCLUDE_FILE(zlib.h LWS_HAVE_ZLIB_H)
443 # TODO: These can also be tested to see whether they actually work...
444 set(LWS_HAVE_WORKING_FORK LWS_HAVE_FORK)
445 set(LWS_HAVE_WORKING_VFORK LWS_HAVE_VFORK)
447 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
449 # These don't work Cross...
450 #CHECK_TYPE_SIZE(pid_t PID_T_SIZE)
451 #CHECK_TYPE_SIZE(size_t SIZE_T_SIZE)
452 #CHECK_TYPE_SIZE("void *" LWS_SIZEOFPTR LANGUAGE C)
459 set(size_t "unsigned int")
462 if (NOT LWS_HAVE_MALLOC)
463 set(malloc rpl_malloc)
466 if (NOT LWS_HAVE_REALLOC)
467 set(realloc rpl_realloc)
472 # Turn off stupid microsoft security warnings.
473 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
476 include_directories("${PROJECT_SOURCE_DIR}/lib")
478 # Group headers and sources.
479 # Some IDEs use this for nicer file structure.
481 lib/private-libwebsockets.h)
484 "${PROJECT_SOURCE_DIR}/lib/libwebsockets.h"
485 "${PROJECT_BINARY_DIR}/lws_config.h")
499 if (NOT LWS_WITHOUT_CLIENT)
502 lib/client-handshake.c
510 if (NOT LWS_WITHOUT_SERVER)
514 if (NOT LWS_WITHOUT_CLIENT)
520 if (NOT LWS_WITHOUT_BUILTIN_SHA1)
531 # select the active platform files
539 lib/lws-plat-mbed3.cpp
540 lib/lws-plat-mbed3.c)
547 if (NOT LWS_WITHOUT_SERVER)
550 lib/server-handshake.c)
553 if (NOT LWS_WITHOUT_EXTENSIONS)
554 list(APPEND HDR_PRIVATE
555 lib/extension-permessage-deflate.h)
558 lib/extension-permessage-deflate.c)
561 if (LWS_WITH_HTTP_PROXY)
576 # Add helper files for Windows.
578 set(WIN32_HELPERS_PATH win32port/win32helpers)
579 include_directories(${WIN32_HELPERS_PATH})
582 if (NOT LWS_WITHOUT_DAEMONIZE)
589 if (NOT LWS_HAVE_GETIFADDRS)
590 list(APPEND HDR_PRIVATE lib/getifaddrs.h)
591 list(APPEND SOURCES lib/getifaddrs.c)
595 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
596 include (CheckCCompilerFlag)
597 CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY)
598 if (LWS_HAVE_VISIBILITY)
599 set(VISIBILITY_FLAG -fvisibility=hidden)
602 set(CMAKE_C_FLAGS "-Wall -Werror ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
604 set(CMAKE_C_FLAGS "-Wall ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
608 if ((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT LWS_WITHOUT_TESTAPPS)
610 # jeez clang understands -pthread but dies if he sees it at link time!
611 # http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang
612 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" )
616 if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
617 # otherwise osx blows a bunch of openssl deprecated api errors
618 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" )
621 source_group("Headers Private" FILES ${HDR_PRIVATE})
622 source_group("Headers Public" FILES ${HDR_PUBLIC})
623 source_group("Sources" FILES ${SOURCES})
631 add_library(websockets STATIC
635 list(APPEND LWS_LIBRARIES websockets)
638 # Windows uses the same .lib ending for static libraries and shared
639 # library linker files, so rename the static library.
640 set_target_properties(websockets
642 OUTPUT_NAME websockets_static)
647 add_library(websockets_shared SHARED
651 list(APPEND LWS_LIBRARIES websockets_shared)
653 # We want the shared lib to be named "libwebsockets"
654 # not "libwebsocket_shared".
655 set_target_properties(websockets_shared
657 OUTPUT_NAME websockets)
660 # Compile as DLL (export function declarations)
662 TARGET websockets_shared
663 PROPERTY COMPILE_DEFINITIONS
669 set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES)
673 # Set the so version of the lib.
674 # Equivalent to LDFLAGS=-version-info x:x:x
675 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
676 foreach(lib ${LWS_LIBRARIES})
677 set_target_properties(${lib}
679 SOVERSION ${SOVERSION})
690 # ZLIB (Only needed for deflate extensions).
693 if (LWS_USE_BUNDLED_ZLIB)
695 set(WIN32_ZLIB_PATH "win32port/zlib")
697 ${WIN32_ZLIB_PATH}/adler32.c
698 ${WIN32_ZLIB_PATH}/compress.c
699 ${WIN32_ZLIB_PATH}/crc32.c
700 ${WIN32_ZLIB_PATH}/deflate.c
701 ${WIN32_ZLIB_PATH}/gzclose.c
702 ${WIN32_ZLIB_PATH}/gzio.c
703 ${WIN32_ZLIB_PATH}/gzlib.c
704 ${WIN32_ZLIB_PATH}/gzread.c
705 ${WIN32_ZLIB_PATH}/gzwrite.c
706 ${WIN32_ZLIB_PATH}/infback.c
707 ${WIN32_ZLIB_PATH}/inffast.c
708 ${WIN32_ZLIB_PATH}/inflate.c
709 ${WIN32_ZLIB_PATH}/inftrees.c
710 ${WIN32_ZLIB_PATH}/trees.c
711 ${WIN32_ZLIB_PATH}/uncompr.c
712 ${WIN32_ZLIB_PATH}/zutil.c)
713 add_library(zlib_internal STATIC ${ZLIB_SRCS})
714 set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
715 get_property(ZLIB_LIBRARIES TARGET zlib_internal PROPERTY LOCATION)
717 # Make sure zlib_internal is compiled before the libs.
718 foreach (lib ${LWS_LIBRARIES})
719 add_dependencies(${lib} zlib_internal)
722 message(FATAL_ERROR "Don't have bundled zlib for that platform")
724 elseif (NOT ZLIB_FOUND)
725 find_package(ZLIB REQUIRED)
727 message("zlib include dirs: ${ZLIB_INCLUDE_DIRS}")
728 message("zlib libraries: ${ZLIB_LIBRARIES}")
729 include_directories(${ZLIB_INCLUDE_DIRS})
730 list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
737 message("Compiling with SSL support")
740 # Use wolfSSL as OpenSSL replacement.
741 # TODO: Add a find_package command for this also.
742 message("wolfSSL include dir: ${WOLFSSL_INCLUDE_DIRS}")
743 message("wolfSSL libraries: ${WOLFSSL_LIBRARIES}")
745 # Additional to the root directory we need to include
746 # the wolfssl/ subdirectory which contains the OpenSSL
747 # compatibility layer headers.
750 foreach(inc ${WOLFSSL_INCLUDE_DIRS})
751 include_directories("${inc}" "${inc}/cyassl")
754 foreach(inc ${WOLFSSL_INCLUDE_DIRS})
755 include_directories("${inc}" "${inc}/wolfssl")
759 list(APPEND LIB_LIST "${WOLFSSL_LIBRARIES}")
763 if (LWS_USE_POLARSSL)
764 message("POLARSSL include dir: ${POLARSSL_INCLUDE_DIRS}")
765 message("POLARSSL libraries: ${POLARSSL_LIBRARIES}")
767 foreach(inc ${POLARSSL_INCLUDE_DIRS})
768 include_directories("${inc}" "${inc}/polarssl")
771 list(APPEND LIB_LIST "${POLARSSL_LIBRARIES}")
776 message("MBEDTLS include dir: ${MBEDTLS_INCLUDE_DIRS}")
777 message("MBEDTLS libraries: ${MBEDTLS_LIBRARIES}")
779 foreach(inc ${MBEDTLS_INCLUDE_DIRS})
780 include_directories("${inc}" "${inc}/mbedtls")
783 list(APPEND LIB_LIST "${MBEDTLS_LIBRARIES}")
788 if (NOT OPENSSL_FOUND)
789 # TODO: Add support for STATIC also.
790 find_package(OpenSSL REQUIRED)
791 set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}")
794 message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}")
795 message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
797 include_directories("${OPENSSL_INCLUDE_DIRS}")
798 list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
801 # older (0.98) Openssl lacks this
802 set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
803 check_include_file(openssl/ecdh.h LWS_HAVE_OPENSSL_ECDH_H)
805 if (LWS_SSL_SERVER_WITH_ECDH_CERT AND NOT LWS_HAVE_OPENSSL_ECDH_H)
806 message(FATAL_ERROR "Missing openssl/ecdh.h, so cannot use LWS_SSL_SERVER_WITH_ECDH_CERT")
813 find_path(LIBEV_INCLUDE_DIRS NAMES ev.h)
814 find_library(LIBEV_LIBRARIES NAMES ev)
815 if(LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES)
819 message("libev include dir: ${LIBEV_INCLUDE_DIRS}")
820 message("libev libraries: ${LIBEV_LIBRARIES}")
821 include_directories("${LIBEV_INCLUDE_DIRS}")
822 list(APPEND LIB_LIST ${LIBEV_LIBRARIES})
823 endif(LWS_WITH_LIBEV)
827 find_path(LIBUV_INCLUDE_DIRS NAMES uv.h)
828 find_library(LIBUV_LIBRARIES NAMES uv)
829 if(LIBUV_INCLUDE_DIRS AND LIBUV_LIBRARIES)
833 message("libuv include dir: ${LIBUV_INCLUDE_DIRS}")
834 message("libuv libraries: ${LIBUV_LIBRARIES}")
835 include_directories("${LIBUV_INCLUDE_DIRS}")
836 list(APPEND LIB_LIST ${LIBUV_LIBRARIES})
838 if (LWS_WITH_HTTP_PROXY)
839 find_library(LIBHUBBUB_LIBRARIES NAMES libhubbub)
840 list(APPEND LIB_LIST ${LIBHUBBUB_LIBRARIES} )
845 # Platform specific libs.
848 list(APPEND LIB_LIST ws2.lib)
850 list(APPEND LIB_LIST ws2_32.lib)
854 list(APPEND LIB_LIST m)
857 # Setup the linking for all libs.
858 foreach (lib ${LWS_LIBRARIES})
859 target_link_libraries(${lib} ${LIB_LIST})
862 set (temp ${CMAKE_REQUIRED_LIBRARIES})
863 set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST})
864 CHECK_FUNCTION_EXISTS(SSL_CTX_set1_param LWS_HAVE_SSL_CTX_set1_param)
865 set(CMAKE_REQUIRED_LIBRARIES ${temp})
866 # Generate the lws_config.h that includes all the public compilation settings.
868 "${PROJECT_SOURCE_DIR}/lws_config.h.in"
869 "${PROJECT_BINARY_DIR}/lws_config.h")
871 # Generate the lws_config.h that includes all the private compilation settings.
873 "${PROJECT_SOURCE_DIR}/lws_config_private.h.in"
874 "${PROJECT_BINARY_DIR}/lws_config_private.h")
882 if (NOT LWS_WITHOUT_TESTAPPS)
884 # Helper function for adding a test app.
886 macro(create_test_app TEST_NAME MAIN_SRC S2 S3 S4 S5 S6)
888 set(TEST_SRCS ${MAIN_SRC})
890 if ("${S2}" STREQUAL "")
892 list(APPEND TEST_SRCS ${S2})
894 if ("${S3}" STREQUAL "")
896 list(APPEND TEST_SRCS ${S3})
898 if ("${S4}" STREQUAL "")
900 list(APPEND TEST_SRCS ${S4})
902 if ("${S5}" STREQUAL "")
904 list(APPEND TEST_SRCS ${S5})
906 if ("${S6}" STREQUAL "")
908 list(APPEND TEST_SRCS ${S6})
911 list(APPEND TEST_SRCS
912 ${WIN32_HELPERS_PATH}/getopt.c
913 ${WIN32_HELPERS_PATH}/getopt_long.c
914 ${WIN32_HELPERS_PATH}/gettimeofday.c
918 ${WIN32_HELPERS_PATH}/getopt.h
919 ${WIN32_HELPERS_PATH}/gettimeofday.h
923 source_group("Headers Private" FILES ${TEST_HDR})
924 source_group("Sources" FILES ${TEST_SRCS})
925 add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
927 if (LWS_LINK_TESTAPPS_DYNAMIC)
928 if (NOT LWS_WITH_SHARED)
929 message(FATAL_ERROR "Build of the shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.")
931 target_link_libraries(${TEST_NAME} websockets_shared)
932 add_dependencies(${TEST_NAME} websockets_shared)
934 if (NOT LWS_WITH_STATIC)
935 message(FATAL_ERROR "Build of the static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.")
937 target_link_libraries(${TEST_NAME} websockets)
938 add_dependencies(${TEST_NAME} websockets)
941 # Set test app specific defines.
942 set_property(TARGET ${TEST_NAME}
943 PROPERTY COMPILE_DEFINITIONS
944 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
947 # Prefix the binary names with libwebsockets.
948 set_target_properties(${TEST_NAME}
950 OUTPUT_NAME libwebsockets-${TEST_NAME})
952 # Add to the list of tests.
953 list(APPEND TEST_APP_LIST ${TEST_NAME})
956 if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL AND NOT LWS_USE_POLARSSL AND NOT LWS_USE_MBEDTLS)
957 message("Searching for OpenSSL executable and dlls")
958 find_package(OpenSSLbins)
959 message("OpenSSL executable: ${OPENSSL_EXECUTABLE}")
962 if (UNIX AND LWS_WITH_PLUGINS)
963 set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
964 target_link_libraries(websockets dl)
967 if (NOT LWS_WITHOUT_SERVER)
971 if (NOT LWS_WITHOUT_TEST_SERVER)
972 create_test_app(test-server "test-server/test-server.c"
973 "test-server/test-server-http.c"
974 "test-server/test-server-dumb-increment.c"
975 "test-server/test-server-mirror.c"
976 "test-server/test-server-status.c"
977 "test-server/test-server-echogen.c")
979 create_test_app(test-fuzxy "test-server/fuzxy.c"
986 if (UNIX AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")))
987 create_test_app(test-server-pthreads
988 "test-server/test-server-pthreads.c"
989 "test-server/test-server-http.c"
990 "test-server/test-server-dumb-increment.c"
991 "test-server/test-server-mirror.c"
992 "test-server/test-server-status.c"
993 "test-server/test-server-echogen.c")
995 if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
997 create_test_app(test-server-libev
998 "test-server/test-server-libev.c"
999 "test-server/test-server-http.c"
1000 "test-server/test-server-dumb-increment.c"
1001 "test-server/test-server-mirror.c"
1002 "test-server/test-server-status.c"
1003 "test-server/test-server-echogen.c")
1005 if (NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
1007 create_test_app(test-server-libuv
1008 "test-server/test-server-libuv.c"
1009 "test-server/test-server-http.c"
1010 "test-server/test-server-dumb-increment.c"
1011 "test-server/test-server-mirror.c"
1012 "test-server/test-server-status.c"
1013 "test-server/test-server-echogen.c")
1018 # test-server-extpoll
1020 if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL)
1021 create_test_app(test-server-extpoll "test-server/test-server.c"
1022 "test-server/test-server-http.c"
1023 "test-server/test-server-dumb-increment.c"
1024 "test-server/test-server-mirror.c"
1025 "test-server/test-server-status.c"
1026 "test-server/test-server-echogen.c")
1027 # Set defines for this executable only.
1029 TARGET test-server-extpoll
1030 PROPERTY COMPILE_DEFINITIONS
1032 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1035 # We need to link against winsock code.
1037 target_link_libraries(test-server-extpoll ws2_32.lib)
1041 # Data files for running the test server.
1042 set(TEST_SERVER_DATA
1043 "${PROJECT_SOURCE_DIR}/test-server/favicon.ico"
1044 "${PROJECT_SOURCE_DIR}/test-server/leaf.jpg"
1045 "${PROJECT_SOURCE_DIR}/test-server/libwebsockets.org-logo.png"
1046 "${PROJECT_SOURCE_DIR}/test-server/test.html")
1048 # Generate self-signed SSL certs for the test-server.
1049 if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER)
1050 message("Generating SSL Certificates for the test-server...")
1052 set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem")
1053 set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem")
1057 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}\"")
1059 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}"
1060 RESULT_VARIABLE OPENSSL_RETURN_CODE)
1062 file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt"
1066 "libwebsockets-test\n"
1068 "none@invalid.org\n\n"
1071 # The "type" command is a bit picky with paths.
1072 file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
1073 message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
1074 message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
1077 COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
1078 COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1079 RESULT_VARIABLE OPENSSL_RETURN_CODE
1080 OUTPUT_QUIET ERROR_QUIET)
1085 if (OPENSSL_RETURN_CODE)
1086 message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
1088 message("SUCCSESFULLY generated SSL certificate")
1093 COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n"
1094 COMMAND "${OPENSSL_EXECUTABLE}"
1095 req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
1096 RESULT_VARIABLE OPENSSL_RETURN_CODE
1097 OUTPUT_QUIET ERROR_QUIET)
1099 if (OPENSSL_RETURN_CODE)
1100 message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
1102 message("SUCCESSFULLY generated SSL certificate")
1106 list(APPEND TEST_SERVER_DATA
1107 "${TEST_SERVER_SSL_KEY}"
1108 "${TEST_SERVER_SSL_CERT}")
1111 add_custom_command(TARGET test-server
1113 COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server")
1115 # Copy the file needed to run the server so that the test apps can
1116 # reach them from their default output location
1117 foreach (TEST_FILE ${TEST_SERVER_DATA})
1118 if (EXISTS ${TEST_FILE})
1119 add_custom_command(TARGET test-server
1121 COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM)
1124 endif(NOT LWS_WITHOUT_SERVER)
1126 if (NOT LWS_WITHOUT_CLIENT)
1130 if (NOT LWS_WITHOUT_TEST_CLIENT)
1131 create_test_app(test-client "test-server/test-client.c" "" "" "" "" "")
1137 if (NOT LWS_WITHOUT_TEST_FRAGGLE)
1138 create_test_app(test-fraggle "test-server/test-fraggle.c" "" "" "" "" "")
1144 if (NOT LWS_WITHOUT_TEST_PING)
1145 create_test_app(test-ping "test-server/test-ping.c" "" "" "" "" "")
1150 if (NOT LWS_WITHOUT_TEST_ECHO)
1151 create_test_app(test-echo "test-server/test-echo.c" "" "" "" "" "")
1154 endif(NOT LWS_WITHOUT_CLIENT)
1157 if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
1158 macro(create_plugin PLUGIN_NAME MAIN_SRC)
1160 set(PLUGIN_SRCS ${MAIN_SRC})
1163 list(APPEND PLUGIN_SRCSset_property
1164 ${WIN32_HELPERS_PATH}/getopt.c
1165 ${WIN32_HELPERS_PATH}/getopt_long.c
1166 ${WIN32_HELPERS_PATH}/gettimeofday.c
1169 list(APPEND PLUGIN_HDR
1170 ${WIN32_HELPERS_PATH}/getopt.h
1171 ${WIN32_HELPERS_PATH}/gettimeofday.h
1175 source_group("Headers Private" FILES ${PLUGIN_HDR})
1176 source_group("Sources" FILES ${PLUGIN_SRCS})
1177 add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR})
1179 target_link_libraries(${PLUGIN_NAME} websockets_shared)
1180 add_dependencies(${PLUGIN_NAME} websockets_shared)
1182 # Set test app specific defines.
1183 set_property(TARGET ${PLUGIN_NAME}
1184 PROPERTY COMPILE_DEFINITIONS
1185 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
1188 # set_target_properties(${PLUGIN_NAME}
1190 # OUTPUT_NAME ${PLUGIN_NAME})
1192 list(APPEND PLUGINS_LIST ${PLUGIN_NAME})
1196 create_plugin(protocol_dumb_increment
1197 "plugins/protocol_dumb_increment.c")
1198 create_plugin(protocol_lws_mirror
1199 "plugins/protocol_lws_mirror.c")
1200 create_plugin(protocol_lws_status
1201 "plugins/protocol_lws_status.c")
1202 endif(LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
1205 # Copy OpenSSL dlls to the output directory on Windows.
1206 # (Otherwise we'll get an error when trying to run)
1208 if (WIN32 AND LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL)
1209 if(OPENSSL_BIN_FOUND)
1210 message("OpenSSL dlls found:")
1211 message(" Libeay: ${LIBEAY_BIN}")
1212 message(" SSLeay: ${SSLEAY_BIN}")
1214 foreach(TARGET_BIN ${TEST_APP_LIST})
1215 add_custom_command(TARGET ${TARGET_BIN}
1217 COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
1218 add_custom_command(TARGET ${TARGET_BIN}
1220 COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
1224 endif(NOT LWS_WITHOUT_TESTAPPS)
1227 list(APPEND LWSWS_SRCS
1235 list(APPEND LWSWS_SRCS
1236 ${WIN32_HELPERS_PATH}/getopt.c
1237 ${WIN32_HELPERS_PATH}/getopt_long.c
1238 ${WIN32_HELPERS_PATH}/gettimeofday.c
1241 list(APPEND LWSWS_HDR
1242 ${WIN32_HELPERS_PATH}/getopt.h
1243 ${WIN32_HELPERS_PATH}/gettimeofday.h
1247 source_group("Headers Private" FILES ${LWSWS_HDR})
1248 source_group("Sources" FILES ${LWSWS_SRCS})
1249 add_executable("lwsws" ${LWSWS_SRCS} ${LWSWS_HDR})
1251 target_link_libraries("lwsws" websockets_shared)
1252 add_dependencies("lwsws" websockets_shared)
1254 # Set test app specific defines.
1255 set_property(TARGET "lwsws"
1256 PROPERTY COMPILE_DEFINITIONS
1257 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
1261 endif (LWS_WITH_LWSWS)
1264 # Generate documentation.
1265 # TODO: Fix this on Windows.
1266 message("Generating API documentation")
1267 file(GLOB C_FILES "${PROJECT_SOURCE_DIR}/lib/*.c")
1269 execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${PROJECT_BINARY_DIR}/doc/")
1272 COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -html ${C_FILES} ${HDR_PUBLIC}
1273 OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.html"
1277 COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -text ${C_FILES} ${HDR_PUBLIC}
1278 OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.txt"
1281 # Generate and install pkgconfig.
1282 # (This is not indented, because the tabs will be part of the output)
1283 file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc"
1284 "prefix=\"${CMAKE_INSTALL_PREFIX}\"
1285 exec_prefix=\${prefix}
1286 libdir=\${exec_prefix}/lib${LIB_SUFFIX}
1287 includedir=\${prefix}/include
1290 Description: Websockets server and client library
1291 Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
1293 Libs: -L\${libdir} -lwebsockets
1294 Cflags: -I\${includedir}"
1297 install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc"
1298 DESTINATION lib${LIB_SUFFIX}/pkgconfig)
1302 # Installation preparations.
1305 if(WIN32 AND NOT CYGWIN)
1306 set(DEF_INSTALL_CMAKE_DIR cmake)
1308 set(DEF_INSTALL_CMAKE_DIR lib${LIB_SUFFIX}/cmake/libwebsockets)
1311 set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
1313 # Export targets (This is used for other CMake projects to easily find the libraries and include files).
1314 export(TARGETS ${LWS_LIBRARIES}
1315 FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
1316 export(PACKAGE libwebsockets)
1318 # Generate the config file for the build-tree.
1319 set(LWS__INCLUDE_DIRS
1320 "${PROJECT_SOURCE_DIR}/lib"
1321 "${PROJECT_BINARY_DIR}")
1322 set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories")
1323 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
1324 ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake
1327 # Generate the config file for the installation tree.
1328 get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE)
1329 get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE)
1332 "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}"
1333 "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir.
1335 # Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in,
1336 # we escape it here so it's evaluated when it is included instead
1337 # so that the include dirs are given relative to where the
1338 # config file is located.
1339 set(LWS__INCLUDE_DIRS
1340 "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}")
1341 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
1342 ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake
1345 # Generate version info for both build-tree and install-tree.
1346 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in
1347 ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake
1350 set_target_properties(${LWS_LIBRARIES}
1351 PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
1357 # Install libs and headers.
1358 install(TARGETS ${LWS_LIBRARIES}
1359 EXPORT LibwebsocketsTargets
1360 LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
1361 ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
1362 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT libraries # Windows DLLs
1363 PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
1364 set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
1365 set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files")
1367 # Install test apps.
1368 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_CLIENT)
1369 install(TARGETS test-client ${TEST_APP_LIST}
1370 RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR}
1372 set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files")
1377 install(TARGETS lwsws
1378 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT lwsws )
1381 # Programs shared files used by the test-server.
1382 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_SERVER)
1383 install(FILES ${TEST_SERVER_DATA}
1384 DESTINATION share/libwebsockets-test-server
1387 set(CGI_TEST_SCRIPT "${PROJECT_SOURCE_DIR}/test-server/lws-cgi-test.sh")
1388 install(FILES ${CGI_TEST_SCRIPT}
1389 PERMISSIONS OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
1390 DESTINATION share/libwebsockets-test-server
1397 if (LWS_WITH_PLUGINS)
1398 install(TARGETS ${PLUGINS_LIST}
1399 PERMISSIONS OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE OWNER_READ GROUP_READ WORLD_READ
1400 DESTINATION share/libwebsockets-test-server/plugins
1404 # Install the LibwebsocketsConfig.cmake and LibwebsocketsConfigVersion.cmake
1406 "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake"
1407 "${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake"
1408 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
1410 # Install exports for the install-tree.
1411 install(EXPORT LibwebsocketsTargets
1412 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
1414 # build subdir is not part of sources
1415 set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) ".git" "build" "tgz" "tar.gz")
1417 # Most people are more used to "make dist" compared to "make package_source"
1418 add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source)
1420 include(UseRPMTools)
1422 RPMTools_ADD_RPM_TARGETS(libwebsockets libwebsockets.spec)
1425 message("---------------------------------------------------------------------")
1426 message(" Settings: (For more help do cmake -LH <srcpath>)")
1427 message("---------------------------------------------------------------------")
1428 message(" LWS_WITH_STATIC = ${LWS_WITH_STATIC}")
1429 message(" LWS_WITH_SHARED = ${LWS_WITH_SHARED}")
1430 message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)")
1431 message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}")
1432 message(" LWS_USE_WOLFSSL = ${LWS_USE_WOLFSSL} (wolfSSL/CyaSSL replacement for OpenSSL)")
1433 if (LWS_USE_WOLFSSL)
1434 message(" LWS_WOLFSSL_LIBRARIES = ${LWS_WOLFSSL_LIBRARIES}")
1435 message(" LWS_WOLFSSL_INCLUDE_DIRS = ${LWS_WOLFSSL_INCLUDE_DIRS}")
1437 message(" LWS_USE_POLARSSL = ${LWS_USE_POLARSSL} (PolarSSL replacement for OpenSSL)")
1438 message(" LWS_USE_MBEDTLS = ${LWS_USE_MBEDTLS} (mbedtls (nee Polarssl) replacement for OpenSSL)")
1439 message(" LWS_WITHOUT_BUILTIN_SHA1 = ${LWS_WITHOUT_BUILTIN_SHA1}")
1440 message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}")
1441 message(" LWS_WITHOUT_CLIENT = ${LWS_WITHOUT_CLIENT}")
1442 message(" LWS_WITHOUT_SERVER = ${LWS_WITHOUT_SERVER}")
1443 message(" LWS_LINK_TESTAPPS_DYNAMIC = ${LWS_LINK_TESTAPPS_DYNAMIC}")
1444 message(" LWS_WITHOUT_TESTAPPS = ${LWS_WITHOUT_TESTAPPS}")
1445 message(" LWS_WITHOUT_TEST_SERVER = ${LWS_WITHOUT_TEST_SERVER}")
1446 message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}")
1447 message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}")
1448 message(" LWS_WITHOUT_TEST_ECHO = ${LWS_WITHOUT_TEST_ECHO}")
1449 message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}")
1450 message(" LWS_WITHOUT_TEST_FRAGGLE = ${LWS_WITHOUT_TEST_FRAGGLE}")
1451 message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}")
1452 message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}")
1453 message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}")
1454 message(" LWS_USE_LIBEV = ${LWS_USE_LIBEV}")
1455 message(" LWS_USE_LIBUV = ${LWS_USE_LIBUV}")
1456 message(" LWS_IPV6 = ${LWS_IPV6}")
1457 message(" LWS_UNIX_SOCK = ${LWS_UNIX_SOCK}")
1458 message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}")
1459 message(" LWS_MBED3 = ${LWS_MBED3}")
1460 message(" LWS_SSL_SERVER_WITH_ECDH_CERT = ${LWS_SSL_SERVER_WITH_ECDH_CERT}")
1461 message(" LWS_MAX_SMP = ${LWS_MAX_SMP}")
1462 message(" LWS_WITH_CGI = ${LWS_WITH_CGI}")
1463 message(" LWS_HAVE_OPENSSL_ECDH_H = ${LWS_HAVE_OPENSSL_ECDH_H}")
1464 message(" LWS_HAVE_SSL_CTX_set1_param = ${LWS_HAVE_SSL_CTX_set1_param}")
1465 message(" LWS_WITH_HTTP_PROXY = ${LWS_WITH_HTTP_PROXY}")
1466 message(" LIBHUBBUB_LIBRARIES = ${LIBHUBBUB_LIBRARIES}")
1467 message(" PLUGINS = ${PLUGINS_LIST}")
1468 message(" LWS_WITH_ACCESS_LOG = ${LWS_WITH_ACCESS_LOG}")
1469 message("---------------------------------------------------------------------")
1471 # These will be available to parent projects including libwebsockets using add_subdirectory()
1472 set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries")
1473 if (LWS_WITH_STATIC)
1474 set(LIBWEBSOCKETS_LIBRARIES_STATIC websocket CACHE STRING "Libwebsocket static library")
1476 if (LWS_WITH_SHARED)
1477 set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library")
1480 # This must always be last!