Hiroaki Sakon | c00675c | 2014-09-22 22:39:59 +0900 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 2 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 3 | if(NOT DEFINED CMAKE_BUILD_TYPE) |
| 4 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type") |
| 5 | endif() |
| 6 | |
Samuel Martin | a11a282 | 2014-05-02 14:24:58 +0200 | [diff] [blame] | 7 | project(libwebsockets C) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 8 | |
| 9 | set(PACKAGE "libwebsockets") |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 10 | set(CPACK_PACKAGE_NAME "${PACKAGE}") |
| 11 | set(CPACK_PACKAGE_VERSION_MAJOR "1") |
Andy Green | ab620ff | 2015-10-28 08:39:09 +0800 | [diff] [blame] | 12 | set(CPACK_PACKAGE_VERSION_MINOR "5") |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 13 | set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}") |
| 14 | set(CPACK_PACKAGE_VENDOR "andy@warmcat.com") |
| 15 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}") |
Roger Light | b863954 | 2015-02-17 10:06:58 +0000 | [diff] [blame] | 16 | set(SOVERSION "5") |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 17 | set(CPACK_SOURCE_GENERATOR "TGZ") |
| 18 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") |
| 19 | set(VERSION "${CPACK_PACKAGE_VERSION}") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 20 | |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 21 | set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION}) |
Edwin van den Oetelaar | d6bf73c | 2013-02-18 20:20:05 +0800 | [diff] [blame] | 22 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 23 | |
Andy Green | 5b479ac | 2013-03-30 10:30:03 +0800 | [diff] [blame] | 24 | message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'") |
| 25 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 26 | # Try to find the current Git hash. |
| 27 | find_package(Git) |
| 28 | if(GIT_EXECUTABLE) |
| 29 | execute_process( |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 30 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 31 | COMMAND "${GIT_EXECUTABLE}" log -n 1 --pretty=%h |
| 32 | OUTPUT_VARIABLE GIT_HASH |
| 33 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 34 | ) |
| 35 | |
| 36 | set(LWS_BUILD_HASH ${GIT_HASH}) |
| 37 | message("Git commit hash: ${LWS_BUILD_HASH}") |
| 38 | endif() |
| 39 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 40 | set(LWS_USE_BUNDLED_ZLIB_DEFAULT OFF) |
| 41 | if(WIN32) |
| 42 | set(LWS_USE_BUNDLED_ZLIB_DEFAULT ON) |
| 43 | endif() |
| 44 | |
| 45 | option(LWS_WITH_STATIC "Build the static version of the library" ON) |
| 46 | option(LWS_WITH_SHARED "Build the shared version of the library" ON) |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 47 | option(LWS_WITH_SSL "Include SSL support (default OpenSSL, wolfSSL if LWS_USE_WOLFSSL is set)" ON) |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 48 | 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) |
| 49 | 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) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 50 | option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" ON) |
| 51 | option(LWS_WITH_LIBEV "Compile with support for libev" OFF) |
| 52 | option(LWS_USE_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_USE_BUNDLED_ZLIB_DEFAULT}) |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 53 | option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of the OS-installed CA root certs" ON) |
| 54 | 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) |
Andy Green | 4c79ee7 | 2015-10-15 11:20:40 +0800 | [diff] [blame] | 55 | option(LWS_WITHOUT_BUILTIN_SHA1 "Don't build the lws sha-1 (eg, because openssl will provide it" OFF) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 56 | option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF) |
| 57 | option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 58 | option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF) |
| 59 | option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF) |
| 60 | option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF) |
| 61 | option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF) |
| 62 | option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF) |
| 63 | option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF) |
| 64 | option(LWS_WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 65 | option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" OFF) |
| 66 | option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 67 | option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON) |
Quinlan Pfiffer | 363420d | 2015-01-26 11:24:03 +0800 | [diff] [blame] | 68 | option(LWS_IPV6 "Compile with support for ipv6" OFF) |
Andy Green | 2eedea9 | 2014-04-03 14:33:48 +0800 | [diff] [blame] | 69 | option(LWS_WITH_HTTP2 "Compile with support for http2" OFF) |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 70 | option(LWS_MBED3 "Platform is MBED3" OFF) |
Andy Green | 6d41720 | 2015-12-04 10:39:23 +0800 | [diff] [blame^] | 71 | option(LWS_WITH_OLD_API_WRAPPERS "Compile with binary compatibility with pre-v1.6 apis" OFF) |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 72 | |
| 73 | if (DEFINED YOTTA_WEBSOCKETS_VERSION_STRING) |
| 74 | |
| 75 | set(LWS_WITH_SHARED OFF) |
| 76 | set(LWS_WITH_SSL OFF) |
| 77 | set(LWS_WITH_ZLIB OFF) |
| 78 | set(LWS_WITHOUT_CLIENT ON) |
| 79 | set(LWS_WITHOUT_TESTAPPS ON) |
| 80 | set(LWS_WITHOUT_EXTENSIONS ON) |
| 81 | set(LWS_MBED3 ON) |
| 82 | |
| 83 | endif() |
| 84 | |
| 85 | if (DEFINED YOTTA_WEBSOCKETS_VERSION_STRING) |
| 86 | |
| 87 | set(LWS_WITH_SHARED OFF) |
| 88 | set(LWS_WITH_SSL OFF) |
| 89 | set(LWS_WITH_ZLIB OFF) |
| 90 | set(LWS_WITHOUT_CLIENT ON) |
| 91 | set(LWS_WITHOUT_TESTAPPS ON) |
| 92 | set(LWS_WITHOUT_EXTENSIONS ON) |
| 93 | set(LWS_MBED3 ON) |
| 94 | |
| 95 | endif() |
| 96 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 97 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 98 | # Allow the user to override installation directories. |
| 99 | set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") |
| 100 | set(LWS_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") |
| 101 | set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") |
| 102 | set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files") |
| 103 | |
ABruines | 80a7068 | 2015-08-09 22:56:32 +0200 | [diff] [blame] | 104 | # Allow the user to use the old CyaSSL options/library in stead of wolfSSL |
| 105 | if (LWS_USE_CYASSL AND LWS_USE_WOLFSSL) |
| 106 | message(FATAL_ERROR "LWS_USE_CYASSL and LWS_USE_WOLFSSL are mutually exclusive!") |
| 107 | endif() |
| 108 | if (LWS_USE_CYASSL) |
| 109 | # Copy CyaSSL options to the wolfSSL options |
| 110 | set(LWS_USE_WOLFSSL ${LWS_USE_CYASSL} CACHE BOOL "Use wolfSSL/CyaSSL instead of OpenSSL" FORCE) |
| 111 | set(LWS_WOLFSSL_LIBRARIES ${LWS_CYASSL_LIBRARIES} CACHE PATH "Path to wolfSSL/CyaSSL libraries" FORCE) |
| 112 | set(LWS_WOLFSSL_INCLUDE_DIRS ${LWS_CYASSL_INCLUDE_DIRS} CACHE PATH "Path to wolfSSL/CyaSSL header files" FORCE) |
| 113 | endif() |
| 114 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 115 | if (LWS_WITHOUT_CLIENT AND LWS_WITHOUT_SERVER) |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 116 | message(FATAL_ERROR "Makes no sense to compile with neither client nor server.") |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 117 | endif() |
| 118 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 119 | if (NOT (LWS_WITH_STATIC OR LWS_WITH_SHARED)) |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 120 | message(FATAL_ERROR "Makes no sense to compile with neither static nor shared libraries.") |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 121 | endif() |
| 122 | |
| 123 | if (NOT LWS_WITHOUT_EXTENSIONS) |
| 124 | if (NOT LWS_WITH_ZLIB) |
| 125 | message(FATAL_ERROR "zlib is required for extensions.") |
| 126 | endif() |
| 127 | endif() |
| 128 | |
| 129 | set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib library") |
| 130 | set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib include directory") |
| 131 | set(LWS_OPENSSL_LIBRARIES CACHE PATH "Path to the OpenSSL library") |
| 132 | set(LWS_OPENSSL_INCLUDE_DIRS CACHE PATH "Path to the OpenSSL include directory") |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 133 | set(LWS_WOLFSSL_LIBRARIES CACHE PATH "Path to the wolfSSL library") |
| 134 | set(LWS_WOLFSSL_INCLUDE_DIRS CACHE PATH "Path to the wolfSSL include directory") |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 135 | set(LWS_LIBEV_LIBRARIES CACHE PATH "Path to the libev library") |
| 136 | set(LWS_LIBEV_INCLUDE_DIRS CACHE PATH "Path to the libev include directory") |
| 137 | |
Andy Green | 9ffb42e | 2015-11-09 04:24:46 +0800 | [diff] [blame] | 138 | if (NOT LWS_WITH_SSL) |
| 139 | set(LWS_WITHOUT_BUILTIN_SHA1 OFF) |
| 140 | endif() |
| 141 | |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 142 | if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 143 | if ("${LWS_OPENSSL_LIBRARIES}" STREQUAL "" OR "${LWS_OPENSSL_INCLUDE_DIRS}" STREQUAL "") |
| 144 | else() |
| 145 | set(OPENSSL_LIBRARIES ${LWS_OPENSSL_LIBRARIES}) |
| 146 | set(OPENSSL_INCLUDE_DIRS ${LWS_OPENSSL_INCLUDE_DIRS}) |
| 147 | set(OPENSSL_FOUND 1) |
| 148 | endif() |
| 149 | endif() |
| 150 | |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 151 | if (LWS_WITH_SSL AND LWS_USE_WOLFSSL) |
| 152 | if ("${LWS_WOLFSSL_LIBRARIES}" STREQUAL "" OR "${LWS_WOLFSSL_INCLUDE_DIRS}" STREQUAL "") |
| 153 | if (NOT WOLFSSL_FOUND) |
ABruines | 80a7068 | 2015-08-09 22:56:32 +0200 | [diff] [blame] | 154 | if (LWS_USE_CYASSL) |
| 155 | message(FATAL_ERROR "You must set LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS when LWS_USE_CYASSL is turned on.") |
| 156 | else() |
| 157 | message(FATAL_ERROR "You must set LWS_WOLFSSL_LIBRARIES and LWS_WOLFSSL_INCLUDE_DIRS when LWS_USE_WOLFSSL is turned on.") |
| 158 | endif() |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 159 | endif() |
| 160 | else() |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 161 | set(WOLFSSL_LIBRARIES ${LWS_WOLFSSL_LIBRARIES}) |
| 162 | set(WOLFSSL_INCLUDE_DIRS ${LWS_WOLFSSL_INCLUDE_DIRS}) |
| 163 | set(WOLFSSL_FOUND 1) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 164 | endif() |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 165 | set(USE_WOLFSSL 1) |
ABruines | 80a7068 | 2015-08-09 22:56:32 +0200 | [diff] [blame] | 166 | if (LWS_USE_CYASSL) |
| 167 | set(USE_OLD_CYASSL 1) |
| 168 | endif() |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 169 | endif() |
| 170 | |
| 171 | if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB) |
| 172 | if ("${LWS_ZLIB_LIBRARIES}" STREQUAL "" OR "${LWS_ZLIB_INCLUDE_DIRS}" STREQUAL "") |
| 173 | else() |
| 174 | set(ZLIB_LIBRARIES ${LWS_ZLIB_LIBRARIES}) |
| 175 | set(ZLIB_INCLUDE_DIRS ${LWS_ZLIB_INCLUDE_DIRS}) |
| 176 | set(ZLIB_FOUND 1) |
| 177 | endif() |
| 178 | endif() |
| 179 | |
| 180 | if (LWS_WITH_LIBEV) |
| 181 | if ("${LWS_LIBEV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEV_INCLUDE_DIRS}" STREQUAL "") |
| 182 | else() |
| 183 | set(LIBEV_LIBRARIES ${LWS_LIBEV_LIBRARIES}) |
| 184 | set(LIBEV_INCLUDE_DIRS ${LWS_LIBEV_INCLUDE_DIRS}) |
| 185 | set(LIBEV_FOUND 1) |
| 186 | endif() |
| 187 | endif() |
| 188 | |
| 189 | # FIXME: This must be runtime-only option. |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 190 | # The base dir where the test-apps look for the SSL certs. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 191 | set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory") |
| 192 | if (WIN32) |
| 193 | set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory") |
Joakim Soderberg | 46e4886 | 2014-04-24 14:47:10 +0200 | [diff] [blame] | 194 | |
| 195 | if (LWS_IPV6) |
| 196 | set(LWS_IPV6 OFF) |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 197 | message(WARNING "IPv6 does not currently work on Windows!") |
Joakim Soderberg | 46e4886 | 2014-04-24 14:47:10 +0200 | [diff] [blame] | 198 | endif() |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 199 | else() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 200 | set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory") |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 201 | endif() |
| 202 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 203 | if (LWS_WITHOUT_EXTENSIONS) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 204 | set(LWS_NO_EXTENSIONS 1) |
| 205 | endif() |
| 206 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 207 | if (LWS_WITH_SSL) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 208 | set(LWS_OPENSSL_SUPPORT 1) |
| 209 | endif() |
| 210 | |
Andy Green | d2ec7ad | 2014-03-15 10:39:29 +0800 | [diff] [blame] | 211 | if (LWS_SSL_CLIENT_USE_OS_CA_CERTS) |
| 212 | set(LWS_SSL_CLIENT_USE_OS_CA_CERTS 1) |
| 213 | endif() |
| 214 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 215 | if (LWS_WITH_LATENCY) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 216 | set(LWS_LATENCY 1) |
| 217 | endif() |
| 218 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 219 | if (LWS_WITHOUT_DAEMONIZE OR WIN32) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 220 | set(LWS_NO_DAEMONIZE 1) |
| 221 | endif() |
| 222 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 223 | if (LWS_WITHOUT_SERVER) |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame] | 224 | set(LWS_NO_SERVER 1) |
| 225 | endif() |
| 226 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 227 | if (LWS_WITHOUT_CLIENT) |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame] | 228 | set(LWS_NO_CLIENT 1) |
| 229 | endif() |
| 230 | |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 231 | if (LWS_WITH_LIBEV) |
| 232 | set(LWS_USE_LIBEV 1) |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 233 | endif() |
| 234 | |
Andy Green | 055f297 | 2014-03-24 16:09:25 +0800 | [diff] [blame] | 235 | if (LWS_IPV6) |
| 236 | set(LWS_USE_IPV6 1) |
James Devine | 3f13ea2 | 2014-03-24 16:09:25 +0800 | [diff] [blame] | 237 | endif() |
| 238 | |
Andy Green | 2eedea9 | 2014-04-03 14:33:48 +0800 | [diff] [blame] | 239 | if (LWS_WITH_HTTP2) |
| 240 | set(LWS_USE_HTTP2 1) |
| 241 | endif() |
| 242 | |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 243 | if (LWS_MBED3) |
| 244 | set(CMAKE_C_FLAGS "-D_DEBUG ${CMAKE_C_FLAGS}") |
| 245 | endif() |
| 246 | |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 247 | if (MINGW) |
| 248 | set(LWS_MINGW_SUPPORT 1) |
Stephan Eberle | b820e2c | 2015-10-23 08:10:55 +0200 | [diff] [blame] | 249 | set(CMAKE_C_FLAGS "-D__USE_MINGW_ANSI_STDIO ${CMAKE_C_FLAGS}") |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 250 | endif() |
| 251 | |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 252 | include_directories("${PROJECT_BINARY_DIR}") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 253 | |
Joakim Soderberg | 4f4a38b | 2013-02-06 15:28:07 +0900 | [diff] [blame] | 254 | include(CheckCSourceCompiles) |
| 255 | |
| 256 | # Check for different inline keyword versions. |
| 257 | foreach(KEYWORD "inline" "__inline__" "__inline") |
| 258 | set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}") |
| 259 | CHECK_C_SOURCE_COMPILES( |
| 260 | " |
| 261 | #include <stdio.h> |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 262 | static KEYWORD void a() {} |
Joakim Soderberg | 4f4a38b | 2013-02-06 15:28:07 +0900 | [diff] [blame] | 263 | int main(int argc, char **argv) { a(); return 0; } |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 264 | " LWS_HAVE_${KEYWORD}) |
Joakim Soderberg | 4f4a38b | 2013-02-06 15:28:07 +0900 | [diff] [blame] | 265 | endforeach() |
| 266 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 267 | if (NOT LWS_HAVE_inline) |
| 268 | if (LWS_HAVE___inline__) |
Joakim Soderberg | 4f4a38b | 2013-02-06 15:28:07 +0900 | [diff] [blame] | 269 | set(inline __inline__) |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 270 | elseif(LWS_HAVE___inline) |
Joakim Soderberg | 4f4a38b | 2013-02-06 15:28:07 +0900 | [diff] [blame] | 271 | set(inline __inline) |
| 272 | endif() |
| 273 | endif() |
| 274 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 275 | # Put the libaries and binaries that get built into directories at the |
| 276 | # top of the build tree rather than in hard-to-find leaf directories. |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 277 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") |
| 278 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") |
| 279 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 280 | |
thinkski | d34bae1 | 2013-04-16 19:48:05 +0800 | [diff] [blame] | 281 | # Put absolute path of dynamic libraries into the object code. Some |
| 282 | # architectures, notably Mac OS X, need this. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 283 | SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}") |
thinkski | d34bae1 | 2013-04-16 19:48:05 +0800 | [diff] [blame] | 284 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 285 | include(CheckFunctionExists) |
| 286 | include(CheckIncludeFile) |
| 287 | include(CheckIncludeFiles) |
| 288 | include(CheckLibraryExists) |
Patrick Gansterer | 8a59033 | 2014-02-28 00:42:08 +0100 | [diff] [blame] | 289 | include(CheckTypeSize) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 290 | |
Andy Green | 4c79ee7 | 2015-10-15 11:20:40 +0800 | [diff] [blame] | 291 | if (LWS_WITHOUT_BUILTIN_SHA1) |
| 292 | set(LWS_SHA1_USE_OPENSSL_NAME 1) |
| 293 | endif() |
| 294 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 295 | CHECK_FUNCTION_EXISTS(bzero LWS_HAVE_BZERO) |
| 296 | CHECK_FUNCTION_EXISTS(fork LWS_HAVE_FORK) |
| 297 | CHECK_FUNCTION_EXISTS(getenv LWS_HAVE_GETENV) |
| 298 | CHECK_FUNCTION_EXISTS(malloc LWS_HAVE_MALLOC) |
| 299 | CHECK_FUNCTION_EXISTS(memset LWS_HAVE_MEMSET) |
| 300 | CHECK_FUNCTION_EXISTS(realloc LWS_HAVE_REALLOC) |
| 301 | CHECK_FUNCTION_EXISTS(socket LWS_HAVE_SOCKET) |
| 302 | CHECK_FUNCTION_EXISTS(strerror LWS_HAVE_STRERROR) |
| 303 | CHECK_FUNCTION_EXISTS(vfork LWS_HAVE_VFORK) |
| 304 | CHECK_FUNCTION_EXISTS(getifaddrs LWS_HAVE_GETIFADDRS) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 305 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 306 | if (NOT LWS_HAVE_GETIFADDRS) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 307 | if (LWS_WITHOUT_BUILTIN_GETIFADDRS) |
| 308 | 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.") |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 309 | endif() |
| 310 | set(LWS_BUILTIN_GETIFADDRS 1) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 311 | endif() |
| 312 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 313 | CHECK_INCLUDE_FILE(dlfcn.h LWS_HAVE_DLFCN_H) |
| 314 | CHECK_INCLUDE_FILE(fcntl.h LWS_HAVE_FCNTL_H) |
| 315 | CHECK_INCLUDE_FILE(in6addr.h LWS_HAVE_IN6ADDR_H) |
| 316 | CHECK_INCLUDE_FILE(inttypes.h LWS_HAVE_INTTYPES_H) |
| 317 | CHECK_INCLUDE_FILE(memory.h LWS_HAVE_MEMORY_H) |
| 318 | CHECK_INCLUDE_FILE(netinet/in.h LWS_HAVE_NETINET_IN_H) |
| 319 | CHECK_INCLUDE_FILE(stdint.h LWS_HAVE_STDINT_H) |
| 320 | CHECK_INCLUDE_FILE(stdlib.h LWS_HAVE_STDLIB_H) |
| 321 | CHECK_INCLUDE_FILE(strings.h LWS_HAVE_STRINGS_H) |
| 322 | CHECK_INCLUDE_FILE(string.h LWS_HAVE_STRING_H) |
| 323 | CHECK_INCLUDE_FILE(sys/prctl.h LWS_HAVE_SYS_PRCTL_H) |
| 324 | CHECK_INCLUDE_FILE(sys/socket.h LWS_HAVE_SYS_SOCKET_H) |
| 325 | CHECK_INCLUDE_FILE(sys/stat.h LWS_HAVE_SYS_STAT_H) |
| 326 | CHECK_INCLUDE_FILE(sys/types.h LWS_HAVE_SYS_TYPES_H) |
| 327 | CHECK_INCLUDE_FILE(unistd.h LWS_HAVE_UNISTD_H) |
| 328 | CHECK_INCLUDE_FILE(vfork.h LWS_HAVE_VFORK_H) |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 329 | |
| 330 | if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB) |
| 331 | CHECK_INCLUDE_FILE(zlib.h LWS_HAVE_ZLIB_H) |
| 332 | endif() |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 333 | |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 334 | # TODO: These can also be tested to see whether they actually work... |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 335 | set(LWS_HAVE_WORKING_FORK LWS_HAVE_FORK) |
| 336 | set(LWS_HAVE_WORKING_VFORK LWS_HAVE_VFORK) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 337 | |
| 338 | CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS) |
| 339 | |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 340 | # These don't work Cross... |
| 341 | #CHECK_TYPE_SIZE(pid_t PID_T_SIZE) |
| 342 | #CHECK_TYPE_SIZE(size_t SIZE_T_SIZE) |
| 343 | #CHECK_TYPE_SIZE("void *" LWS_SIZEOFPTR LANGUAGE C) |
Patrick Gansterer | 8a59033 | 2014-02-28 00:42:08 +0100 | [diff] [blame] | 344 | |
| 345 | if (NOT PID_T_SIZE) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 346 | set(pid_t int) |
Patrick Gansterer | 8a59033 | 2014-02-28 00:42:08 +0100 | [diff] [blame] | 347 | endif() |
| 348 | |
| 349 | if (NOT SIZE_T_SIZE) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 350 | set(size_t "unsigned int") |
| 351 | endif() |
| 352 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 353 | if (NOT LWS_HAVE_MALLOC) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 354 | set(malloc rpl_malloc) |
| 355 | endif() |
| 356 | |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 357 | if (NOT LWS_HAVE_REALLOC) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 358 | set(realloc rpl_realloc) |
| 359 | endif() |
| 360 | |
Roger A. Light | 7a474b4 | 2015-06-26 11:40:54 +0200 | [diff] [blame] | 361 | # Generate the lws_config.h that includes all the public compilation settings. |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 362 | configure_file( |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 363 | "${PROJECT_SOURCE_DIR}/lws_config.h.in" |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 364 | "${PROJECT_BINARY_DIR}/lws_config.h") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 365 | |
Roger A. Light | 7a474b4 | 2015-06-26 11:40:54 +0200 | [diff] [blame] | 366 | # Generate the lws_config.h that includes all the private compilation settings. |
| 367 | configure_file( |
| 368 | "${PROJECT_SOURCE_DIR}/lws_config_private.h.in" |
| 369 | "${PROJECT_BINARY_DIR}/lws_config_private.h") |
| 370 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 371 | if (MSVC) |
| 372 | # Turn off stupid microsoft security warnings. |
| 373 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 374 | endif(MSVC) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 375 | |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 376 | include_directories("${PROJECT_SOURCE_DIR}/lib") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 377 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 378 | # Group headers and sources. |
| 379 | # Some IDEs use this for nicer file structure. |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 380 | set(HDR_PRIVATE |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 381 | lib/private-libwebsockets.h) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 382 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 383 | set(HDR_PUBLIC |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 384 | "${PROJECT_SOURCE_DIR}/lib/libwebsockets.h" |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 385 | "${PROJECT_BINARY_DIR}/lws_config.h") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 386 | |
| 387 | set(SOURCES |
| 388 | lib/base64-decode.c |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 389 | lib/handshake.c |
| 390 | lib/libwebsockets.c |
Andy Green | d474135 | 2014-04-03 07:36:41 +0800 | [diff] [blame] | 391 | lib/service.c |
Andy Green | 34f3dd2 | 2014-04-03 07:42:50 +0800 | [diff] [blame] | 392 | lib/pollfd.c |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 393 | lib/output.c |
| 394 | lib/parsers.c |
Andy Green | 3d67f51 | 2014-04-03 07:29:50 +0800 | [diff] [blame] | 395 | lib/context.c |
Alejandro Mery | cdc9717 | 2014-12-04 23:15:27 +0100 | [diff] [blame] | 396 | lib/alloc.c |
wonder-mice | dd32c24 | 2015-04-23 05:37:46 +0800 | [diff] [blame] | 397 | lib/header.c) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 398 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 399 | if (NOT LWS_WITHOUT_CLIENT) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 400 | list(APPEND SOURCES |
| 401 | lib/client.c |
| 402 | lib/client-handshake.c |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 403 | lib/client-parser.c) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 404 | endif() |
| 405 | |
Andy Green | c57037a | 2014-04-03 10:17:00 +0800 | [diff] [blame] | 406 | if (LWS_WITH_SSL) |
| 407 | list(APPEND SOURCES |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 408 | lib/ssl.c) |
Andy Green | c57037a | 2014-04-03 10:17:00 +0800 | [diff] [blame] | 409 | endif() |
| 410 | |
Andy Green | 4c79ee7 | 2015-10-15 11:20:40 +0800 | [diff] [blame] | 411 | if (NOT LWS_WITHOUT_BUILTIN_SHA1) |
| 412 | list(APPEND SOURCES |
| 413 | lib/sha-1.c) |
| 414 | endif() |
| 415 | |
Andy Green | 2eedea9 | 2014-04-03 14:33:48 +0800 | [diff] [blame] | 416 | if (LWS_WITH_HTTP2) |
| 417 | list(APPEND SOURCES |
Andy Green | 024eb6c | 2014-10-08 12:00:53 +0800 | [diff] [blame] | 418 | lib/http2.c |
Andy Green | 2add634 | 2014-10-12 08:38:16 +0800 | [diff] [blame] | 419 | lib/hpack.c |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 420 | lib/ssl-http2.c) |
Andy Green | 2eedea9 | 2014-04-03 14:33:48 +0800 | [diff] [blame] | 421 | endif() |
Andy Green | e40aa9b | 2014-04-02 21:02:54 +0800 | [diff] [blame] | 422 | # select the active platform files |
| 423 | |
| 424 | if (WIN32) |
| 425 | list(APPEND SOURCES |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 426 | lib/lws-plat-win.c) |
Andy Green | e40aa9b | 2014-04-02 21:02:54 +0800 | [diff] [blame] | 427 | else() |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 428 | if (LWS_MBED3) |
| 429 | list(APPEND SOURCES |
| 430 | lib/lws-plat-mbed3.cpp |
| 431 | lib/lws-plat-mbed3.c) |
| 432 | else() |
| 433 | list(APPEND SOURCES |
| 434 | lib/lws-plat-unix.c) |
| 435 | endif() |
Andy Green | e40aa9b | 2014-04-02 21:02:54 +0800 | [diff] [blame] | 436 | endif() |
| 437 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 438 | if (NOT LWS_WITHOUT_SERVER) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 439 | list(APPEND SOURCES |
| 440 | lib/server.c |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 441 | lib/server-handshake.c) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 442 | endif() |
| 443 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 444 | if (NOT LWS_WITHOUT_EXTENSIONS) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 445 | list(APPEND HDR_PRIVATE |
| 446 | lib/extension-deflate-frame.h |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 447 | lib/extension-deflate-stream.h) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 448 | list(APPEND SOURCES |
| 449 | lib/extension.c |
| 450 | lib/extension-deflate-frame.c |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 451 | lib/extension-deflate-stream.c) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 452 | endif() |
| 453 | |
Andy Green | a717df2 | 2014-04-11 13:14:37 +0800 | [diff] [blame] | 454 | if (LWS_WITH_LIBEV) |
| 455 | list(APPEND SOURCES |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 456 | lib/libev.c) |
Andy Green | a717df2 | 2014-04-11 13:14:37 +0800 | [diff] [blame] | 457 | endif(LWS_WITH_LIBEV) |
| 458 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 459 | # Add helper files for Windows. |
| 460 | if (WIN32) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 461 | set(WIN32_HELPERS_PATH win32port/win32helpers) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 462 | include_directories(${WIN32_HELPERS_PATH}) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 463 | else() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 464 | # Unix. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 465 | if (NOT LWS_WITHOUT_DAEMONIZE) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 466 | list(APPEND SOURCES |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 467 | lib/daemonize.c) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 468 | endif() |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 469 | endif() |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 470 | |
| 471 | if (UNIX) |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 472 | if (NOT LWS_HAVE_GETIFADDRS) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 473 | list(APPEND HDR_PRIVATE lib/getifaddrs.h) |
| 474 | list(APPEND SOURCES lib/getifaddrs.c) |
| 475 | endif() |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 476 | endif() |
Andy Green | da3f6ff | 2013-03-16 12:32:59 +0800 | [diff] [blame] | 477 | |
Andy Green | b39c22f | 2015-11-29 18:52:37 +0800 | [diff] [blame] | 478 | if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) |
Steven Lai | ba3c75c | 2015-01-27 19:46:26 +0800 | [diff] [blame] | 479 | include (CheckCCompilerFlag) |
=?UTF-8?q?Joakim=20S=C3=B6derberg?= | cefab31 | 2015-06-24 16:46:02 +0200 | [diff] [blame] | 480 | CHECK_C_COMPILER_FLAG(-fvisibility=hidden LWS_HAVE_VISIBILITY) |
| 481 | if (LWS_HAVE_VISIBILITY) |
Steven Lai | ba3c75c | 2015-01-27 19:46:26 +0800 | [diff] [blame] | 482 | set(VISIBILITY_FLAG -fvisibility=hidden) |
| 483 | endif() |
pmcdona | 0a0a7eb | 2013-12-18 10:17:25 +0800 | [diff] [blame] | 484 | if (UNIX) |
Andy Green | abc8635 | 2015-11-29 20:17:49 +0800 | [diff] [blame] | 485 | set(CMAKE_C_FLAGS "-Wall -Werror ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" ) |
pmcdona | 0a0a7eb | 2013-12-18 10:17:25 +0800 | [diff] [blame] | 486 | else(UNIX) |
Bruce Perens | e38b850 | 2015-10-15 08:46:29 +0800 | [diff] [blame] | 487 | set(CMAKE_C_FLAGS "-Wall ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" ) |
pmcdona | 0a0a7eb | 2013-12-18 10:17:25 +0800 | [diff] [blame] | 488 | endif(UNIX) |
Joakim Soderberg | c2012e4 | 2013-03-23 08:55:02 +0800 | [diff] [blame] | 489 | endif () |
Andy Green | da3f6ff | 2013-03-16 12:32:59 +0800 | [diff] [blame] | 490 | |
Andy Green | 09b8a71 | 2015-11-29 19:41:13 +0800 | [diff] [blame] | 491 | if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) |
| 492 | if (UNIX) |
| 493 | # jeez clang understands -pthread but dies if he sees it at link time! |
| 494 | # http://stackoverflow.com/questions/2391194/what-is-gs-pthread-equiv-in-clang |
| 495 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread" ) |
| 496 | endif() |
| 497 | endif() |
| 498 | |
Andy Green | 1700265 | 2015-11-29 19:19:09 +0800 | [diff] [blame] | 499 | if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) |
| 500 | # otherwise osx blows a bunch of openssl deprecated api errors |
| 501 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations" ) |
| 502 | endif() |
| 503 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 504 | source_group("Headers Private" FILES ${HDR_PRIVATE}) |
| 505 | source_group("Headers Public" FILES ${HDR_PUBLIC}) |
| 506 | source_group("Sources" FILES ${SOURCES}) |
| 507 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 508 | # |
| 509 | # Create the lib. |
| 510 | # |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 511 | set(LWS_LIBRARIES) |
Roger A. Light | b6147fd | 2015-05-05 15:02:08 -0500 | [diff] [blame] | 512 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 513 | if (LWS_WITH_STATIC) |
| 514 | add_library(websockets STATIC |
| 515 | ${HDR_PRIVATE} |
| 516 | ${HDR_PUBLIC} |
| 517 | ${SOURCES}) |
| 518 | list(APPEND LWS_LIBRARIES websockets) |
Roger A. Light | b6147fd | 2015-05-05 15:02:08 -0500 | [diff] [blame] | 519 | |
| 520 | if (WIN32) |
| 521 | # Windows uses the same .lib ending for static libraries and shared |
| 522 | # library linker files, so rename the static library. |
| 523 | set_target_properties(websockets |
| 524 | PROPERTIES |
| 525 | OUTPUT_NAME websockets_static) |
| 526 | endif() |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 527 | endif() |
Roger A. Light | b6147fd | 2015-05-05 15:02:08 -0500 | [diff] [blame] | 528 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 529 | if (LWS_WITH_SHARED) |
| 530 | add_library(websockets_shared SHARED |
| 531 | ${HDR_PRIVATE} |
| 532 | ${HDR_PUBLIC} |
| 533 | ${SOURCES}) |
| 534 | list(APPEND LWS_LIBRARIES websockets_shared) |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 535 | |
Roger A. Light | b6147fd | 2015-05-05 15:02:08 -0500 | [diff] [blame] | 536 | # We want the shared lib to be named "libwebsockets" |
| 537 | # not "libwebsocket_shared". |
| 538 | set_target_properties(websockets_shared |
| 539 | PROPERTIES |
| 540 | OUTPUT_NAME websockets) |
| 541 | |
| 542 | if (WIN32) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 543 | # Compile as DLL (export function declarations) |
| 544 | set_property( |
| 545 | TARGET websockets_shared |
| 546 | PROPERTY COMPILE_DEFINITIONS |
| 547 | LWS_DLL |
| 548 | LWS_INTERNAL) |
| 549 | endif() |
Roger A. Light | b6147fd | 2015-05-05 15:02:08 -0500 | [diff] [blame] | 550 | |
| 551 | if (APPLE) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 552 | set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES) |
| 553 | endif() |
| 554 | endif() |
Joakim Soderberg | f83585f | 2013-02-13 09:29:09 +0800 | [diff] [blame] | 555 | |
| 556 | # Set the so version of the lib. |
Andy Green | 19c1a99 | 2013-03-10 06:59:01 +0800 | [diff] [blame] | 557 | # Equivalent to LDFLAGS=-version-info x:x:x |
Andy Green | b39c22f | 2015-11-29 18:52:37 +0800 | [diff] [blame] | 558 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 559 | foreach(lib ${LWS_LIBRARIES}) |
| 560 | set_target_properties(${lib} |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 561 | PROPERTIES |
| 562 | SOVERSION ${SOVERSION}) |
| 563 | endforeach() |
Joakim Soderberg | f83585f | 2013-02-13 09:29:09 +0800 | [diff] [blame] | 564 | endif() |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 565 | |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 566 | set(LIB_LIST) |
| 567 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 568 | # |
| 569 | # Find libraries. |
| 570 | # |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 571 | |
| 572 | # |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 573 | # ZLIB (Only needed for deflate extensions). |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 574 | # |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 575 | if (LWS_WITH_ZLIB) |
| 576 | if (LWS_USE_BUNDLED_ZLIB) |
| 577 | if (WIN32) |
| 578 | set(WIN32_ZLIB_PATH "win32port/zlib") |
| 579 | set(ZLIB_SRCS |
| 580 | ${WIN32_ZLIB_PATH}/adler32.c |
| 581 | ${WIN32_ZLIB_PATH}/compress.c |
| 582 | ${WIN32_ZLIB_PATH}/crc32.c |
| 583 | ${WIN32_ZLIB_PATH}/deflate.c |
| 584 | ${WIN32_ZLIB_PATH}/gzclose.c |
| 585 | ${WIN32_ZLIB_PATH}/gzio.c |
| 586 | ${WIN32_ZLIB_PATH}/gzlib.c |
| 587 | ${WIN32_ZLIB_PATH}/gzread.c |
| 588 | ${WIN32_ZLIB_PATH}/gzwrite.c |
| 589 | ${WIN32_ZLIB_PATH}/infback.c |
| 590 | ${WIN32_ZLIB_PATH}/inffast.c |
| 591 | ${WIN32_ZLIB_PATH}/inflate.c |
| 592 | ${WIN32_ZLIB_PATH}/inftrees.c |
| 593 | ${WIN32_ZLIB_PATH}/trees.c |
| 594 | ${WIN32_ZLIB_PATH}/uncompr.c |
| 595 | ${WIN32_ZLIB_PATH}/zutil.c) |
| 596 | add_library(zlib_internal STATIC ${ZLIB_SRCS}) |
| 597 | set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH}) |
| 598 | get_property(ZLIB_LIBRARIES TARGET zlib_internal PROPERTY LOCATION) |
| 599 | set(ZLIB_FOUND 1) |
| 600 | # Make sure zlib_internal is compiled before the libs. |
| 601 | foreach (lib ${LWS_LIBRARIES}) |
| 602 | add_dependencies(${lib} zlib_internal) |
| 603 | endforeach() |
| 604 | else() |
| 605 | message(FATAL_ERROR "Don't have bundled zlib for that platform") |
| 606 | endif() |
| 607 | elseif (NOT ZLIB_FOUND) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 608 | find_package(ZLIB REQUIRED) |
| 609 | endif() |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 610 | message("zlib include dirs: ${ZLIB_INCLUDE_DIRS}") |
| 611 | message("zlib libraries: ${ZLIB_LIBRARIES}") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 612 | include_directories(${ZLIB_INCLUDE_DIRS}) |
| 613 | list(APPEND LIB_LIST ${ZLIB_LIBRARIES}) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 614 | endif() |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 615 | |
| 616 | # |
| 617 | # OpenSSL |
| 618 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 619 | if (LWS_WITH_SSL) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 620 | message("Compiling with SSL support") |
| 621 | |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 622 | if (LWS_USE_WOLFSSL) |
| 623 | # Use wolfSSL as OpenSSL replacement. |
Joakim Söderberg | cb4156d | 2013-02-06 15:30:56 +0900 | [diff] [blame] | 624 | # TODO: Add a find_package command for this also. |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 625 | message("wolfSSL include dir: ${WOLFSSL_INCLUDE_DIRS}") |
| 626 | message("wolfSSL libraries: ${WOLFSSL_LIBRARIES}") |
Joakim Söderberg | cb4156d | 2013-02-06 15:30:56 +0900 | [diff] [blame] | 627 | |
Joakim Soderberg | 7df9908 | 2013-02-07 20:24:19 +0800 | [diff] [blame] | 628 | # Additional to the root directory we need to include |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 629 | # the wolfssl/ subdirectory which contains the OpenSSL |
Peter Pentchev | bb085da | 2015-12-03 15:55:11 +0200 | [diff] [blame] | 630 | # compatibility layer headers. |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 631 | |
ABruines | 80a7068 | 2015-08-09 22:56:32 +0200 | [diff] [blame] | 632 | if (LWS_USE_CYASSL) |
| 633 | foreach(inc ${WOLFSSL_INCLUDE_DIRS}) |
| 634 | include_directories("${inc}" "${inc}/cyassl") |
| 635 | endforeach() |
| 636 | else() |
| 637 | foreach(inc ${WOLFSSL_INCLUDE_DIRS}) |
| 638 | include_directories("${inc}" "${inc}/wolfssl") |
| 639 | endforeach() |
| 640 | endif() |
Joakim Soderberg | 7df9908 | 2013-02-07 20:24:19 +0800 | [diff] [blame] | 641 | |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 642 | list(APPEND LIB_LIST "${WOLFSSL_LIBRARIES}") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 643 | else() |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 644 | if (NOT OPENSSL_FOUND) |
| 645 | # TODO: Add support for STATIC also. |
| 646 | find_package(OpenSSL REQUIRED) |
| 647 | set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}") |
| 648 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 649 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 650 | message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}") |
Joakim Söderberg | cb4156d | 2013-02-06 15:30:56 +0900 | [diff] [blame] | 651 | message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 652 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 653 | include_directories("${OPENSSL_INCLUDE_DIRS}") |
Joakim Soderberg | d2f5b19 | 2014-04-07 11:28:08 +0200 | [diff] [blame] | 654 | list(APPEND LIB_LIST ${OPENSSL_LIBRARIES}) |
Joakim Söderberg | cb4156d | 2013-02-06 15:30:56 +0900 | [diff] [blame] | 655 | endif() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 656 | endif(LWS_WITH_SSL) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 657 | |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 658 | if (LWS_WITH_LIBEV) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 659 | if (NOT LIBEV_FOUND) |
| 660 | find_path(LIBEV_INCLUDE_DIRS NAMES ev.h) |
| 661 | find_library(LIBEV_LIBRARIES NAMES ev) |
| 662 | if(LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES) |
| 663 | set(LIBEV_FOUND 1) |
| 664 | endif() |
| 665 | endif() |
| 666 | message("libev include dir: ${LIBEV_INCLUDE_DIRS}") |
| 667 | message("libev libraries: ${LIBEV_LIBRARIES}") |
| 668 | include_directories("${LIBEV_INCLUDE_DIRS}") |
| 669 | list(APPEND LIB_LIST ${LIBEV_LIBRARIES}) |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 670 | endif(LWS_WITH_LIBEV) |
| 671 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 672 | # |
| 673 | # Platform specific libs. |
| 674 | # |
Patrick Gansterer | 5b71aac | 2014-02-28 01:31:39 +0100 | [diff] [blame] | 675 | if (WINCE) |
| 676 | list(APPEND LIB_LIST ws2.lib) |
| 677 | elseif (WIN32) |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 678 | list(APPEND LIB_LIST ws2_32.lib) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 679 | endif() |
| 680 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 681 | if (UNIX) |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 682 | list(APPEND LIB_LIST m) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 683 | endif() |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 684 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 685 | # Setup the linking for all libs. |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 686 | foreach (lib ${LWS_LIBRARIES}) |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 687 | target_link_libraries(${lib} ${LIB_LIST}) |
| 688 | endforeach() |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 689 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 690 | # |
| 691 | # Test applications |
| 692 | # |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 693 | set(TEST_APP_LIST) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 694 | if (NOT LWS_WITHOUT_TESTAPPS) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 695 | # |
| 696 | # Helper function for adding a test app. |
| 697 | # |
Andy Green | eb15ea0 | 2015-11-19 13:55:47 +0800 | [diff] [blame] | 698 | macro(create_test_app TEST_NAME MAIN_SRC S2 S3 S4) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 699 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 700 | set(TEST_SRCS ${MAIN_SRC}) |
| 701 | set(TEST_HDR) |
Andy Green | eb15ea0 | 2015-11-19 13:55:47 +0800 | [diff] [blame] | 702 | if ("${S2}" STREQUAL "") |
| 703 | else() |
| 704 | list(APPEND TEST_SRCS ${S2}) |
| 705 | endif() |
| 706 | if ("${S3}" STREQUAL "") |
| 707 | else() |
| 708 | list(APPEND TEST_SRCS ${S3}) |
| 709 | endif() |
| 710 | if ("${S4}" STREQUAL "") |
| 711 | else() |
| 712 | list(APPEND TEST_SRCS ${S4}) |
| 713 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 714 | if (WIN32) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 715 | list(APPEND TEST_SRCS |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 716 | ${WIN32_HELPERS_PATH}/getopt.c |
| 717 | ${WIN32_HELPERS_PATH}/getopt_long.c |
| 718 | ${WIN32_HELPERS_PATH}/gettimeofday.c |
Patrick Gansterer | 73882e4 | 2014-03-29 08:25:58 +0100 | [diff] [blame] | 719 | ) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 720 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 721 | list(APPEND TEST_HDR |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 722 | ${WIN32_HELPERS_PATH}/getopt.h |
| 723 | ${WIN32_HELPERS_PATH}/gettimeofday.h |
Patrick Gansterer | 73882e4 | 2014-03-29 08:25:58 +0100 | [diff] [blame] | 724 | ) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 725 | endif(WIN32) |
| 726 | |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 727 | source_group("Headers Private" FILES ${TEST_HDR}) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 728 | source_group("Sources" FILES ${TEST_SRCS}) |
| 729 | add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR}) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 730 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 731 | if (LWS_LINK_TESTAPPS_DYNAMIC) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 732 | if (NOT LWS_WITH_SHARED) |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 733 | message(FATAL_ERROR "Build of the shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.") |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 734 | endif() |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 735 | target_link_libraries(${TEST_NAME} websockets_shared) |
| 736 | add_dependencies(${TEST_NAME} websockets_shared) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 737 | else() |
| 738 | if (NOT LWS_WITH_STATIC) |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 739 | message(FATAL_ERROR "Build of the static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.") |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 740 | endif() |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 741 | target_link_libraries(${TEST_NAME} websockets) |
| 742 | add_dependencies(${TEST_NAME} websockets) |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 743 | endif() |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 744 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 745 | # Set test app specific defines. |
| 746 | set_property(TARGET ${TEST_NAME} |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 747 | PROPERTY COMPILE_DEFINITIONS |
Andy Green | 63b3b95 | 2013-03-09 12:51:43 +0800 | [diff] [blame] | 748 | INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 749 | ) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 750 | |
| 751 | # Prefix the binary names with libwebsockets. |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 752 | set_target_properties(${TEST_NAME} |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 753 | PROPERTIES |
| 754 | OUTPUT_NAME libwebsockets-${TEST_NAME}) |
| 755 | |
| 756 | # Add to the list of tests. |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 757 | list(APPEND TEST_APP_LIST ${TEST_NAME}) |
Joakim Soderberg | 11a8cda | 2013-02-22 09:28:06 +0800 | [diff] [blame] | 758 | endmacro() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 759 | |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 760 | if (LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 761 | message("Searching for OpenSSL executable and dlls") |
| 762 | find_package(OpenSSLbins) |
| 763 | message("OpenSSL executable: ${OPENSSL_EXECUTABLE}") |
| 764 | endif() |
| 765 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 766 | if (NOT LWS_WITHOUT_SERVER) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 767 | # |
| 768 | # test-server |
| 769 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 770 | if (NOT LWS_WITHOUT_TEST_SERVER) |
Andy Green | eb15ea0 | 2015-11-19 13:55:47 +0800 | [diff] [blame] | 771 | create_test_app(test-server "test-server/test-server.c" "test-server/test-server-http.c" "test-server/test-server-dumb-increment.c" "test-server/test-server-mirror.c") |
Andy Green | 09b8a71 | 2015-11-29 19:41:13 +0800 | [diff] [blame] | 772 | if (UNIX AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))) |
Andy Green | b7fed35 | 2015-11-20 09:33:02 +0800 | [diff] [blame] | 773 | create_test_app(test-server-pthreads "test-server/test-server-pthreads.c" "test-server/test-server-http.c" "test-server/test-server-dumb-increment.c" "test-server/test-server-mirror.c") |
| 774 | endif() |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 775 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 776 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 777 | # |
| 778 | # test-server-extpoll |
| 779 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 780 | if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL) |
Andy Green | eb15ea0 | 2015-11-19 13:55:47 +0800 | [diff] [blame] | 781 | create_test_app(test-server-extpoll "test-server/test-server.c" "test-server/test-server-http.c" "test-server/test-server-dumb-increment.c" "test-server/test-server-mirror.c") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 782 | # Set defines for this executable only. |
| 783 | set_property( |
| 784 | TARGET test-server-extpoll |
| 785 | PROPERTY COMPILE_DEFINITIONS |
| 786 | EXTERNAL_POLL |
Andy Green | 63b3b95 | 2013-03-09 12:51:43 +0800 | [diff] [blame] | 787 | INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 788 | ) |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 789 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 790 | # We need to link against winsock code. |
| 791 | if (WIN32) |
| 792 | target_link_libraries(test-server-extpoll ws2_32.lib) |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 793 | endif(WIN32) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 794 | endif() |
| 795 | |
| 796 | # Data files for running the test server. |
| 797 | set(TEST_SERVER_DATA |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 798 | "${PROJECT_SOURCE_DIR}/test-server/favicon.ico" |
| 799 | "${PROJECT_SOURCE_DIR}/test-server/leaf.jpg" |
| 800 | "${PROJECT_SOURCE_DIR}/test-server/libwebsockets.org-logo.png" |
| 801 | "${PROJECT_SOURCE_DIR}/test-server/test.html") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 802 | |
| 803 | # Generate self-signed SSL certs for the test-server. |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 804 | if (LWS_WITH_SSL AND OPENSSL_EXECUTABLE AND NOT LWS_WITHOUT_TEST_SERVER) |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 805 | message("Generating SSL Certificates for the test-server...") |
| 806 | |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 807 | set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem") |
| 808 | set(TEST_SERVER_SSL_CERT "${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 809 | |
| 810 | if (WIN32) |
Stephan Eberle | b820e2c | 2015-10-23 08:10:55 +0200 | [diff] [blame] | 811 | if (MINGW) |
| 812 | 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}\"") |
| 813 | execute_process( |
| 814 | 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}" |
| 815 | RESULT_VARIABLE OPENSSL_RETURN_CODE) |
| 816 | else() |
| 817 | file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt" |
| 818 | "GB\n" |
| 819 | "Erewhon\n" |
| 820 | "All around\n" |
| 821 | "libwebsockets-test\n" |
| 822 | "localhost\n" |
| 823 | "none@invalid.org\n\n" |
| 824 | ) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 825 | |
Stephan Eberle | b820e2c | 2015-10-23 08:10:55 +0200 | [diff] [blame] | 826 | # The "type" command is a bit picky with paths. |
| 827 | file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH) |
| 828 | message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}") |
| 829 | message("cmd = \"${OPENSSL_EXECUTABLE}\" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout \"${TEST_SERVER_SSL_KEY}\" -out \"${TEST_SERVER_SSL_CERT}\"") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 830 | |
Stephan Eberle | b820e2c | 2015-10-23 08:10:55 +0200 | [diff] [blame] | 831 | execute_process( |
| 832 | COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}" |
| 833 | COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" |
| 834 | RESULT_VARIABLE OPENSSL_RETURN_CODE |
| 835 | OUTPUT_QUIET ERROR_QUIET) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 836 | |
Stephan Eberle | b820e2c | 2015-10-23 08:10:55 +0200 | [diff] [blame] | 837 | message("\n") |
| 838 | endif() |
Joakim Soderberg | c7ed2be | 2013-02-22 09:28:17 +0800 | [diff] [blame] | 839 | |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 840 | if (OPENSSL_RETURN_CODE) |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 841 | message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}") |
| 842 | else() |
| 843 | message("SUCCSESFULLY generated SSL certificate") |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 844 | endif() |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 845 | else() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 846 | # Unix. |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 847 | execute_process( |
| 848 | COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n" |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 849 | COMMAND "${OPENSSL_EXECUTABLE}" |
| 850 | req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" |
wonder-mice | 67e246f | 2015-04-22 13:17:53 -0700 | [diff] [blame] | 851 | RESULT_VARIABLE OPENSSL_RETURN_CODE |
| 852 | OUTPUT_QUIET ERROR_QUIET) |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 853 | |
| 854 | if (OPENSSL_RETURN_CODE) |
| 855 | message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}") |
| 856 | else() |
Peter Pentchev | e46f412 | 2015-10-01 12:25:05 +0300 | [diff] [blame] | 857 | message("SUCCESSFULLY generated SSL certificate") |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 858 | endif() |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 859 | endif() |
| 860 | |
| 861 | list(APPEND TEST_SERVER_DATA |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 862 | "${TEST_SERVER_SSL_KEY}" |
| 863 | "${TEST_SERVER_SSL_CERT}") |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 864 | endif() |
Joakim Soderberg | c7ed2be | 2013-02-22 09:28:17 +0800 | [diff] [blame] | 865 | |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 866 | add_custom_command(TARGET test-server |
| 867 | POST_BUILD |
Joakim Soderberg | 1632c9a | 2014-11-26 01:22:50 +0800 | [diff] [blame] | 868 | COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server") |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 869 | |
Joakim Soderberg | c7ed2be | 2013-02-22 09:28:17 +0800 | [diff] [blame] | 870 | # Copy the file needed to run the server so that the test apps can |
| 871 | # reach them from their default output location |
| 872 | foreach (TEST_FILE ${TEST_SERVER_DATA}) |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 873 | if (EXISTS ${TEST_FILE}) |
| 874 | add_custom_command(TARGET test-server |
| 875 | POST_BUILD |
Joakim Soderberg | 1632c9a | 2014-11-26 01:22:50 +0800 | [diff] [blame] | 876 | COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM) |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 877 | endif() |
Joakim Soderberg | c7ed2be | 2013-02-22 09:28:17 +0800 | [diff] [blame] | 878 | endforeach() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 879 | endif(NOT LWS_WITHOUT_SERVER) |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 880 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 881 | if (NOT LWS_WITHOUT_CLIENT) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 882 | # |
| 883 | # test-client |
| 884 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 885 | if (NOT LWS_WITHOUT_TEST_CLIENT) |
Andy Green | eb15ea0 | 2015-11-19 13:55:47 +0800 | [diff] [blame] | 886 | create_test_app(test-client "test-server/test-client.c" "" "" "") |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 887 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 888 | |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 889 | # |
| 890 | # test-fraggle |
| 891 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 892 | if (NOT LWS_WITHOUT_TEST_FRAGGLE) |
Andy Green | eb15ea0 | 2015-11-19 13:55:47 +0800 | [diff] [blame] | 893 | create_test_app(test-fraggle "test-server/test-fraggle.c" "" "" "") |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 894 | endif() |
| 895 | |
| 896 | # |
| 897 | # test-ping |
| 898 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 899 | if (NOT LWS_WITHOUT_TEST_PING) |
Andy Green | eb15ea0 | 2015-11-19 13:55:47 +0800 | [diff] [blame] | 900 | create_test_app(test-ping "test-server/test-ping.c" "" "" "") |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 901 | endif() |
Andy Green | 27696f2 | 2013-03-10 08:09:25 +0800 | [diff] [blame] | 902 | # |
| 903 | # test-echo |
| 904 | # |
| 905 | if (NOT WITHOUT_TEST_ECHO) |
Andy Green | eb15ea0 | 2015-11-19 13:55:47 +0800 | [diff] [blame] | 906 | create_test_app(test-echo "test-server/test-echo.c" "" "" "") |
Andy Green | 27696f2 | 2013-03-10 08:09:25 +0800 | [diff] [blame] | 907 | endif() |
| 908 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 909 | endif(NOT LWS_WITHOUT_CLIENT) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 910 | |
| 911 | # |
| 912 | # Copy OpenSSL dlls to the output directory on Windows. |
| 913 | # (Otherwise we'll get an error when trying to run) |
| 914 | # |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 915 | if (WIN32 AND LWS_WITH_SSL AND NOT LWS_USE_WOLFSSL) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 916 | if(OPENSSL_BIN_FOUND) |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 917 | message("OpenSSL dlls found:") |
| 918 | message(" Libeay: ${LIBEAY_BIN}") |
| 919 | message(" SSLeay: ${SSLEAY_BIN}") |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 920 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 921 | foreach(TARGET_BIN ${TEST_APP_LIST}) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 922 | add_custom_command(TARGET ${TARGET_BIN} |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 923 | POST_BUILD |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 924 | COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 925 | add_custom_command(TARGET ${TARGET_BIN} |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 926 | POST_BUILD |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 927 | COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 928 | endforeach() |
| 929 | endif() |
| 930 | endif() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 931 | endif(NOT LWS_WITHOUT_TESTAPPS) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 932 | |
| 933 | if (UNIX) |
| 934 | # Generate documentation. |
| 935 | # TODO: Fix this on Windows. |
| 936 | message("Generating API documentation") |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 937 | file(GLOB C_FILES "${PROJECT_SOURCE_DIR}/lib/*.c") |
| 938 | execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${PROJECT_BINARY_DIR}/doc/") |
Joakim Söderberg | 455e451 | 2013-02-19 10:14:54 +0800 | [diff] [blame] | 939 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 940 | execute_process( |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 941 | COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -html ${C_FILES} ${HDR_PUBLIC} |
| 942 | OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.html" |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 943 | ERROR_QUIET) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 944 | |
| 945 | execute_process( |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 946 | COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -text ${C_FILES} ${HDR_PUBLIC} |
| 947 | OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.txt" |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 948 | ERROR_QUIET) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 949 | |
| 950 | # Generate and install pkgconfig. |
| 951 | # (This is not indented, because the tabs will be part of the output) |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 952 | file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc" |
Andy Green | 0f3e413 | 2014-02-27 07:28:45 +0800 | [diff] [blame] | 953 | "prefix=\"${CMAKE_INSTALL_PREFIX}\" |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 954 | exec_prefix=\${prefix} |
Andy Green | 975423c | 2013-02-26 11:58:45 +0800 | [diff] [blame] | 955 | libdir=\${exec_prefix}/lib${LIB_SUFFIX} |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 956 | includedir=\${prefix}/include |
| 957 | |
| 958 | Name: libwebsockets |
| 959 | Description: Websockets server and client library |
Andy Green | e919af8 | 2014-02-15 14:45:14 +0800 | [diff] [blame] | 960 | Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR} |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 961 | |
| 962 | Libs: -L\${libdir} -lwebsockets |
| 963 | Cflags: -I\${includedir}" |
| 964 | ) |
| 965 | |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 966 | install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc" |
Andy Green | c8c1662 | 2013-03-10 08:10:19 +0800 | [diff] [blame] | 967 | DESTINATION lib${LIB_SUFFIX}/pkgconfig) |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 968 | endif(UNIX) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 969 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 970 | # |
| 971 | # Installation preparations. |
| 972 | # |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 973 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 974 | if(WIN32 AND NOT CYGWIN) |
| 975 | set(DEF_INSTALL_CMAKE_DIR cmake) |
| 976 | else() |
| 977 | set(DEF_INSTALL_CMAKE_DIR lib/cmake/libwebsockets) |
| 978 | endif() |
| 979 | |
| 980 | set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") |
| 981 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 982 | # Export targets (This is used for other CMake projects to easily find the libraries and include files). |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 983 | export(TARGETS ${LWS_LIBRARIES} |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 984 | FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake") |
| 985 | export(PACKAGE libwebsockets) |
| 986 | |
| 987 | # Generate the config file for the build-tree. |
| 988 | set(LWS__INCLUDE_DIRS |
| 989 | "${PROJECT_SOURCE_DIR}/lib" |
| 990 | "${PROJECT_BINARY_DIR}") |
| 991 | set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories") |
| 992 | configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in |
| 993 | ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake |
| 994 | @ONLY) |
| 995 | |
| 996 | # Generate the config file for the installation tree. |
Patrick Gansterer | e04ec35 | 2014-02-28 16:29:28 +0100 | [diff] [blame] | 997 | get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE) |
| 998 | get_filename_component(LWS_ABSOLUTE_INSTALL_INCLUDE_DIR ${LWS_INSTALL_INCLUDE_DIR} ABSOLUTE) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 999 | file(RELATIVE_PATH |
| 1000 | REL_INCLUDE_DIR |
Patrick Gansterer | e04ec35 | 2014-02-28 16:29:28 +0100 | [diff] [blame] | 1001 | "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}" |
| 1002 | "${LWS_ABSOLUTE_INSTALL_INCLUDE_DIR}") # Calculate the relative directory from the cmake dir. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1003 | |
| 1004 | # Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in, |
| 1005 | # we escape it here so it's evaluated when it is included instead |
| 1006 | # so that the include dirs are given relative to where the |
| 1007 | # config file is located. |
| 1008 | set(LWS__INCLUDE_DIRS |
| 1009 | "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}") |
| 1010 | configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in |
| 1011 | ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake |
| 1012 | @ONLY) |
| 1013 | |
| 1014 | # Generate version info for both build-tree and install-tree. |
| 1015 | configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in |
| 1016 | ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake |
| 1017 | @ONLY) |
| 1018 | |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 1019 | set_target_properties(${LWS_LIBRARIES} |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1020 | PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}") |
| 1021 | |
| 1022 | # |
| 1023 | # Installation. |
| 1024 | # |
| 1025 | |
| 1026 | # Install libs and headers. |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 1027 | install(TARGETS ${LWS_LIBRARIES} |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1028 | EXPORT LibwebsocketsTargets |
| 1029 | LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries |
| 1030 | ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries |
| 1031 | RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT libraries # Windows DLLs |
| 1032 | PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 1033 | set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries") |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1034 | set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 1035 | |
| 1036 | # Install test apps. |
Andy Green | 7f54e76 | 2014-02-21 18:48:05 +0800 | [diff] [blame] | 1037 | if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_CLIENT) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 1038 | install(TARGETS test-client ${TEST_APP_LIST} |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1039 | RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR} |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 1040 | COMPONENT examples) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1041 | set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 1042 | endif() |
| 1043 | |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 1044 | # Programs shared files used by the test-server. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1045 | if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_SERVER) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 1046 | install(FILES ${TEST_SERVER_DATA} |
| 1047 | DESTINATION share/libwebsockets-test-server |
| 1048 | COMPONENT examples) |
| 1049 | endif() |
| 1050 | |
Andy Green | 2aab3f9 | 2013-03-10 08:11:48 +0800 | [diff] [blame] | 1051 | # build subdir is not part of sources |
| 1052 | set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) ".git" "build" "tgz" "tar.gz") |
| 1053 | |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 1054 | # Most people are more used to "make dist" compared to "make package_source" |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 1055 | add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 1056 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1057 | include(UseRPMTools) |
| 1058 | if (RPMTools_FOUND) |
Tomas Cejka | efda177 | 2013-04-11 08:13:13 +0800 | [diff] [blame] | 1059 | RPMTools_ADD_RPM_TARGETS(libwebsockets libwebsockets.spec) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1060 | endif() |
| 1061 | |
| 1062 | message("---------------------------------------------------------------------") |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 1063 | message(" Settings: (For more help do cmake -LH <srcpath>)") |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1064 | message("---------------------------------------------------------------------") |
Stephan Eberle | b820e2c | 2015-10-23 08:10:55 +0200 | [diff] [blame] | 1065 | message(" LWS_WITH_STATIC = ${LWS_WITH_STATIC}") |
| 1066 | message(" LWS_WITH_SHARED = ${LWS_WITH_SHARED}") |
| 1067 | message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)") |
Andy Green | d2ec7ad | 2014-03-15 10:39:29 +0800 | [diff] [blame] | 1068 | message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}") |
ABruines | 80a7068 | 2015-08-09 22:56:32 +0200 | [diff] [blame] | 1069 | message(" LWS_USE_WOLFSSL = ${LWS_USE_WOLFSSL} (wolfSSL/CyaSSL replacement for OpenSSL)") |
Alexander Bruines | c3bcb89 | 2015-08-08 18:54:49 +0200 | [diff] [blame] | 1070 | if (LWS_USE_WOLFSSL) |
| 1071 | message(" LWS_WOLFSSL_LIBRARIES = ${LWS_WOLFSSL_LIBRARIES}") |
| 1072 | message(" LWS_WOLFSSL_INCLUDE_DIRS = ${LWS_WOLFSSL_INCLUDE_DIRS}") |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1073 | endif() |
Andy Green | 4c79ee7 | 2015-10-15 11:20:40 +0800 | [diff] [blame] | 1074 | message(" LWS_WITHOUT_BUILTIN_SHA1 = ${LWS_WITHOUT_BUILTIN_SHA1}") |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1075 | message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}") |
| 1076 | message(" LWS_WITHOUT_CLIENT = ${LWS_WITHOUT_CLIENT}") |
| 1077 | message(" LWS_WITHOUT_SERVER = ${LWS_WITHOUT_SERVER}") |
| 1078 | message(" LWS_LINK_TESTAPPS_DYNAMIC = ${LWS_LINK_TESTAPPS_DYNAMIC}") |
| 1079 | message(" LWS_WITHOUT_TESTAPPS = ${LWS_WITHOUT_TESTAPPS}") |
| 1080 | message(" LWS_WITHOUT_TEST_SERVER = ${LWS_WITHOUT_TEST_SERVER}") |
| 1081 | message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}") |
| 1082 | message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}") |
| 1083 | message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}") |
| 1084 | message(" LWS_WITHOUT_TEST_FRAGGLE = ${LWS_WITHOUT_TEST_FRAGGLE}") |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1085 | message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}") |
| 1086 | message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}") |
| 1087 | message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}") |
Andrew Canaday | 9769f4f | 2014-03-23 13:25:07 +0800 | [diff] [blame] | 1088 | message(" LWS_USE_LIBEV = ${LWS_USE_LIBEV}") |
Andy Green | 2eedea9 | 2014-04-03 14:33:48 +0800 | [diff] [blame] | 1089 | message(" LWS_IPV6 = ${LWS_IPV6}") |
| 1090 | message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}") |
Andy Green | 5f2a815 | 2015-11-02 08:21:08 +0800 | [diff] [blame] | 1091 | message(" LWS_MBED3 = ${LWS_MBED3}") |
Andy Green | 6d41720 | 2015-12-04 10:39:23 +0800 | [diff] [blame^] | 1092 | message(" LWS_WITH_OLD_API_WRAPPERS = ${LWS_WITH_OLD_API_WRAPPERS}") |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 1093 | message("---------------------------------------------------------------------") |
| 1094 | |
| 1095 | # These will be available to parent projects including libwebsockets using add_subdirectory() |
wonder-mice | f1b1254 | 2015-04-22 10:52:13 -0700 | [diff] [blame] | 1096 | set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries") |
| 1097 | if (LWS_WITH_STATIC) |
| 1098 | set(LIBWEBSOCKETS_LIBRARIES_STATIC websocket CACHE STRING "Libwebsocket static library") |
| 1099 | endif() |
| 1100 | if (LWS_WITH_SHARED) |
| 1101 | set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library") |
| 1102 | endif() |
Tomas Cejka | efda177 | 2013-04-11 08:13:13 +0800 | [diff] [blame] | 1103 | |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 1104 | # This must always be last! |
| 1105 | include(CPack) |