1 cmake_minimum_required(VERSION 2.8)
3 project(libwebsockets C)
5 set(PACKAGE "libwebsockets")
6 set(CPACK_PACKAGE_NAME "${PACKAGE}")
7 set(CPACK_PACKAGE_VERSION_MAJOR "1")
8 set(CPACK_PACKAGE_VERSION_MINOR "3")
9 set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
10 set(CPACK_PACKAGE_VENDOR "andy@warmcat.com")
11 set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}")
12 set(SOVERSION "5.0.0")
13 set(CPACK_SOURCE_GENERATOR "TGZ")
14 set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
15 set(VERSION "${CPACK_PACKAGE_VERSION}")
17 set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION})
18 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
20 message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
22 # Try to find the current Git hash.
26 WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
27 COMMAND "${GIT_EXECUTABLE}" log -n 1 --pretty=%h
28 OUTPUT_VARIABLE GIT_HASH
29 OUTPUT_STRIP_TRAILING_WHITESPACE
32 set(LWS_BUILD_HASH ${GIT_HASH})
33 message("Git commit hash: ${LWS_BUILD_HASH}")
36 option(LWS_WITH_SSL "Include SSL support (default OpenSSL, CyaSSL if LWS_USE_CYASSL is set)" ON)
37 option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of OS installed CA root certs" ON)
38 option(LWS_USE_EXTERNAL_ZLIB "Search the system for ZLib instead of using the included one (on Windows)" OFF)
39 option(LWS_USE_CYASSL "Use CyaSSL replacement for OpenSSL. When settings this, you also need to specify LWS_CYASSL_LIB and LWS_CYASSL_INCLUDE_DIRS" OFF)
40 option(LWS_WITHOUT_BUILTIN_GETIFADDRS "Don't use BSD getifaddrs implementation from libwebsockets if it is missing (this will result in a compilation error) ... Default is your libc provides it. On some systems such as uclibc it doesn't exist." OFF)
41 option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF)
42 option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF)
43 option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF)
44 option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
45 option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF)
46 option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF)
47 option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF)
48 option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
49 option(LWS_WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF)
50 option(LWS_WITHOUT_DEBUG "Don't compile debug related code" OFF)
51 option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" OFF)
52 option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF)
53 option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" OFF)
54 option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
55 option(LWS_IPV6 "Compile with support for ipv6" ON)
56 option(LWS_WITH_HTTP2 "Compile with support for http2" OFF)
58 # Allow the user to override installation directories.
59 set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
60 set(LWS_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
61 set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
62 set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files")
64 if (LWS_WITHOUT_CLIENT AND LWS_WITHOUT_SERVER)
65 message(FATAL_ERROR "Makes no sense to compile without both client or server.")
68 # The base dir where the test-apps look for the SSL certs.
69 set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory")
71 set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory")
75 message(WARNING "IPv6 does currently not work on Windows!")
78 set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory")
81 set(LWS_CYASSL_LIB CACHE PATH "Path to the CyaSSL library")
82 set(LWS_CYASSL_INCLUDE_DIRS CACHE PATH "Path to the CyaSSL include directory")
85 if ("${LWS_CYASSL_LIB}" STREQUAL "" OR "${LWS_CYASSL_INCLUDE_DIRS}" STREQUAL "")
86 message(FATAL_ERROR "You must set LWS_CYASSL_LIB and LWS_CYASSL_INCLUDE_DIRS when LWS_USE_CYASSL is turned on")
91 if (LWS_WITHOUT_EXTENSIONS)
92 set(LWS_NO_EXTENSIONS 1)
96 set(LWS_OPENSSL_SUPPORT 1)
99 if (LWS_SSL_CLIENT_USE_OS_CA_CERTS)
100 set(LWS_SSL_CLIENT_USE_OS_CA_CERTS 1)
103 if (LWS_WITH_LATENCY)
107 if (LWS_WITHOUT_DAEMONIZE OR WIN32)
108 set(LWS_NO_DAEMONIZE 1)
111 if (LWS_WITHOUT_SERVER)
115 if (LWS_WITHOUT_CLIENT)
119 if (LWS_WITHOUT_DEBUG)
127 set(LWS_NO_EXTERNAL_POLL 1)
139 set(LWS_MINGW_SUPPORT 1)
142 include_directories("${PROJECT_BINARY_DIR}")
144 include(CheckCSourceCompiles)
146 # Check for different inline keyword versions.
147 foreach(KEYWORD "inline" "__inline__" "__inline")
148 set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}")
149 CHECK_C_SOURCE_COMPILES(
153 int main(int argc, char **argv) { a(); return 0; }
159 set(inline __inline__)
160 elseif(HAVE___inline)
165 # Put the libaries and binaries that get built into directories at the
166 # top of the build tree rather than in hard-to-find leaf directories.
167 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
168 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
169 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
171 # Put absolute path of dynamic libraries into the object code. Some
172 # architectures, notably Mac OS X, need this.
173 SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}")
175 # So we can include the CMake generated config file only when
176 # building with CMAKE.
177 add_definitions(-DCMAKE_BUILD)
179 include(CheckFunctionExists)
180 include(CheckIncludeFile)
181 include(CheckIncludeFiles)
182 include(CheckLibraryExists)
183 include(CheckTypeSize)
185 CHECK_FUNCTION_EXISTS(bzero HAVE_BZERO)
186 CHECK_FUNCTION_EXISTS(fork HAVE_FORK)
187 CHECK_FUNCTION_EXISTS(getenv HAVE_GETENV)
188 CHECK_FUNCTION_EXISTS(malloc HAVE_MALLOC)
189 CHECK_FUNCTION_EXISTS(memset HAVE_MEMSET)
190 CHECK_FUNCTION_EXISTS(realloc HAVE_REALLOC)
191 CHECK_FUNCTION_EXISTS(socket HAVE_SOCKET)
192 CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
193 CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK)
194 CHECK_FUNCTION_EXISTS(getifaddrs HAVE_GETIFADDRS)
196 if (NOT HAVE_GETIFADDRS)
197 if (LWS_WITHOUT_BUILTIN_GETIFADDRS)
198 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.")
201 set(LWS_BUILTIN_GETIFADDRS 1)
204 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
205 CHECK_INCLUDE_FILE(fcntl.h HAVE_FCNTL_H)
206 CHECK_INCLUDE_FILE(in6addr.h HAVE_IN6ADDR_H)
207 CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
208 CHECK_INCLUDE_FILE(memory.h HAVE_MEMORY_H)
209 CHECK_INCLUDE_FILE(netinet/in.h HAVE_NETINET_IN_H)
210 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
211 CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H)
212 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
213 CHECK_INCLUDE_FILE(string.h HAVE_STRING_H)
214 CHECK_INCLUDE_FILE(sys/prctl.h HAVE_SYS_PRCTL_H)
215 CHECK_INCLUDE_FILE(sys/socket.h HAVE_SYS_SOCKET_H)
216 CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
217 CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
218 CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
219 CHECK_INCLUDE_FILE(vfork.h HAVE_VFORK_H)
220 CHECK_INCLUDE_FILE(zlib.h HAVE_ZLIB_H)
222 # TODO: These can be tested if they actually work also...
223 set(HAVE_WORKING_FORK HAVE_FORK)
224 set(HAVE_WORKING_VFORK HAVE_VFORK)
226 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
228 CHECK_TYPE_SIZE(pid_t PID_T_SIZE)
229 CHECK_TYPE_SIZE(size_t SIZE_T_SIZE)
236 set(size_t "unsigned int")
240 set(malloc rpl_malloc)
243 if (NOT HAVE_REALLOC)
244 set(realloc rpl_realloc)
247 # Generate the config.h that includes all the compilation settings.
249 "${PROJECT_SOURCE_DIR}/config.h.cmake"
250 "${PROJECT_BINARY_DIR}/lws_config.h")
253 # Turn off stupid microsoft security warnings.
254 add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
257 include_directories("${PROJECT_SOURCE_DIR}/lib")
259 # Group headers and sources.
260 # Some IDEs use this for nicer file structure.
262 lib/private-libwebsockets.h
266 "${PROJECT_SOURCE_DIR}/lib/libwebsockets.h"
267 "${PROJECT_BINARY_DIR}/lws_config.h"
282 if (NOT LWS_WITHOUT_CLIENT)
285 lib/client-handshake.c
303 # select the active platform files
315 if (NOT LWS_WITHOUT_SERVER)
318 lib/server-handshake.c
322 if (NOT LWS_WITHOUT_EXTENSIONS)
323 list(APPEND HDR_PRIVATE
324 lib/extension-deflate-frame.h
325 lib/extension-deflate-stream.h
330 lib/extension-deflate-frame.c
331 lib/extension-deflate-stream.c
339 endif(LWS_WITH_LIBEV)
341 # Add helper files for Windows.
343 set(WIN32_HELPERS_PATH win32port/win32helpers)
344 include_directories(${WIN32_HELPERS_PATH})
347 if (NOT LWS_WITHOUT_DAEMONIZE)
355 if (NOT HAVE_GETIFADDRS)
356 list(APPEND HDR_PRIVATE lib/getifaddrs.h)
357 list(APPEND SOURCES lib/getifaddrs.c)
362 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
364 set( CMAKE_C_FLAGS "-Wall -Werror -O3 -fvisibility=hidden ${CMAKE_C_FLAGS}" )
366 set( CMAKE_C_FLAGS "-Wall -O3 -fvisibility=hidden ${CMAKE_C_FLAGS}" )
370 source_group("Headers Private" FILES ${HDR_PRIVATE})
371 source_group("Headers Public" FILES ${HDR_PUBLIC})
372 source_group("Sources" FILES ${SOURCES})
377 add_library(websockets STATIC
381 add_library(websockets_shared SHARED
387 # On Windows libs have the same file ending (.lib)
388 # for both static and shared libraries, so we
389 # need a unique name for the static one.
390 set_target_properties(websockets
392 OUTPUT_NAME websockets_static)
394 # Compile as DLL (export function declarations)
396 TARGET websockets_shared
397 PROPERTY COMPILE_DEFINITIONS
403 # We want the shared lib to be named "libwebsockets"
404 # not "libwebsocket_shared".
405 set_target_properties(websockets_shared
407 OUTPUT_NAME websockets)
409 # Set the so version of the lib.
410 # Equivalent to LDFLAGS=-version-info x:x:x
411 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
412 foreach(lib websockets websockets_shared)
413 set_target_properties(${lib}
415 SOVERSION ${SOVERSION})
426 # ZLIB (Only needed for deflate extensions).
428 if (NOT LWS_WITHOUT_EXTENSIONS)
429 if (WIN32 AND NOT LWS_USE_EXTERNAL_ZLIB)
430 message("Using included Zlib version")
432 # Compile ZLib if needed.
433 set(WIN32_ZLIB_PATH "win32port/zlib")
435 ${WIN32_ZLIB_PATH}/adler32.c
436 ${WIN32_ZLIB_PATH}/compress.c
437 ${WIN32_ZLIB_PATH}/crc32.c
438 ${WIN32_ZLIB_PATH}/deflate.c
439 ${WIN32_ZLIB_PATH}/gzclose.c
440 ${WIN32_ZLIB_PATH}/gzio.c
441 ${WIN32_ZLIB_PATH}/gzlib.c
442 ${WIN32_ZLIB_PATH}/gzread.c
443 ${WIN32_ZLIB_PATH}/gzwrite.c
444 ${WIN32_ZLIB_PATH}/infback.c
445 ${WIN32_ZLIB_PATH}/inffast.c
446 ${WIN32_ZLIB_PATH}/inflate.c
447 ${WIN32_ZLIB_PATH}/inftrees.c
448 ${WIN32_ZLIB_PATH}/trees.c
449 ${WIN32_ZLIB_PATH}/uncompr.c
450 ${WIN32_ZLIB_PATH}/zutil.c
453 # Create the library.
454 add_library(ZLIB STATIC ${ZLIB_SRCS})
456 # Set the same variables as find_package would.
457 set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
458 get_property(ZLIB_LIBRARIES TARGET ZLIB PROPERTY LOCATION)
461 find_package(ZLIB REQUIRED)
464 # Make sure ZLib is compiled before the libs.
465 foreach (lib websockets websockets_shared)
466 add_dependencies(${lib} ZLIB)
469 message("ZLib include dirs: ${ZLIB_INCLUDE_DIRS}")
470 message("ZLib libraries: ${ZLIB_LIBRARIES}")
471 include_directories(${ZLIB_INCLUDE_DIRS})
472 list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
473 endif(NOT LWS_WITHOUT_EXTENSIONS)
479 message("Compiling with SSL support")
482 # Use CyaSSL as OpenSSL replacement.
483 # TODO: Add a find_package command for this also.
484 message("CyaSSL include dir: ${LWS_CYASSL_INCLUDE_DIRS}")
485 message("CyaSSL libraries: ${LWS_CYASSL_LIB}")
487 # Additional to the root directory we need to include
488 # the cyassl/ subdirectory which contains the OpenSSL
489 # compatability layer headers.
490 foreach(inc ${LWS_CYASSL_INCLUDE_DIRS})
491 include_directories("${inc}" "${inc}/cyassl")
494 list(APPEND LIB_LIST "${LWS_CYASSL_LIB}")
496 if (OPENSSL_ROOT_DIR)
497 set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include")
498 set(OPENSSL_LIBRARIES "${OPENSSL_ROOT_DIR}/lib/libssl.so" "${OPENSSL_ROOT_DIR}/lib/libcrypto.so")
499 else(OPENSSL_ROOT_DIR)
501 # TODO: Add support for STATIC also.
502 find_package(OpenSSL REQUIRED)
503 endif(OPENSSL_ROOT_DIR)
505 message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
506 message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
508 include_directories("${OPENSSL_INCLUDE_DIR}")
509 list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
511 # Link against dynamic linking functions.
512 # (Don't link directly to libdl since it is not needed on all platforms, it's now a part of libc).
513 list(APPEND LIB_LIST ${CMAKE_DL_LIBS})
518 list(APPEND LIB_LIST "ev")
519 endif(LWS_WITH_LIBEV)
522 # Platform specific libs.
525 list(APPEND LIB_LIST ws2.lib)
527 list(APPEND LIB_LIST ws2_32.lib)
531 list(APPEND LIB_LIST m)
534 # Setup the linking for all libs.
535 foreach (lib websockets websockets_shared)
536 target_link_libraries(${lib} ${LIB_LIST})
543 if (NOT LWS_WITHOUT_TESTAPPS)
545 # Helper function for adding a test app.
547 macro(create_test_app TEST_NAME MAIN_SRC)
549 set(TEST_SRCS ${MAIN_SRC})
553 list(APPEND TEST_SRCS
554 ${WIN32_HELPERS_PATH}/getopt.c
555 ${WIN32_HELPERS_PATH}/getopt_long.c
556 ${WIN32_HELPERS_PATH}/gettimeofday.c
560 ${WIN32_HELPERS_PATH}/getopt.h
561 ${WIN32_HELPERS_PATH}/gettimeofday.h
565 source_group("Headers Private" FILES ${TEST_HDR})
566 source_group("Sources" FILES ${TEST_SRCS})
567 add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
569 if (LWS_LINK_TESTAPPS_DYNAMIC)
570 target_link_libraries(${TEST_NAME} websockets_shared)
571 add_dependencies(${TEST_NAME} websockets_shared)
572 else(LWS_LINK_TESTAPPS_DYNAMIC)
573 target_link_libraries(${TEST_NAME} websockets)
574 add_dependencies(${TEST_NAME} websockets)
575 endif(LWS_LINK_TESTAPPS_DYNAMIC)
577 # Set test app specific defines.
578 set_property(TARGET ${TEST_NAME}
579 PROPERTY COMPILE_DEFINITIONS
580 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
583 # Prefix the binary names with libwebsockets.
584 set_target_properties(${TEST_NAME}
586 OUTPUT_NAME libwebsockets-${TEST_NAME})
588 # Add to the list of tests.
589 list(APPEND TEST_APP_LIST ${TEST_NAME})
592 if (LWS_WITH_SSL AND NOT LWS_USE_CYASSL)
593 message("Searching for OpenSSL executable and dlls")
594 find_package(OpenSSLbins)
595 message("OpenSSL executable: ${OPENSSL_EXECUTABLE}")
598 if (NOT LWS_WITHOUT_SERVER)
602 if (NOT LWS_WITHOUT_TEST_SERVER)
603 create_test_app(test-server "test-server/test-server.c")
607 # test-server-extpoll
609 if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL)
610 create_test_app(test-server-extpoll "test-server/test-server.c")
611 # Set defines for this executable only.
613 TARGET test-server-extpoll
614 PROPERTY COMPILE_DEFINITIONS
616 INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
619 # We need to link against winsock code.
621 target_link_libraries(test-server-extpoll ws2_32.lib)
625 # Data files for running the test server.
627 "${PROJECT_SOURCE_DIR}/test-server/favicon.ico"
628 "${PROJECT_SOURCE_DIR}/test-server/leaf.jpg"
629 "${PROJECT_SOURCE_DIR}/test-server/libwebsockets.org-logo.png"
630 "${PROJECT_SOURCE_DIR}/test-server/test.html")
632 # Generate self-signed SSL certs for the test-server.
633 if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER)
634 message("Generating SSL Certificates for the test-server...")
636 set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem")
637 set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem")
640 file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt"
644 "libwebsockets-test\n"
646 "none@invalid.org\n\n"
649 # The "type" command is a bit picky with paths.
650 file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
651 message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
652 message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
655 COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
656 COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
657 RESULT_VARIABLE OPENSSL_RETURN_CODE)
661 if (OPENSSL_RETURN_CODE)
662 message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
664 message("SUCCSESFULLY generated SSL certificate")
669 COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n"
670 COMMAND "${OPENSSL_EXECUTABLE}"
671 req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
672 RESULT_VARIABLE OPENSSL_RETURN_CODE)
674 if (OPENSSL_RETURN_CODE)
675 message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
677 message("SUCCSESFULLY generated SSL certificate")
681 list(APPEND TEST_SERVER_DATA
682 "${TEST_SERVER_SSL_KEY}"
683 "${TEST_SERVER_SSL_CERT}")
686 add_custom_command(TARGET test-server
688 COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server")
690 # Copy the file needed to run the server so that the test apps can
691 # reach them from their default output location
692 foreach (TEST_FILE ${TEST_SERVER_DATA})
693 if (EXISTS ${TEST_FILE})
694 add_custom_command(TARGET test-server
696 COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM)
699 endif(NOT LWS_WITHOUT_SERVER)
701 if (NOT LWS_WITHOUT_CLIENT)
705 if (NOT LWS_WITHOUT_TEST_CLIENT)
706 create_test_app(test-client "test-server/test-client.c")
712 if (NOT LWS_WITHOUT_TEST_FRAGGLE)
713 create_test_app(test-fraggle "test-server/test-fraggle.c")
719 if (NOT LWS_WITHOUT_TEST_PING)
720 create_test_app(test-ping "test-server/test-ping.c")
725 if (NOT WITHOUT_TEST_ECHO)
726 create_test_app(test-echo "test-server/test-echo.c")
729 endif(NOT LWS_WITHOUT_CLIENT)
732 # Copy OpenSSL dlls to the output directory on Windows.
733 # (Otherwise we'll get an error when trying to run)
735 if (WIN32 AND LWS_WITH_SSL AND NOT LWS_USE_CYASSL)
736 if(OPENSSL_BIN_FOUND)
737 message("OpenSSL dlls found:")
738 message(" Libeay: ${LIBEAY_BIN}")
739 message(" SSLeay: ${SSLEAY_BIN}")
741 foreach(TARGET_BIN ${TEST_APP_LIST})
742 add_custom_command(TARGET ${TARGET_BIN}
744 COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
746 add_custom_command(TARGET ${TARGET_BIN}
748 COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
752 endif(NOT LWS_WITHOUT_TESTAPPS)
755 # Generate documentation.
756 # TODO: Fix this on Windows.
757 message("Generating API documentation")
758 file(GLOB C_FILES "${PROJECT_SOURCE_DIR}/lib/*.c")
759 execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${PROJECT_BINARY_DIR}/doc/")
762 COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -html ${C_FILES} ${HDR_PUBLIC}
763 OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.html"
767 COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -text ${C_FILES} ${HDR_PUBLIC}
768 OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.txt"
771 # Generate and install pkgconfig.
772 # (This is not indented, because the tabs will be part of the output)
773 file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc"
774 "prefix=\"${CMAKE_INSTALL_PREFIX}\"
775 exec_prefix=\${prefix}
776 libdir=\${exec_prefix}/lib${LIB_SUFFIX}
777 includedir=\${prefix}/include
780 Description: Websockets server and client library
781 Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}
783 Libs: -L\${libdir} -lwebsockets
784 Cflags: -I\${includedir}"
787 install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc"
788 DESTINATION lib${LIB_SUFFIX}/pkgconfig)
792 # Installation preparations.
795 if(WIN32 AND NOT CYGWIN)
796 set(DEF_INSTALL_CMAKE_DIR cmake)
798 set(DEF_INSTALL_CMAKE_DIR lib/cmake/libwebsockets)
801 set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
803 # Export targets (This is used for other CMake projects to easily find the libraries and include files).
804 export(TARGETS websockets websockets_shared
805 FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
806 export(PACKAGE libwebsockets)
808 # Generate the config file for the build-tree.
809 set(LWS__INCLUDE_DIRS
810 "${PROJECT_SOURCE_DIR}/lib"
811 "${PROJECT_BINARY_DIR}")
812 set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories")
813 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
814 ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake
817 # Generate the config file for the installation tree.
818 get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE)
819 get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE)
822 "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}"
823 "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir.
825 # Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in,
826 # we escape it here so it's evaluated when it is included instead
827 # so that the include dirs are given relative to where the
828 # config file is located.
829 set(LWS__INCLUDE_DIRS
830 "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}")
831 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in
832 ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake
835 # Generate version info for both build-tree and install-tree.
836 configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in
837 ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake
840 set_target_properties(websockets websockets_shared
841 PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
847 # Install libs and headers.
848 install(TARGETS websockets websockets_shared
849 EXPORT LibwebsocketsTargets
850 LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
851 ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
852 RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT libraries # Windows DLLs
853 PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev)
854 set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
855 set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files")
858 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_CLIENT)
859 install(TARGETS test-client ${TEST_APP_LIST}
860 RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR}
862 set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files")
865 # Programs shared files used by the test-server.
866 if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_SERVER)
867 install(FILES ${TEST_SERVER_DATA}
868 DESTINATION share/libwebsockets-test-server
872 # Install exports for the install-tree.
873 install(EXPORT LibwebsocketsTargets
874 DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev)
876 # build subdir is not part of sources
877 set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) ".git" "build" "tgz" "tar.gz")
879 # Most people are more used to "make dist" compared to "make package_source"
880 add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source)
884 RPMTools_ADD_RPM_TARGETS(libwebsockets libwebsockets.spec)
887 message("---------------------------------------------------------------------")
888 message(" Settings: (For more help do cmake -LH <srcpath>")
889 message("---------------------------------------------------------------------")
890 message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)")
891 message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}")
892 message(" LWS_USE_CYASSL = ${LWS_USE_CYASSL} (CyaSSL replacement for OpenSSL)")
894 message(" LWS_CYASSL_LIB = ${LWS_CYASSL_LIB}")
895 message(" LWS_CYASSL_INCLUDE_DIRS = ${LWS_CYASSL_INCLUDE_DIRS}")
897 message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}")
898 message(" LWS_WITHOUT_CLIENT = ${LWS_WITHOUT_CLIENT}")
899 message(" LWS_WITHOUT_SERVER = ${LWS_WITHOUT_SERVER}")
900 message(" LWS_LINK_TESTAPPS_DYNAMIC = ${LWS_LINK_TESTAPPS_DYNAMIC}")
901 message(" LWS_WITHOUT_TESTAPPS = ${LWS_WITHOUT_TESTAPPS}")
902 message(" LWS_WITHOUT_TEST_SERVER = ${LWS_WITHOUT_TEST_SERVER}")
903 message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}")
904 message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}")
905 message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}")
906 message(" LWS_WITHOUT_TEST_FRAGGLE = ${LWS_WITHOUT_TEST_FRAGGLE}")
907 message(" LWS_WITHOUT_DEBUG = ${LWS_WITHOUT_DEBUG}")
908 message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}")
909 message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}")
910 message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}")
911 message(" LWS_USE_LIBEV = ${LWS_USE_LIBEV}")
912 message(" LWS_IPV6 = ${LWS_IPV6}")
913 message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}")
914 message("---------------------------------------------------------------------")
916 # These will be available to parent projects including libwebsockets using add_subdirectory()
917 set(LIBWEBSOCKETS_LIBRARIES websocket websockets_shared CACHE STRING "Libwebsocket libraries")
918 set(LIBWEBSOCKETS_LIBRARIES_STATIC websocket CACHE STRING "Libwebsocket static library")
919 set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library")
921 # This must always be last!