Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.6) |
| 2 | |
| 3 | project(libwebsockets) |
| 4 | |
| 5 | set(PACKAGE "libwebsockets") |
| 6 | set(PACKAGE_VERSION "1.1") |
| 7 | set(PACKAGE_BUGREPORT "andy@warmcat.com") |
| 8 | set(PACKAGE_NAME "${PACKAGE}") |
| 9 | set(PACKAGE_STRING "${PACKAGE} ${PACKAGE_VERSION}") |
| 10 | set(PACKAGE_TARNAME "${PACKAGE}") |
| 11 | set(PACKAGE_URL "http://libwebsockets.org") |
| 12 | set(VERSION "{PACKAGE_VERSION}") |
| 13 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 14 | set(LWS_LIBRARY_VERSION ${PACKAGE_VERSION}) |
| 15 | |
| 16 | # Try to find the current Git hash. |
| 17 | find_package(Git) |
| 18 | if(GIT_EXECUTABLE) |
| 19 | execute_process( |
| 20 | COMMAND "${GIT_EXECUTABLE}" log -n 1 --pretty=%h |
| 21 | OUTPUT_VARIABLE GIT_HASH |
| 22 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 23 | ) |
| 24 | |
| 25 | set(LWS_BUILD_HASH ${GIT_HASH}) |
| 26 | message("Git commit hash: ${LWS_BUILD_HASH}") |
| 27 | endif() |
| 28 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 29 | option(WITH_SSL "Include SSL support (default OpenSSL, CyaSSL if USE_CYASSL is set)" ON) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 30 | option(USE_EXTERNAL_ZLIB "Search the system for ZLib instead of using the included one (on Windows)" OFF) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 31 | option(USE_CYASSL "Use CyaSSL replacement for OpenSSL" OFF) |
| 32 | option(WITH_BUILTIN_GETIFADDRS "Use BSD getifaddrs implementation from libwebsockets... default is your libc provides it" OFF) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 33 | option(WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF) |
| 34 | option(WITHOUT_CLIENT "Don't build the client part of the library" OFF) |
| 35 | option(WITHOUT_SERVER "Don't build the server part of the library" OFF) |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 36 | option(WITHOUT_SERVER_EXTPOLL "Don't build a server version that uses external poll" OFF) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 37 | option(WITH_LIBCRYPTO "Use libcrypto MD5 and SHA1 implementations" ON) |
| 38 | option(WITHOUT_PING "Don't build the ping test application" OFF) |
| 39 | option(WITHOUT_DEBUG "Don't compile debug related code" OFF) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 40 | option(WITHOUT_EXTENSIONS "Don't compile with extensions" OFF) |
| 41 | option(WITH_LATENCY "Build latency measuring code into the library" OFF) |
| 42 | option(WITHOUT_DAEMONIZE "Don't build the daemonization api" OFF) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 43 | |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 44 | # The base dir where the SSL dirs should be looked for. |
| 45 | set(SSL_CERT_DIR CACHE STRING "") |
| 46 | set(SSL_CLIENT_CERT_DIR CACHE STRING "") |
| 47 | |
| 48 | if ("${SSL_CERT_DIR}" STREQUAL "") |
| 49 | set(SSL_CERT_DIR ".") |
| 50 | endif() |
| 51 | |
| 52 | if ("${SSL_CLIENT_CERT_DIR}" STREQUAL "") |
| 53 | set(LWS_OPENSSL_CLIENT_CERTS ".") |
| 54 | else() |
| 55 | set(LWS_OPENSSL_CLIENT_CERTS "${SSL_CLIENT_CERT_DIR}") |
| 56 | endif() |
| 57 | |
| 58 | set(CYASSL_LIB CACHE STRING "") |
| 59 | set(CYASSL_INCLUDE_DIRS CACHE STRING "") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 60 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 61 | if (USE_CYASSL) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 62 | if ("${CYASSL_LIB}" STREQUAL "" OR "${CYASSL_INCLUDE_DIRS}" STREQUAL "") |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame^] | 63 | message(FATAL_ERROR "You must set CYASSL_LIB and CYASSL_INCLUDE_DIRS when USE_CYASSL is turned on") |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 64 | endif() |
| 65 | endif() |
| 66 | |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 67 | if (WITHOUT_EXTENSIONS) |
| 68 | set(LWS_NO_EXTENSIONS 1) |
| 69 | endif() |
| 70 | |
| 71 | if (WITH_SSL) |
| 72 | set(LWS_OPENSSL_SUPPORT 1) |
| 73 | endif() |
| 74 | |
| 75 | if (WITH_LATENCY) |
| 76 | set(LWS_LATENCY 1) |
| 77 | endif() |
| 78 | |
| 79 | if (WITHOUT_DAEMONIZE) |
| 80 | set(LWS_NO_DAEMONIZE 1) |
| 81 | endif() |
| 82 | |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame^] | 83 | if (WITHOUT_SERVER) |
| 84 | set(LWS_NO_SERVER 1) |
| 85 | endif() |
| 86 | |
| 87 | if (WITHOUT_CLIENT) |
| 88 | set(LWS_NO_CLIENT 1) |
| 89 | endif() |
| 90 | |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 91 | if (MINGW) |
| 92 | set(LWS_MINGW_SUPPORT 1) |
| 93 | endif() |
| 94 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 95 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") |
| 96 | include_directories(${PROJECT_BINARY_DIR}) |
| 97 | |
Joakim Soderberg | 4f4a38b | 2013-02-06 15:28:07 +0900 | [diff] [blame] | 98 | include(CheckCSourceCompiles) |
| 99 | |
| 100 | # Check for different inline keyword versions. |
| 101 | foreach(KEYWORD "inline" "__inline__" "__inline") |
| 102 | set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}") |
| 103 | CHECK_C_SOURCE_COMPILES( |
| 104 | " |
| 105 | #include <stdio.h> |
| 106 | KEYWORD void a() {} |
| 107 | int main(int argc, char **argv) { a(); return 0; } |
| 108 | " HAVE_${KEYWORD}) |
| 109 | endforeach() |
| 110 | |
| 111 | if (NOT HAVE_inline) |
| 112 | if (HAVE___inline__) |
| 113 | set(inline __inline__) |
| 114 | elseif(HAVE___inline) |
| 115 | set(inline __inline) |
| 116 | endif() |
| 117 | endif() |
| 118 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 119 | # Put the libaries and binaries that get built into directories at the |
| 120 | # top of the build tree rather than in hard-to-find leaf directories. |
| 121 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) |
| 122 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) |
| 123 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) |
| 124 | |
| 125 | # So we can include the CMake generated config file only when |
| 126 | # building with CMAKE. |
| 127 | add_definitions(-DCMAKE_BUILD) |
| 128 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 129 | include(CheckFunctionExists) |
| 130 | include(CheckIncludeFile) |
| 131 | include(CheckIncludeFiles) |
| 132 | include(CheckLibraryExists) |
| 133 | |
| 134 | CHECK_FUNCTION_EXISTS(bzero HAVE_BZERO) |
| 135 | CHECK_FUNCTION_EXISTS(fork HAVE_FORK) |
| 136 | CHECK_FUNCTION_EXISTS(malloc HAVE_MALLOC) |
| 137 | CHECK_FUNCTION_EXISTS(memset HAVE_MEMSET) |
| 138 | CHECK_FUNCTION_EXISTS(realloc HAVE_REALLOC) |
| 139 | CHECK_FUNCTION_EXISTS(socket HAVE_SOCKET) |
| 140 | CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR) |
| 141 | CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK) |
| 142 | CHECK_FUNCTION_EXISTS(getifaddrs HAVE_GETIFADDRS) |
| 143 | |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 144 | if (WITH_BUILTIN_GETIFADDRS) |
| 145 | if (HAVE_GETIFADDRS) |
| 146 | warning("getifaddrs already exists on the system, are you sure you want to build using the BSD version? (This is normally only needed on systems running uclibc)") |
| 147 | endif() |
| 148 | set(LWS_BUILTIN_GETIFADDRS 1) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 149 | endif() |
| 150 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 151 | CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H) |
| 152 | CHECK_INCLUDE_FILE(fcntl.h HAVE_FCNTL_H) |
| 153 | CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H) |
| 154 | CHECK_INCLUDE_FILE(memory.h HAVE_MEMORY_H) |
| 155 | CHECK_INCLUDE_FILE(netinet/in.h HAVE_NETINET_IN_H) |
| 156 | CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H) |
| 157 | CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H) |
| 158 | CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H) |
| 159 | CHECK_INCLUDE_FILE(string.h HAVE_STRING_H) |
| 160 | CHECK_INCLUDE_FILE(sys/prctl.h HAVE_SYS_PRCTL_H) |
| 161 | CHECK_INCLUDE_FILE(sys/socket.h HAVE_SYS_SOCKET_H) |
| 162 | CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H) |
| 163 | CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H) |
| 164 | CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) |
| 165 | CHECK_INCLUDE_FILE(vfork.h HAVE_VFORK_H) |
| 166 | CHECK_INCLUDE_FILE(zlib.h HAVE_ZLIB_H) |
| 167 | |
| 168 | # TODO: These can be tested if they actually work also... |
| 169 | set(HAVE_WORKING_FORK HAVE_FORK) |
| 170 | set(HAVE_WORKING_VFORK HAVE_VFORK) |
| 171 | |
| 172 | CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS) |
| 173 | |
| 174 | if (NOT HAVE_SYS_TYPES_H) |
| 175 | set(pid_t int) |
| 176 | set(size_t "unsigned int") |
| 177 | endif() |
| 178 | |
| 179 | if (NOT HAVE_MALLOC) |
| 180 | set(malloc rpl_malloc) |
| 181 | endif() |
| 182 | |
| 183 | if (NOT HAVE_REALLOC) |
| 184 | set(realloc rpl_realloc) |
| 185 | endif() |
| 186 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 187 | # Generate the config.h that includes all the compilation settings. |
| 188 | configure_file( |
| 189 | ${PROJECT_SOURCE_DIR}/config.h.cmake |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 190 | ${PROJECT_BINARY_DIR}/lws_config.h) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 191 | |
| 192 | set(LIB_LIST) |
| 193 | |
| 194 | if (MSVC) |
| 195 | # Turn off stupid microsoft security warnings. |
| 196 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE) |
| 197 | endif() |
| 198 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 199 | include_directories(${PROJECT_SOURCE_DIR}/lib) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 200 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 201 | # Group headers and sources. |
| 202 | # Some IDEs use this for nicer file structure. |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 203 | set(HDR_PRIVATE |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 204 | lib/private-libwebsockets.h |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 205 | lib/extension-deflate-frame.h |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 206 | lib/extension-deflate-stream.h |
| 207 | ${PROJECT_BINARY_DIR}/lws_config.h |
| 208 | ) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 209 | |
| 210 | set(HDR_PUBLIC |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 211 | lib/libwebsockets.h |
| 212 | ) |
| 213 | |
| 214 | set(SOURCES |
| 215 | lib/base64-decode.c |
| 216 | lib/client.c |
| 217 | lib/client-handshake.c |
| 218 | lib/client-parser.c |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 219 | lib/extension.c |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 220 | lib/extension-deflate-frame.c |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 221 | lib/extension-deflate-stream.c |
| 222 | lib/handshake.c |
| 223 | lib/libwebsockets.c |
| 224 | lib/minilex.c |
| 225 | lib/output.c |
| 226 | lib/parsers.c |
| 227 | lib/server.c |
| 228 | lib/server-handshake.c |
| 229 | lib/sha-1.c |
| 230 | ) |
| 231 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 232 | # Add helper files for Windows. |
| 233 | if (WIN32) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 234 | set(WIN32_HELPERS_PATH win32port/win32helpers) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 235 | |
| 236 | list(APPEND HDR_PRIVATE |
| 237 | ${WIN32_HELPERS_PATH}/websock-w32.h |
| 238 | ${WIN32_HELPERS_PATH}/gettimeofday.h |
| 239 | ) |
| 240 | |
| 241 | list(APPEND SOURCES |
| 242 | ${WIN32_HELPERS_PATH}/websock-w32.c |
| 243 | ${WIN32_HELPERS_PATH}/gettimeofday.c |
| 244 | ) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 245 | |
| 246 | include_directories(${WIN32_HELPERS_PATH}) |
| 247 | else() |
| 248 | # Unix. |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 249 | if (NOT WITHOUT_DAEMONIZE) |
| 250 | list(APPEND SOURCES |
| 251 | lib/daemonize.c |
| 252 | ) |
| 253 | endif() |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 254 | endif() |
| 255 | |
| 256 | if (UNIX) |
| 257 | if (!WITH_BUILTIN_GETIFADDRS) |
| 258 | list(APPEND HDR_PRIVATE lib/getifaddrs.h) |
| 259 | list(APPEND SOURCES lib/getifaddrs.c) |
| 260 | endif() |
| 261 | endif() |
| 262 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 263 | source_group("Headers Private" FILES ${HDR_PRIVATE}) |
| 264 | source_group("Headers Public" FILES ${HDR_PUBLIC}) |
| 265 | source_group("Sources" FILES ${SOURCES}) |
| 266 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 267 | # |
| 268 | # Create the lib. |
| 269 | # |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 270 | add_library(websockets STATIC |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 271 | ${HDR_PRIVATE} |
| 272 | ${HDR_PUBLIC} |
| 273 | ${SOURCES}) |
| 274 | |
| 275 | # |
| 276 | # Find libraries. |
| 277 | # |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 278 | |
| 279 | # |
| 280 | # ZLIB. |
| 281 | # |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 282 | if (WIN32 AND NOT USE_EXTERNAL_ZLIB) |
| 283 | message("Using included Zlib version") |
| 284 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 285 | # Compile ZLib if needed. |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 286 | set(WIN32_ZLIB_PATH "win32port/zlib") |
| 287 | set(ZLIB_SRCS |
| 288 | ${WIN32_ZLIB_PATH}/adler32.c |
| 289 | ${WIN32_ZLIB_PATH}/compress.c |
| 290 | ${WIN32_ZLIB_PATH}/crc32.c |
| 291 | ${WIN32_ZLIB_PATH}/deflate.c |
| 292 | ${WIN32_ZLIB_PATH}/gzclose.c |
| 293 | ${WIN32_ZLIB_PATH}/gzio.c |
| 294 | ${WIN32_ZLIB_PATH}/gzlib.c |
| 295 | ${WIN32_ZLIB_PATH}/gzread.c |
| 296 | ${WIN32_ZLIB_PATH}/gzwrite.c |
| 297 | ${WIN32_ZLIB_PATH}/infback.c |
| 298 | ${WIN32_ZLIB_PATH}/inffast.c |
| 299 | ${WIN32_ZLIB_PATH}/inflate.c |
| 300 | ${WIN32_ZLIB_PATH}/inftrees.c |
| 301 | ${WIN32_ZLIB_PATH}/trees.c |
| 302 | ${WIN32_ZLIB_PATH}/uncompr.c |
| 303 | ${WIN32_ZLIB_PATH}/zutil.c |
| 304 | ) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 305 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 306 | # Create the library. |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 307 | add_library(ZLIB STATIC ${ZLIB_SRCS}) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 308 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 309 | # Set the same variables as find_package would. |
| 310 | set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH}) |
| 311 | get_property(ZLIB_LIBRARIES TARGET zlib PROPERTY LOCATION) |
| 312 | set(ZLIB_FOUND 1) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 313 | else() |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 314 | find_package(ZLIB REQUIRED) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 315 | endif() |
| 316 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 317 | message("ZLib include dirs: ${ZLIB_INCLUDE_DIRS}") |
| 318 | message("ZLib libraries: ${ZLIB_LIBRARIES}") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 319 | include_directories(${ZLIB_INCLUDE_DIRS}) |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 320 | target_link_libraries(websockets ${ZLIB_LIBRARIES}) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 321 | |
| 322 | # |
| 323 | # OpenSSL |
| 324 | # |
| 325 | if (WITH_SSL) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 326 | message("Compiling with SSL support") |
| 327 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 328 | if (USE_CYASSL) |
| 329 | # Use CyaSSL as OpenSSL replacement. |
| 330 | set(OPENSSL_LIBRARIES ${CYASSL_LIB}) |
Joakim Soderberg | b378ce9 | 2013-02-06 15:29:18 +0900 | [diff] [blame] | 331 | set(OPENSSL_INCLUDE_DIR ${CYASSL_INCLUDE_DIRS}) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 332 | set(OPENSSL_FOUND 1) |
| 333 | else() |
| 334 | # TODO: Add support for STATIC also. |
| 335 | find_package(OpenSSL REQUIRED) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 336 | |
| 337 | # TODO: Find OpenSSL binaries and copy them to the output directories for the test-apps so that they can be run out of the box. |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 338 | endif() |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 339 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 340 | message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") |
| 341 | message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 342 | include_directories(${OPENSSL_INCLUDE_DIR}) |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 343 | target_link_libraries(websockets ${OPENSSL_LIBRARIES}) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 344 | endif(WITH_SSL) |
| 345 | |
| 346 | # |
| 347 | # Platform specific libs. |
| 348 | # |
| 349 | if (WIN32) |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 350 | target_link_libraries(websockets ws2_32.lib) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 351 | endif() |
| 352 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 353 | if (UNIX) |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 354 | target_link_libraries(websockets m) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 355 | endif() |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 356 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 357 | # |
| 358 | # Test applications |
| 359 | # |
| 360 | if (NOT WITHOUT_TESTAPPS) |
| 361 | # |
| 362 | # Helper function for adding a test app. |
| 363 | # |
| 364 | function(create_test_app TEST_NAME MAIN_SRC WIN32_SRCS WIN32_HDRS) |
| 365 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 366 | set(TEST_SRCS ${MAIN_SRC}) |
| 367 | set(TEST_HDR) |
| 368 | |
| 369 | if (WIN32) |
| 370 | list(APPEND TEST_SRCS |
| 371 | ${WIN32_HELPERS_PATH}/getopt.c |
| 372 | ${WIN32_HELPERS_PATH}/getopt_long.c |
| 373 | ${WIN32_HELPERS_PATH}/gettimeofday.c |
| 374 | ${WIN32_SRCS}) |
| 375 | |
| 376 | list(APPEND TEST_HDR |
| 377 | ${WIN32_HELPERS_PATH}/getopt.h |
| 378 | ${WIN32_HELPERS_PATH}/gettimeofday.h |
| 379 | ${WIN32_HDRS}) |
| 380 | endif(WIN32) |
| 381 | |
| 382 | source_group("Headers" FILES ${TEST_HDR}) |
| 383 | source_group("Sources" FILES ${TEST_SRCS}) |
| 384 | add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR}) |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 385 | target_link_libraries(${TEST_NAME} websockets) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 386 | |
| 387 | set_property( |
| 388 | TARGET ${TEST_NAME} |
| 389 | PROPERTY COMPILE_DEFINITIONS INSTALL_DATADIR="${SSL_CERT_DIR}" |
| 390 | ) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 391 | endfunction() |
| 392 | |
| 393 | # |
| 394 | # test-client |
| 395 | # |
| 396 | if (NOT WITHOUT_CLIENT) |
| 397 | create_test_app(test-client |
| 398 | "test-server/test-client.c" |
| 399 | "" |
| 400 | "") |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame^] | 401 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 402 | |
| 403 | # |
| 404 | # test-server |
| 405 | # |
| 406 | if (NOT WITHOUT_SERVER) |
| 407 | create_test_app(test-server |
| 408 | "test-server/test-server.c" |
| 409 | "" |
| 410 | "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h") |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame^] | 411 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 412 | |
| 413 | # |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 414 | # test-server-extpoll |
| 415 | # |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame^] | 416 | if (NOT WITHOUT_SERVER AND NOT WITHOUT_SERVER_EXTPOLL) |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 417 | create_test_app(test-server-extpoll |
| 418 | "test-server/test-server.c" |
| 419 | "" |
| 420 | "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h") |
| 421 | |
| 422 | # Set defines for this executable only. |
| 423 | set_property( |
| 424 | TARGET test-server-extpoll |
| 425 | PROPERTY COMPILE_DEFINITIONS EXTERNAL_POLL INSTALL_DATADIR="${SSL_CERT_DIR}" |
| 426 | ) |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame^] | 427 | endif() |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 428 | |
| 429 | # |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 430 | # test-fraggle |
| 431 | # |
| 432 | if (NOT WITHOUT_FRAGGLE) |
| 433 | create_test_app(test-fraggle |
| 434 | "test-server/test-fraggle.c" |
| 435 | "" |
| 436 | "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h") |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame^] | 437 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 438 | |
| 439 | # |
| 440 | # test-ping |
| 441 | # |
| 442 | if (NOT WITHOUT_PING) |
| 443 | create_test_app(test-ping |
| 444 | "test-server/test-ping.c" |
| 445 | "" |
| 446 | "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h") |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame^] | 447 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 448 | |
| 449 | # |
| 450 | # Copy OpenSSL dlls to the output directory on Windows. |
| 451 | # (Otherwise we'll get an error when trying to run) |
| 452 | # |
| 453 | if (WIN32 AND WITH_SSL AND NOT USE_CYASSL) |
| 454 | |
| 455 | message("Searching for OpenSSL dlls") |
| 456 | find_package(OpenSSLbins) |
| 457 | |
| 458 | if(OPENSSL_BIN_FOUND) |
| 459 | message("OpenSSL dlls found, copying to output directory") |
| 460 | message("Libeay: ${LIBEAY_BIN}") |
| 461 | message("SSLeay: ${SSLEAY_BIN}") |
| 462 | |
| 463 | foreach(TARGET_BIN |
| 464 | test-client |
| 465 | test-server |
| 466 | test-fraggle |
| 467 | test-echo |
| 468 | test-ping |
| 469 | ) |
| 470 | add_custom_command(TARGET ${TARGET_BIN} |
| 471 | POST_BUILD |
| 472 | COMMAND ${CMAKE_COMMAND} -E copy ${LIBEAY_BIN} $<TARGET_FILE_DIR:${TARGET_BIN}> VERBATIM) |
| 473 | |
| 474 | add_custom_command(TARGET ${TARGET_BIN} |
| 475 | POST_BUILD |
| 476 | COMMAND ${CMAKE_COMMAND} -E copy ${SSLEAY_BIN} $<TARGET_FILE_DIR:${TARGET_BIN}> VERBATIM) |
| 477 | endforeach() |
| 478 | endif() |
| 479 | endif() |
| 480 | endif(NOT WITHOUT_TESTAPPS) |