-# ZLIB (needed for deflate extension and if LWS_WITH_HTTP_STREAM_COMPRESSION)
-#
-if (LWS_WITH_ZLIB)
- if (LWS_WITH_BUNDLED_ZLIB)
- if (WIN32)
- set(WIN32_ZLIB_PATH "win32port/zlib")
- set(ZLIB_SRCS
- ${WIN32_ZLIB_PATH}/adler32.c
- ${WIN32_ZLIB_PATH}/compress.c
- ${WIN32_ZLIB_PATH}/crc32.c
- ${WIN32_ZLIB_PATH}/deflate.c
- ${WIN32_ZLIB_PATH}/gzlib.c
- ${WIN32_ZLIB_PATH}/gzread.c
- ${WIN32_ZLIB_PATH}/gzwrite.c
- ${WIN32_ZLIB_PATH}/infback.c
- ${WIN32_ZLIB_PATH}/inffast.c
- ${WIN32_ZLIB_PATH}/inflate.c
- ${WIN32_ZLIB_PATH}/inftrees.c
- ${WIN32_ZLIB_PATH}/trees.c
- ${WIN32_ZLIB_PATH}/uncompr.c
- ${WIN32_ZLIB_PATH}/zutil.c)
- add_library(zlib_internal STATIC ${ZLIB_SRCS})
- set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
- get_property(ZLIB_LIBRARIES TARGET zlib_internal PROPERTY LOCATION)
- set(ZLIB_FOUND 1)
- # Make sure zlib_internal is compiled before the libs.
- foreach (lib ${LWS_LIBRARIES})
- add_dependencies(${lib} zlib_internal)
- endforeach()
- else()
- message(FATAL_ERROR "Don't have bundled zlib for that platform")
- endif()
- elseif (NOT ZLIB_FOUND)
- if (LWS_WITH_MINIZ)
- find_package(Miniz REQUIRED)
- set(ZLIB_INCLUDE_DIRS ${MINIZ_INCLUDE_DIRS})
- set(ZLIB_LIBRARIES ${MINIZ_LIBRARIES})
- else()
- find_package(ZLIB REQUIRED)
- endif()
- endif()
- message("zlib/miniz include dirs: ${ZLIB_INCLUDE_DIRS}")
- message("zlib/miniz libraries: ${ZLIB_LIBRARIES}")
- include_directories(${ZLIB_INCLUDE_DIRS})
- # done later at end of link list
- # list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
-endif()
-
-if (LWS_WITH_HTTP_BROTLI)
- list(APPEND LIB_LIST brotlienc brotlidec brotlidec)
-endif()
-
-#
-# OpenSSL
-#
-if (LWS_WITH_SSL)
- message("Compiling with SSL support")
- set(chose_ssl 0)
- if (LWS_WITH_WOLFSSL)
- # Use wolfSSL as OpenSSL replacement.
- # TODO: Add a find_package command for this also.
- message("wolfSSL include dir: ${WOLFSSL_INCLUDE_DIRS}")
- message("wolfSSL libraries: ${WOLFSSL_LIBRARIES}")
-
- # Additional to the root directory we need to include
- # the wolfssl/ subdirectory which contains the OpenSSL
- # compatibility layer headers.
-
- if (LWS_WITH_CYASSL)
- foreach(inc ${WOLFSSL_INCLUDE_DIRS})
- include_directories("${inc}" "${inc}/cyassl")
- endforeach()
- else()
- foreach(inc ${WOLFSSL_INCLUDE_DIRS})
- include_directories("${inc}" "${inc}/wolfssl")
- endforeach()
- endif()
-
- list(APPEND LIB_LIST "${WOLFSSL_LIBRARIES}")
- set(chose_ssl 1)
- endif()
-
- if (LWS_WITH_MBEDTLS)
- message("MBEDTLS include dir: ${MBEDTLS_INCLUDE_DIRS}")
- message("MBEDTLS libraries: ${MBEDTLS_LIBRARIES}")
-
- foreach(inc ${MBEDTLS_INCLUDE_DIRS})
- include_directories("${inc}" "${inc}/mbedtls")
- endforeach()
-
- list(APPEND LIB_LIST "${MBEDTLS_LIBRARIES}")
- set(chose_ssl 1)
- endif()
-
- if (NOT chose_ssl)
- if (NOT OPENSSL_FOUND AND NOT LWS_WITH_BORINGSSL)
- # TODO: Add support for STATIC also.
- if (NOT LWS_WITH_ESP32)
- find_package(OpenSSL REQUIRED)
- endif()
- set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}")
- endif()
-
- message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}")
- if (NOT LWS_WITH_ESP32)
- message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
- endif()
-
- include_directories("${OPENSSL_INCLUDE_DIRS}")
- if (NOT LWS_WITH_ESP32)
- list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
- endif()
-
- if (NOT LWS_WITH_MBEDTLS)
- # older (0.98) Openssl lacks this
- set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
- check_include_file(openssl/ecdh.h LWS_HAVE_OPENSSL_ECDH_H)
-
- if (LWS_SSL_SERVER_WITH_ECDH_CERT AND NOT LWS_HAVE_OPENSSL_ECDH_H)
- message(FATAL_ERROR "Missing openssl/ecdh.h, so cannot use LWS_SSL_SERVER_WITH_ECDH_CERT")
- endif()
- else()
- unset(LWS_HAVE_OPENSSL_ECDH_H)
- endif(NOT LWS_WITH_MBEDTLS)
- endif()
-
-endif(LWS_WITH_SSL)
-
-if (LWS_WITH_LIBEV)
- if (NOT LIBEV_FOUND)
- find_path(LIBEV_INCLUDE_DIRS NAMES ev.h)
- find_library(LIBEV_LIBRARIES NAMES ev)
- if(LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES)
- set(LIBEV_FOUND 1)
- endif()
- endif()
- message("libev include dir: ${LIBEV_INCLUDE_DIRS}")
- message("libev libraries: ${LIBEV_LIBRARIES}")
- include_directories("${LIBEV_INCLUDE_DIRS}")
- list(APPEND LIB_LIST ${LIBEV_LIBRARIES})
-endif(LWS_WITH_LIBEV)
-
-if (LWS_WITH_LIBUV)
- if (NOT LIBUV_FOUND)
- find_path(LIBUV_INCLUDE_DIRS NAMES uv.h)
- find_library(LIBUV_LIBRARIES NAMES uv)
- if(LIBUV_INCLUDE_DIRS AND LIBUV_LIBRARIES)
- set(LIBUV_FOUND 1)
- endif()
- endif()
- message("libuv include dir: ${LIBUV_INCLUDE_DIRS}")
- message("libuv libraries: ${LIBUV_LIBRARIES}")
- include_directories("${LIBUV_INCLUDE_DIRS}")
- list(APPEND LIB_LIST ${LIBUV_LIBRARIES})
-endif()
-
-if (LWS_WITH_LIBEVENT)
- if (NOT LIBEVENT_FOUND)
- find_path(LIBEVENT_INCLUDE_DIRS NAMES event2/event.h)
- find_library(LIBEVENT_LIBRARIES NAMES event)
- if(LIBEVENT_INCLUDE_DIRS AND LIBEVENT_LIBRARIES)
- set(LIBEVENT_FOUND 1)
- endif()
- endif()
- message("libevent include dir: ${LIBEVENT_INCLUDE_DIRS}")
- message("libevent libraries: ${LIBEVENT_LIBRARIES}")
- include_directories("${LIBEVENT_INCLUDE_DIRS}")
- list(APPEND LIB_LIST ${LIBEVENT_LIBRARIES})
-endif(LWS_WITH_LIBEVENT)
-
-if (LWS_WITH_SQLITE3)
- if (NOT SQLITE3_FOUND)
- find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h)
- find_library(SQLITE3_LIBRARIES NAMES sqlite3)
- if(SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
- set(SQLITE3_FOUND 1)
- endif()
- endif()
- message("sqlite3 include dir: ${SQLITE3_INCLUDE_DIRS}")
- message("sqlite3 libraries: ${SQLITE3_LIBRARIES}")
- include_directories("${SQLITE3_INCLUDE_DIRS}")
- list(APPEND LIB_LIST ${SQLITE3_LIBRARIES})
-endif()
-
-
-if (LWS_WITH_HUBBUB)
- find_library(LIBHUBBUB_LIBRARIES NAMES hubbub)
- list(APPEND LIB_LIST ${LIBHUBBUB_LIBRARIES} )
-endif()
-
-if (LWS_ROLE_DBUS)
- message("dbus include dir 1: ${LWS_DBUS_INCLUDE1}")
- message("dbus include dir 2: ${LWS_DBUS_INCLUDE2}")
- include_directories("${LWS_DBUS_INCLUDE1}")
- include_directories("${LWS_DBUS_INCLUDE2}")
- list(APPEND LIB_LIST ${LWS_DBUS_LIB})
-endif()
-
-#
-# Platform specific libs.
-#
-if (WINCE)
- list(APPEND LIB_LIST ws2.lib)
-elseif (WIN32)
- list(APPEND LIB_LIST ws2_32.lib userenv.lib psapi.lib iphlpapi.lib)
-endif()
-
-if (${CMAKE_SYSTEM_NAME} MATCHES "QNX")
- list(APPEND LIB_LIST socket)
-endif()
-
-#
-# add libs here that need to be at the end of the link order
-#
-
-if (UNIX)
- list(APPEND LIB_LIST m)
-endif()
-
-if(SMARTOS)
- list(APPEND LIB_LIST socket)
-endif()
-
-if (HAIKU)
- list(APPEND LIB_LIST network)
-endif()
-
-if (LWS_HAVE_LIBCAP)
- list(APPEND LIB_LIST cap )
-endif()
-
-if (UNIX)
- list(APPEND LIB_LIST dl)
-endif()
-
-if (LWS_WITH_ZLIB AND NOT LWS_WITH_BUNDLED_ZLIB)
- list(APPEND LIB_LIST "${ZLIB_LIBRARIES}")
-endif()
-
-# Setup the linking for all libs.
-foreach (lib ${LWS_LIBRARIES})
- target_link_libraries(${lib} ${LIB_LIST})
-endforeach()
-
-set (temp ${CMAKE_REQUIRED_LIBRARIES})
-set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIST})
-
-if (LWS_WITH_ZLIB)
- if (LWS_WITH_BUNDLED_ZLIB)
- if (WIN32)
- # it's trying to delete internal zlib entry
- LIST(REMOVE_AT CMAKE_REQUIRED_LIBRARIES 0 )
- endif()
- endif()
-endif()
-
-CHECK_FUNCTION_EXISTS(SSL_CTX_set1_param LWS_HAVE_SSL_CTX_set1_param)
-CHECK_FUNCTION_EXISTS(SSL_set_info_callback LWS_HAVE_SSL_SET_INFO_CALLBACK)
-CHECK_FUNCTION_EXISTS(X509_VERIFY_PARAM_set1_host LWS_HAVE_X509_VERIFY_PARAM_set1_host)
-CHECK_FUNCTION_EXISTS(RSA_set0_key LWS_HAVE_RSA_SET0_KEY)
-CHECK_FUNCTION_EXISTS(X509_get_key_usage LWS_HAVE_X509_get_key_usage)
-CHECK_FUNCTION_EXISTS(EVP_PKEY_new_raw_private_key LWS_HAVE_SSL_CTX_EVP_PKEY_new_raw_private_key)
-CHECK_FUNCTION_EXISTS(SSL_CTX_get0_certificate LWS_HAVE_SSL_CTX_get0_certificate)
-CHECK_FUNCTION_EXISTS(SSL_get0_alpn_selected LWS_HAVE_SSL_get0_alpn_selected)
-CHECK_FUNCTION_EXISTS(SSL_set_alpn_protos LWS_HAVE_SSL_set_alpn_protos)
-CHECK_FUNCTION_EXISTS(EVP_aes_128_cfb8 LWS_HAVE_EVP_aes_128_cfb8)
-CHECK_FUNCTION_EXISTS(EVP_aes_128_cfb128 LWS_HAVE_EVP_aes_128_cfb128)
-CHECK_FUNCTION_EXISTS(EVP_aes_192_cfb8 LWS_HAVE_EVP_aes_192_cfb8)
-CHECK_FUNCTION_EXISTS(EVP_aes_192_cfb128 LWS_HAVE_EVP_aes_192_cfb128)
-CHECK_FUNCTION_EXISTS(EVP_aes_256_cfb8 LWS_HAVE_EVP_aes_256_cfb8)
-CHECK_FUNCTION_EXISTS(EVP_aes_256_cfb128 LWS_HAVE_EVP_aes_256_cfb128)
-CHECK_FUNCTION_EXISTS(EVP_aes_128_xts LWS_HAVE_EVP_aes_128_xts)
-CHECK_FUNCTION_EXISTS(RSA_verify_pss_mgf1 LWS_HAVE_RSA_verify_pss_mgf1)
-CHECK_FUNCTION_EXISTS(HMAC_CTX_new LWS_HAVE_HMAC_CTX_new)
-CHECK_FUNCTION_EXISTS(SSL_CTX_set_ciphersuites LWS_HAVE_SSL_CTX_set_ciphersuites)
-if (LWS_WITH_SSL AND NOT LWS_WITH_MBEDTLS)
- if (UNIX)
- set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} dl)
- endif()
-CHECK_C_SOURCE_COMPILES("#include <openssl/ssl.h>\nint main(void) { STACK_OF(X509) *c = NULL; SSL_CTX *ctx = NULL; return (int)SSL_CTX_get_extra_chain_certs_only(ctx, &c); }\n" LWS_HAVE_SSL_EXTRA_CHAIN_CERTS)
-CHECK_C_SOURCE_COMPILES("#include <openssl/ssl.h>\nint main(void) { EVP_MD_CTX *md_ctx = NULL; EVP_MD_CTX_free(md_ctx); return 0; }\n" LWS_HAVE_EVP_MD_CTX_free)
-CHECK_FUNCTION_EXISTS(ECDSA_SIG_set0 LWS_HAVE_ECDSA_SIG_set0)
-CHECK_FUNCTION_EXISTS(BN_bn2binpad LWS_HAVE_BN_bn2binpad)
-CHECK_FUNCTION_EXISTS(EVP_aes_128_wrap LWS_HAVE_EVP_aes_128_wrap)
-CHECK_FUNCTION_EXISTS(EC_POINT_get_affine_coordinates LWS_HAVE_EC_POINT_get_affine_coordinates)
-endif()
-if (LWS_WITH_MBEDTLS)
- set(LWS_HAVE_TLS_CLIENT_METHOD 1)
- if (NOT LWS_WITH_ESP32)
- # not supported in esp-idf openssl wrapper yet, but is in our version
- set(LWS_HAVE_X509_VERIFY_PARAM_set1_host 1)
- endif()
-
- CHECK_FUNCTION_EXISTS(mbedtls_ssl_conf_alpn_protocols LWS_HAVE_mbedtls_ssl_conf_alpn_protocols)
- CHECK_FUNCTION_EXISTS(mbedtls_ssl_get_alpn_protocol LWS_HAVE_mbedtls_ssl_get_alpn_protocol)
- CHECK_FUNCTION_EXISTS(mbedtls_ssl_conf_sni LWS_HAVE_mbedtls_ssl_conf_sni)
- CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_ca_chain LWS_HAVE_mbedtls_ssl_set_hs_ca_chain)
- CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_own_cert LWS_HAVE_mbedtls_ssl_set_hs_own_cert)
- CHECK_FUNCTION_EXISTS(mbedtls_ssl_set_hs_authmode LWS_HAVE_mbedtls_ssl_set_hs_authmode)
- CHECK_FUNCTION_EXISTS(mbedtls_net_init LWS_HAVE_mbedtls_net_init)
-
-else()
-CHECK_FUNCTION_EXISTS(TLS_client_method LWS_HAVE_TLS_CLIENT_METHOD)
-CHECK_FUNCTION_EXISTS(TLSv1_2_client_method LWS_HAVE_TLSV1_2_CLIENT_METHOD)
-endif()
-
-# ideally we want to use pipe2()
-
-CHECK_C_SOURCE_COMPILES("#define _GNU_SOURCE\n#include <unistd.h>\nint main(void) {int fd[2];\n return pipe2(fd, 0);\n}\n" LWS_HAVE_PIPE2)
-
-# tcp keepalive needs this on linux to work practically... but it only exists
-# after kernel 2.6.37
-
-CHECK_C_SOURCE_COMPILES("#include <netinet/tcp.h>\nint main(void) { return TCP_USER_TIMEOUT; }\n" LWS_HAVE_TCP_USER_TIMEOUT)
-
-set(CMAKE_REQUIRED_LIBRARIES ${temp})
-# Generate the lws_config.h that includes all the public compilation settings.
-configure_file(
- "${PROJECT_SOURCE_DIR}/cmake/lws_config.h.in"
- "${PROJECT_BINARY_DIR}/lws_config.h")
-
-# Generate the lws_config.h that includes all the private compilation settings.
-configure_file(
- "${PROJECT_SOURCE_DIR}/cmake/lws_config_private.h.in"
- "${PROJECT_BINARY_DIR}/lws_config_private.h")
-
-# Generate self-signed SSL certs for the test-server.
-
-if (LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL)
- message("Searching for OpenSSL executable and dlls")
- find_package(OpenSSLbins)
- message("OpenSSL executable: ${OPENSSL_EXECUTABLE}")
- if (OPENSSL_EXECUTABLE MATCHES "^$")
- set(OPENSSL_EXECUTABLE openssl)
- endif()
- if (NOT OPENSSL_EXECUTABLE)
- set(OPENSSL_EXECUTABLE openssl)
- endif()
-
-endif()
-
-set(GENCERTS 0)
-
-if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER AND NOT LWS_WITHOUT_SERVER AND NOT LWS_WITHOUT_TESTAPPS)
- set(GENCERTS 1)
-endif()
-if (LWS_WITH_ESP32)
- set(GENCERTS 1)
-endif()
-message(" GENCERTS = ${GENCERTS}")
-if (GENCERTS)
- message("Generating SSL Certificates for the test-server...")
-
- set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem")
- set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem")
-
- if (WIN32)
- if (MINGW)
- 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}\"")
- execute_process(
- 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}"
- RESULT_VARIABLE OPENSSL_RETURN_CODE)
- else()
- file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt"
- "GB\n"
- "Erewhon\n"
- "All around\n"
- "libwebsockets-test\n"
- "localhost\n"
- "none@invalid.org\n\n"
- )
-
- # The "type" command is a bit picky with paths.
- file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
- message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}")
- message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"")
-
- execute_process(
- COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
- COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
- RESULT_VARIABLE OPENSSL_RETURN_CODE
- OUTPUT_QUIET ERROR_QUIET)
-
- message("\n")
- endif()
-
- if (OPENSSL_RETURN_CODE)
- message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
- else()
- message("SUCCSESFULLY generated SSL certificate")
- endif()
- else()
- # Unix.
- execute_process(
- COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n"
- COMMAND "${OPENSSL_EXECUTABLE}"
- req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
- RESULT_VARIABLE OPENSSL_RETURN_CODE
- # OUTPUT_QUIET ERROR_QUIET
- )
-
- if (OPENSSL_RETURN_CODE)
- message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}")
- else()
- message("SUCCESSFULLY generated SSL certificate")
- endif()
- endif()
-
- list(APPEND TEST_SERVER_DATA
- "${TEST_SERVER_SSL_KEY}"
- "${TEST_SERVER_SSL_CERT}")
-endif()
-
-
-
-
-#
-# Test applications
-#
-set(TEST_APP_LIST)
-if ((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS)
- #
- # Helper function for adding a test app.
- #
- macro(create_test_app TEST_NAME MAIN_SRC S2 S3 S4 S5 S6)
-
- set(TEST_SRCS ${MAIN_SRC})
- set(TEST_HDR)
- if ("${S2}" STREQUAL "")
- else()
- list(APPEND TEST_SRCS ${S2})
- endif()
- if ("${S3}" STREQUAL "")
- else()
- list(APPEND TEST_SRCS ${S3})
- endif()
- if ("${S4}" STREQUAL "")
- else()
- list(APPEND TEST_SRCS ${S4})
- endif()
- if ("${S5}" STREQUAL "")
- else()
- list(APPEND TEST_SRCS ${S5})
- endif()
- if ("${S6}" STREQUAL "")
- else()
- list(APPEND TEST_SRCS ${S6})
- endif()
- if (WIN32)
- list(APPEND TEST_SRCS
- ${WIN32_HELPERS_PATH}/getopt.c
- ${WIN32_HELPERS_PATH}/getopt_long.c
- ${WIN32_HELPERS_PATH}/gettimeofday.c
- )
-
- list(APPEND TEST_HDR
- ${WIN32_HELPERS_PATH}/getopt.h
- ${WIN32_HELPERS_PATH}/gettimeofday.h
- )
- endif(WIN32)
-
- source_group("Headers Private" FILES ${TEST_HDR})
- source_group("Sources" FILES ${TEST_SRCS})
- add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
-
- if (LWS_LINK_TESTAPPS_DYNAMIC)
- if (NOT LWS_WITH_SHARED)
- message(FATAL_ERROR "Build of the shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.")
- endif()
- target_link_libraries(${TEST_NAME} websockets_shared)
- add_dependencies(${TEST_NAME} websockets_shared)
- else()
- if (NOT LWS_WITH_STATIC)
- message(FATAL_ERROR "Build of the static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.")
- endif()
- target_link_libraries(${TEST_NAME} websockets)
- add_dependencies(${TEST_NAME} websockets)
- if (UNIX AND LWS_WITH_SSL AND NOT LWS_WITH_MBEDTLS)
- target_link_libraries(${TEST_NAME} dl)
- endif()
- endif()
-
- if (LWS_WITH_HTTP_STREAM_COMPRESSION)
- target_link_libraries(${TEST_NAME} z)
- endif()
-
- # Set test app specific defines.
- set_property(TARGET ${TEST_NAME}
- PROPERTY COMPILE_DEFINITIONS
- INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
- )
-
- # Prefix the binary names with libwebsockets.
- set_target_properties(${TEST_NAME}
- PROPERTIES
- OUTPUT_NAME libwebsockets-${TEST_NAME})
-
- # Add to the list of tests.
- list(APPEND TEST_APP_LIST ${TEST_NAME})
- endmacro()
-
- if (UNIX AND LWS_WITH_PLUGINS)
- set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
- if(NOT((${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") OR (${CMAKE_SYSTEM_NAME} MATCHES "QNX")))
- target_link_libraries(websockets dl)
- endif()
- endif()
-
- if (NOT LWS_WITHOUT_SERVER)
- #
- # test-server
- #
- if (NOT LWS_WITHOUT_TEST_SERVER)
- create_test_app(test-server "test-apps/test-server.c"
- ""
- ""
- ""
- ""
- "")
-
- if (LWS_WITH_CGI)
- create_test_app(test-sshd "test-apps/test-sshd.c"
- ""
- ""
- ""
- ""
- "")
- target_include_directories(test-sshd PRIVATE "${PROJECT_SOURCE_DIR}/plugins/ssh-base/include")
-
- endif()
-
- endif()
-
- #
- # test-server-extpoll
- #
- if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL AND NOT WIN32)
- create_test_app(test-server-extpoll
- "test-apps/test-server.c"
- ""
- ""
- ""
- ""
- "")
- # Set defines for this executable only.
- set_property(
- TARGET test-server-extpoll
- PROPERTY COMPILE_DEFINITIONS
- EXTERNAL_POLL
- INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
- )
-
- # We need to link against winsock code.
- if (WIN32)
- target_link_libraries(test-server-extpoll ws2_32.lib)
- endif(WIN32)
- endif()
-
- if (LWS_WITH_LEJP)
- create_test_app(
- test-lejp
- "test-apps/test-lejp.c"
- ""
- ""
- ""
- ""
- "")
- endif()
-
- # Data files for running the test server.
- list(APPEND TEST_SERVER_DATA
- "${PROJECT_SOURCE_DIR}/test-apps/favicon.ico"
- "${PROJECT_SOURCE_DIR}/test-apps/leaf.jpg"
- "${PROJECT_SOURCE_DIR}/test-apps/candide.zip"
- "${PROJECT_SOURCE_DIR}/test-apps/libwebsockets.org-logo.svg"
- "${PROJECT_SOURCE_DIR}/test-apps/http2.png"
- "${PROJECT_SOURCE_DIR}/test-apps/wss-over-h2.png"
- "${PROJECT_SOURCE_DIR}/test-apps/lws-common.js"
- "${PROJECT_SOURCE_DIR}/test-apps/test.html"
- "${PROJECT_SOURCE_DIR}/test-apps/test.css"
- "${PROJECT_SOURCE_DIR}/test-apps/test.js")
-
- add_custom_command(TARGET test-server
- POST_BUILD
- COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server")
-
- # Copy the file needed to run the server so that the test apps can
- # reach them from their default output location
- foreach (TEST_FILE ${TEST_SERVER_DATA})
- if (EXISTS ${TEST_FILE})
- add_custom_command(TARGET test-server
- POST_BUILD
- COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM)
- endif()
- endforeach()
- endif(NOT LWS_WITHOUT_SERVER)
-
- if (NOT LWS_WITHOUT_CLIENT)
- #
- # test-client
- #
- if (NOT LWS_WITHOUT_TEST_CLIENT)
- create_test_app(test-client "test-apps/test-client.c" "" "" "" "" "")
- endif()
-
- endif(NOT LWS_WITHOUT_CLIENT)
-
-
- if (LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
- macro(create_plugin PLUGIN_NAME PLUGIN_INCLUDE MAIN_SRC S2 S3)
-
- set(PLUGIN_SRCS ${MAIN_SRC})
-
- if ("${S2}" STREQUAL "")
- else()
- list(APPEND PLUGIN_SRCS ${S2})
- endif()
- if ("${S3}" STREQUAL "")
- else()
- list(APPEND PLUGIN_SRCS ${S3})
- endif()
-
- if (WIN32)
- list(APPEND PLUGIN_SRCS
- ${WIN32_HELPERS_PATH}/getopt.c
- ${WIN32_HELPERS_PATH}/getopt_long.c
- ${WIN32_HELPERS_PATH}/gettimeofday.c
- )
-
- list(APPEND PLUGIN_HDR
- ${WIN32_HELPERS_PATH}/getopt.h
- ${WIN32_HELPERS_PATH}/gettimeofday.h
- )
- endif(WIN32)
-
- source_group("Headers Private" FILES ${PLUGIN_HDR})
- source_group("Sources" FILES ${PLUGIN_SRCS})
- add_library(${PLUGIN_NAME} SHARED ${PLUGIN_SRCS} ${PLUGIN_HDR})
-
- target_link_libraries(${PLUGIN_NAME} websockets_shared)
- add_dependencies(${PLUGIN_NAME} websockets_shared)
- include_directories(${PLUGIN_INCLUDE})
-
- # Set test app specific defines.
- set_property(TARGET ${PLUGIN_NAME}
- PROPERTY COMPILE_DEFINITIONS
- INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/plugins"
- )
-
- SET_TARGET_PROPERTIES(${PLUGIN_NAME}
- PROPERTIES COMPILE_FLAGS ${CMAKE_C_FLAGS})
-
-# set_target_properties(${PLUGIN_NAME}
-# PROPERTIES
-# OUTPUT_NAME ${PLUGIN_NAME})
-
- list(APPEND PLUGINS_LIST ${PLUGIN_NAME})
-
- endmacro()
-
-if (LWS_ROLE_WS)
- create_plugin(protocol_dumb_increment ""
- "plugins/protocol_dumb_increment.c" "" "")
- create_plugin(protocol_lws_mirror ""
- "plugins/protocol_lws_mirror.c" "" "")
- create_plugin(protocol_lws_status ""
- "plugins/protocol_lws_status.c" "" "")
- create_plugin(protocol_lws_table_dirlisting ""
- "plugins/generic-table/protocol_table_dirlisting.c" "" "")
- if (NOT WIN32)
- create_plugin(protocol_lws_raw_test ""
- "plugins/protocol_lws_raw_test.c" "" "")
-
- create_plugin(protocol_deaddrop ""
- "plugins/deaddrop/protocol_lws_deaddrop.c" "" "")
-
- endif()
-
-if (LWS_WITH_SERVER_STATUS)
- create_plugin(protocol_lws_server_status ""
- "plugins/protocol_lws_server_status.c" "" "")
-endif()
-
-if (NOT LWS_WITHOUT_CLIENT)
- create_plugin(protocol_client_loopback_test ""
- "plugins/protocol_client_loopback_test.c" "" "")
-endif()
-
-endif()
-
- create_plugin(protocol_post_demo ""
- "plugins/protocol_post_demo.c" "" "")
-
-if (LWS_ROLE_RAW_PROXY)
- create_plugin(protocol_lws_raw_proxy ""
- "plugins/raw-proxy/protocol_lws_raw_proxy.c" "" "")
-endif()
-
-if (LWS_WITH_FTS)
- create_plugin(protocol_fulltext_demo ""
- "plugins/protocol_fulltext_demo.c" "" "")
-endif()
-
-
-if (LWS_WITH_SSL)
- create_plugin(protocol_lws_ssh_base "plugins/ssh-base/include"
- "plugins/ssh-base/sshd.c;plugins/ssh-base/telnet.c;plugins/ssh-base/kex-25519.c" "plugins/ssh-base/crypto/chacha.c;plugins/ssh-base/crypto/ed25519.c;plugins/ssh-base/crypto/fe25519.c;plugins/ssh-base/crypto/ge25519.c;plugins/ssh-base/crypto/poly1305.c;plugins/ssh-base/crypto/sc25519.c;plugins/ssh-base/crypto/smult_curve25519_ref.c" "")
- create_plugin(protocol_lws_sshd_demo "plugins/ssh-base/include" "plugins/protocol_lws_sshd_demo.c" "" "")
-
- include_directories("${PROJECT_SOURCE_DIR}/plugins/ssh-base/include")
-endif()
-
-
-
-if (LWS_WITH_ACME)
- create_plugin(protocol_lws_acme_client ""
- "plugins/acme-client/protocol_lws_acme_client.c" "" "")
-endif()
-
-if (LWS_WITH_GENERIC_SESSIONS AND LWS_ROLE_WS)
- create_plugin(protocol_generic_sessions ""
- "plugins/generic-sessions/protocol_generic_sessions.c"
- "plugins/generic-sessions/utils.c"
- "plugins/generic-sessions/handlers.c")
-
- if (WIN32)
- target_link_libraries(protocol_generic_sessions ${LWS_SQLITE3_LIBRARIES})
- else()
- target_link_libraries(protocol_generic_sessions sqlite3 )
- endif(WIN32)
-
- create_plugin(protocol_lws_messageboard ""
- "plugins/generic-sessions/protocol_lws_messageboard.c" "" "")
- if (WIN32)
- target_link_libraries(protocol_lws_messageboard ${LWS_SQLITE3_LIBRARIES})
- else()
- target_link_libraries(protocol_lws_messageboard sqlite3 )
- endif(WIN32)
-
-endif(LWS_WITH_GENERIC_SESSIONS AND LWS_ROLE_WS)
-
-
- endif(LWS_WITH_PLUGINS AND LWS_WITH_SHARED)
-
- #
- # Copy OpenSSL dlls to the output directory on Windows.
- # (Otherwise we'll get an error when trying to run)
- #
- if (WIN32 AND LWS_WITH_SSL AND NOT LWS_WITH_WOLFSSL)
- if(OPENSSL_BIN_FOUND)
- message("OpenSSL dlls found:")
- message(" Libeay: ${LIBEAY_BIN}")
- message(" SSLeay: ${SSLEAY_BIN}")
-
- foreach(TARGET_BIN ${TEST_APP_LIST})
- add_custom_command(TARGET ${TARGET_BIN}
- POST_BUILD
- COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
- add_custom_command(TARGET ${TARGET_BIN}
- POST_BUILD
- COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
-
- #
- # Win32: if we are using libuv, also need to copy it in the output dir
- #
- if (WIN32 AND LWS_WITH_LIBUV)
- STRING(REPLACE ".lib" ".dll" LIBUV_BIN ${LIBUV_LIBRARIES})
- add_custom_command(TARGET ${TARGET_BIN}
- POST_BUILD
- COMMAND "${CMAKE_COMMAND}" -E copy "${LIBUV_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
- endif()
- endforeach()
- endif()
- endif()
-endif((LWS_ROLE_H1 OR LWS_ROLE_H2) AND NOT LWS_WITHOUT_TESTAPPS)
-
-if (LWS_WITH_LWSWS)
- list(APPEND LWSWS_SRCS
- "lwsws/main.c"
- )
-
- if (WIN32)
- list(APPEND LWSWS_SRCS
- ${WIN32_HELPERS_PATH}/getopt.c
- ${WIN32_HELPERS_PATH}/getopt_long.c
- ${WIN32_HELPERS_PATH}/gettimeofday.c
- )
-
- list(APPEND LWSWS_HDR
- ${WIN32_HELPERS_PATH}/getopt.h
- ${WIN32_HELPERS_PATH}/gettimeofday.h
- )
- endif(WIN32)
-
- source_group("Headers Private" FILES ${LWSWS_HDR})
- source_group("Sources" FILES ${LWSWS_SRCS})
- add_executable("lwsws" ${LWSWS_SRCS} ${LWSWS_HDR})
-
- target_link_libraries("lwsws" websockets_shared)
- add_dependencies("lwsws" websockets_shared)
-
- # Set test app specific defines.
- set_property(TARGET "lwsws"
- PROPERTY COMPILE_DEFINITIONS
- INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share"
- )
-endif (LWS_WITH_LWSWS)
-
-if (UNIX)
-
-# Generate and install pkgconfig.
-# (This is not indented, because the tabs will be part of the output)
-file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc"
-"prefix=\"${CMAKE_INSTALL_PREFIX}\"
-exec_prefix=\${prefix}
-libdir=\${exec_prefix}/lib${LIB_SUFFIX}
-includedir=\${prefix}/include
-
-Name: libwebsockets
-Description: Websockets server and client library
-Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
-
-Libs: -L\${libdir} -lwebsockets
-Cflags: -I\${includedir}"
-)
-
- install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc"
- DESTINATION lib${LIB_SUFFIX}/pkgconfig)
-
-file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets_static.pc"
-"prefix=\"${CMAKE_INSTALL_PREFIX}\"
-exec_prefix=\${prefix}
-libdir=\${exec_prefix}/lib${LIB_SUFFIX}
-includedir=\${prefix}/include
-
-Name: libwebsockets_static
-Description: Websockets server and client static library
-Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}
-
-Libs: -L\${libdir} -lwebsockets_static
-Libs.private:
-Cflags: -I\${includedir}"
-)
-
- install(FILES "${PROJECT_BINARY_DIR}/libwebsockets_static.pc"
- DESTINATION lib${LIB_SUFFIX}/pkgconfig)
-
-
-endif(UNIX)
-