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") |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 6 | set(CPACK_PACKAGE_NAME "${PACKAGE}") |
| 7 | set(CPACK_PACKAGE_VERSION_MAJOR "1") |
Andy Green | 19c1a99 | 2013-03-10 06:59:01 +0800 | [diff] [blame] | 8 | set(CPACK_PACKAGE_VERSION_MINOR "3") |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 9 | set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}") |
| 10 | set(CPACK_PACKAGE_VENDOR "andy@warmcat.com") |
| 11 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}") |
Andy Green | 19c1a99 | 2013-03-10 06:59:01 +0800 | [diff] [blame] | 12 | set(SOVERSION "4.0.0") |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 13 | set(CPACK_SOURCE_GENERATOR "TGZ") |
| 14 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") |
| 15 | set(VERSION "${CPACK_PACKAGE_VERSION}") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 16 | |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 17 | set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION}) |
Edwin van den Oetelaar | d6bf73c | 2013-02-18 20:20:05 +0800 | [diff] [blame] | 18 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/") |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 19 | |
Andy Green | 5b479ac | 2013-03-30 10:30:03 +0800 | [diff] [blame] | 20 | message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'") |
| 21 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 22 | # Try to find the current Git hash. |
| 23 | find_package(Git) |
| 24 | if(GIT_EXECUTABLE) |
| 25 | execute_process( |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 26 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 27 | COMMAND "${GIT_EXECUTABLE}" log -n 1 --pretty=%h |
| 28 | OUTPUT_VARIABLE GIT_HASH |
| 29 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 30 | ) |
| 31 | |
| 32 | set(LWS_BUILD_HASH ${GIT_HASH}) |
| 33 | message("Git commit hash: ${LWS_BUILD_HASH}") |
| 34 | endif() |
| 35 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 36 | option(LWS_WITH_SSL "Include SSL support (default OpenSSL, CyaSSL if LWS_USE_CYASSL is set)" ON) |
| 37 | option(LWS_USE_EXTERNAL_ZLIB "Search the system for ZLib instead of using the included one (on Windows)" OFF) |
| 38 | option(LWS_USE_CYASSL "Use CyaSSL replacement for OpenSSL. When settings this, you also need to specify LWS_CYASSL_LIB and LWS_CYASSL_INCLUDE_DIRS" OFF) |
| 39 | option(LWS_WITHOUT_BUILTIN_GETIFADDRS "Don't use BSD getifaddrs implementation from libwebsockets if it is missing (this will result in a compilation error) ... Default is your libc provides it. On some systems such as uclibc it doesn't exist." OFF) |
| 40 | option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF) |
| 41 | option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF) |
| 42 | #option(LWS_WITH_LIBCRYPTO "Use libcrypto MD5 and SHA1 implementations" ON) |
| 43 | option(LWS_LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF) |
| 44 | option(LWS_WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF) |
| 45 | option(LWS_WITHOUT_TEST_SERVER "Don't build the test server" OFF) |
| 46 | option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF) |
| 47 | option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF) |
| 48 | option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF) |
| 49 | option(LWS_WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF) |
| 50 | option(LWS_WITHOUT_DEBUG "Don't compile debug related code" OFF) |
| 51 | option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" OFF) |
| 52 | option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF) |
| 53 | option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" OFF) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 54 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 55 | # Allow the user to override installation directories. |
| 56 | set(LWS_INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") |
| 57 | set(LWS_INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables") |
| 58 | set(LWS_INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files") |
| 59 | set(LWS_INSTALL_EXAMPLES_DIR bin CACHE PATH "Installation directory for example files") |
| 60 | |
| 61 | if (LWS_WITHOUT_CLIENT AND LWS_WITHOUT_SERVER) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 62 | message(FATAL_ERROR "Makes no sense to compile without both client or server.") |
| 63 | endif() |
| 64 | |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 65 | # The base dir where the test-apps look for the SSL certs. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 66 | set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory") |
| 67 | if (WIN32) |
| 68 | set(LWS_OPENSSL_CLIENT_CERTS . CACHE PATH "Client SSL certificate directory") |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 69 | else() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 70 | 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] | 71 | endif() |
| 72 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 73 | set(LWS_CYASSL_LIB CACHE PATH "Path to the CyaSSL library") |
| 74 | set(LWS_CYASSL_INCLUDE_DIRS CACHE PATH "Path to the CyaSSL include directory") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 75 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 76 | if (LWS_USE_CYASSL) |
| 77 | if ("${LWS_CYASSL_LIB}" STREQUAL "" OR "${LWS_CYASSL_INCLUDE_DIRS}" STREQUAL "") |
| 78 | message(FATAL_ERROR "You must set LWS_CYASSL_LIB and LWS_CYASSL_INCLUDE_DIRS when LWS_USE_CYASSL is turned on") |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 79 | endif() |
John Clark | 388dc7d | 2014-03-01 22:24:47 -0500 | [diff] [blame] | 80 | set(USE_CYASSL 1) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 81 | endif() |
| 82 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 83 | if (LWS_WITHOUT_EXTENSIONS) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 84 | set(LWS_NO_EXTENSIONS 1) |
| 85 | endif() |
| 86 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 87 | if (LWS_WITH_SSL) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 88 | set(LWS_OPENSSL_SUPPORT 1) |
| 89 | endif() |
| 90 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 91 | if (LWS_WITH_LATENCY) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 92 | set(LWS_LATENCY 1) |
| 93 | endif() |
| 94 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 95 | if (LWS_WITHOUT_DAEMONIZE OR WIN32) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 96 | set(LWS_NO_DAEMONIZE 1) |
| 97 | endif() |
| 98 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 99 | if (LWS_WITHOUT_SERVER) |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame] | 100 | set(LWS_NO_SERVER 1) |
| 101 | endif() |
| 102 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 103 | if (LWS_WITHOUT_CLIENT) |
Joakim Soderberg | e9a4211 | 2013-02-06 15:29:59 +0900 | [diff] [blame] | 104 | set(LWS_NO_CLIENT 1) |
| 105 | endif() |
| 106 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 107 | if (LWS_WITHOUT_DEBUG) |
Joakim Söderberg | 51197c0 | 2013-02-22 09:28:13 +0800 | [diff] [blame] | 108 | set(_DEBUG 0) |
| 109 | else() |
| 110 | set(_DEBUG 1) |
| 111 | endif() |
| 112 | |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 113 | if (MINGW) |
| 114 | set(LWS_MINGW_SUPPORT 1) |
| 115 | endif() |
| 116 | |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 117 | include_directories("${PROJECT_BINARY_DIR}") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 118 | |
Joakim Soderberg | 4f4a38b | 2013-02-06 15:28:07 +0900 | [diff] [blame] | 119 | include(CheckCSourceCompiles) |
| 120 | |
| 121 | # Check for different inline keyword versions. |
| 122 | foreach(KEYWORD "inline" "__inline__" "__inline") |
| 123 | set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}") |
| 124 | CHECK_C_SOURCE_COMPILES( |
| 125 | " |
| 126 | #include <stdio.h> |
| 127 | KEYWORD void a() {} |
| 128 | int main(int argc, char **argv) { a(); return 0; } |
| 129 | " HAVE_${KEYWORD}) |
| 130 | endforeach() |
| 131 | |
| 132 | if (NOT HAVE_inline) |
| 133 | if (HAVE___inline__) |
| 134 | set(inline __inline__) |
| 135 | elseif(HAVE___inline) |
| 136 | set(inline __inline) |
| 137 | endif() |
| 138 | endif() |
| 139 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 140 | # Put the libaries and binaries that get built into directories at the |
| 141 | # 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] | 142 | SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") |
| 143 | SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") |
| 144 | SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib") |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 145 | |
thinkski | d34bae1 | 2013-04-16 19:48:05 +0800 | [diff] [blame] | 146 | # Put absolute path of dynamic libraries into the object code. Some |
| 147 | # architectures, notably Mac OS X, need this. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 148 | 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] | 149 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 150 | # So we can include the CMake generated config file only when |
| 151 | # building with CMAKE. |
| 152 | add_definitions(-DCMAKE_BUILD) |
| 153 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 154 | include(CheckFunctionExists) |
| 155 | include(CheckIncludeFile) |
| 156 | include(CheckIncludeFiles) |
| 157 | include(CheckLibraryExists) |
Patrick Gansterer | 8a59033 | 2014-02-28 00:42:08 +0100 | [diff] [blame] | 158 | include(CheckTypeSize) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 159 | |
| 160 | CHECK_FUNCTION_EXISTS(bzero HAVE_BZERO) |
| 161 | CHECK_FUNCTION_EXISTS(fork HAVE_FORK) |
Patrick Gansterer | 61a6ae4 | 2014-02-28 02:32:03 +0100 | [diff] [blame] | 162 | CHECK_FUNCTION_EXISTS(getenv HAVE_GETENV) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 163 | CHECK_FUNCTION_EXISTS(malloc HAVE_MALLOC) |
| 164 | CHECK_FUNCTION_EXISTS(memset HAVE_MEMSET) |
| 165 | CHECK_FUNCTION_EXISTS(realloc HAVE_REALLOC) |
| 166 | CHECK_FUNCTION_EXISTS(socket HAVE_SOCKET) |
| 167 | CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR) |
| 168 | CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK) |
| 169 | CHECK_FUNCTION_EXISTS(getifaddrs HAVE_GETIFADDRS) |
| 170 | |
Joakim Soderberg | fcec61c | 2013-02-22 09:28:02 +0800 | [diff] [blame] | 171 | if (NOT HAVE_GETIFADDRS) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 172 | if (LWS_WITHOUT_BUILTIN_GETIFADDRS) |
| 173 | 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] | 174 | endif() |
Joakim Soderberg | fcec61c | 2013-02-22 09:28:02 +0800 | [diff] [blame] | 175 | |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 176 | set(LWS_BUILTIN_GETIFADDRS 1) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 177 | endif() |
| 178 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 179 | CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H) |
| 180 | CHECK_INCLUDE_FILE(fcntl.h HAVE_FCNTL_H) |
| 181 | CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H) |
| 182 | CHECK_INCLUDE_FILE(memory.h HAVE_MEMORY_H) |
| 183 | CHECK_INCLUDE_FILE(netinet/in.h HAVE_NETINET_IN_H) |
| 184 | CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H) |
| 185 | CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H) |
| 186 | CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H) |
| 187 | CHECK_INCLUDE_FILE(string.h HAVE_STRING_H) |
| 188 | CHECK_INCLUDE_FILE(sys/prctl.h HAVE_SYS_PRCTL_H) |
| 189 | CHECK_INCLUDE_FILE(sys/socket.h HAVE_SYS_SOCKET_H) |
| 190 | CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H) |
| 191 | CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H) |
| 192 | CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) |
| 193 | CHECK_INCLUDE_FILE(vfork.h HAVE_VFORK_H) |
| 194 | CHECK_INCLUDE_FILE(zlib.h HAVE_ZLIB_H) |
| 195 | |
| 196 | # TODO: These can be tested if they actually work also... |
| 197 | set(HAVE_WORKING_FORK HAVE_FORK) |
| 198 | set(HAVE_WORKING_VFORK HAVE_VFORK) |
| 199 | |
| 200 | CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS) |
| 201 | |
Patrick Gansterer | 8a59033 | 2014-02-28 00:42:08 +0100 | [diff] [blame] | 202 | CHECK_TYPE_SIZE(pid_t PID_T_SIZE) |
| 203 | CHECK_TYPE_SIZE(size_t SIZE_T_SIZE) |
| 204 | |
| 205 | if (NOT PID_T_SIZE) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 206 | set(pid_t int) |
Patrick Gansterer | 8a59033 | 2014-02-28 00:42:08 +0100 | [diff] [blame] | 207 | endif() |
| 208 | |
| 209 | if (NOT SIZE_T_SIZE) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 210 | set(size_t "unsigned int") |
| 211 | endif() |
| 212 | |
| 213 | if (NOT HAVE_MALLOC) |
| 214 | set(malloc rpl_malloc) |
| 215 | endif() |
| 216 | |
| 217 | if (NOT HAVE_REALLOC) |
| 218 | set(realloc rpl_realloc) |
| 219 | endif() |
| 220 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 221 | # Generate the config.h that includes all the compilation settings. |
| 222 | configure_file( |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 223 | "${PROJECT_SOURCE_DIR}/config.h.cmake" |
| 224 | "${PROJECT_BINARY_DIR}/lws_config.h") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 225 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 226 | if (MSVC) |
| 227 | # Turn off stupid microsoft security warnings. |
| 228 | 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] | 229 | endif(MSVC) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 230 | |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 231 | include_directories("${PROJECT_SOURCE_DIR}/lib") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 232 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 233 | # Group headers and sources. |
| 234 | # Some IDEs use this for nicer file structure. |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 235 | set(HDR_PRIVATE |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 236 | lib/private-libwebsockets.h |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 237 | "${PROJECT_BINARY_DIR}/lws_config.h" |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 238 | ) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 239 | |
| 240 | set(HDR_PUBLIC |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 241 | "${PROJECT_SOURCE_DIR}/lib/libwebsockets.h" |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 242 | ) |
| 243 | |
| 244 | set(SOURCES |
| 245 | lib/base64-decode.c |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 246 | lib/handshake.c |
| 247 | lib/libwebsockets.c |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 248 | lib/output.c |
| 249 | lib/parsers.c |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 250 | lib/sha-1.c |
| 251 | ) |
| 252 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 253 | if (NOT LWS_WITHOUT_CLIENT) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 254 | list(APPEND SOURCES |
| 255 | lib/client.c |
| 256 | lib/client-handshake.c |
| 257 | lib/client-parser.c |
| 258 | ) |
| 259 | endif() |
| 260 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 261 | if (NOT LWS_WITHOUT_SERVER) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 262 | list(APPEND SOURCES |
| 263 | lib/server.c |
| 264 | lib/server-handshake.c |
| 265 | ) |
| 266 | endif() |
| 267 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 268 | if (NOT LWS_WITHOUT_EXTENSIONS) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 269 | list(APPEND HDR_PRIVATE |
| 270 | lib/extension-deflate-frame.h |
| 271 | lib/extension-deflate-stream.h |
| 272 | ) |
| 273 | |
| 274 | list(APPEND SOURCES |
| 275 | lib/extension.c |
| 276 | lib/extension-deflate-frame.c |
| 277 | lib/extension-deflate-stream.c |
| 278 | ) |
| 279 | endif() |
| 280 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 281 | # Add helper files for Windows. |
| 282 | if (WIN32) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 283 | set(WIN32_HELPERS_PATH win32port/win32helpers) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 284 | |
Andy Green | a833494 | 2013-03-09 09:16:41 +0800 | [diff] [blame] | 285 | list(APPEND HDR_PUBLIC |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 286 | ${WIN32_HELPERS_PATH}/websock-w32.h |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 287 | ) |
Patrick Gansterer | 92792b4 | 2014-02-26 21:37:31 +0100 | [diff] [blame] | 288 | if (NOT MINGW) |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 289 | list(APPEND SOURCES |
| 290 | ${WIN32_HELPERS_PATH}/websock-w32.c |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 291 | ) |
Patrick Gansterer | 92792b4 | 2014-02-26 21:37:31 +0100 | [diff] [blame] | 292 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 293 | include_directories(${WIN32_HELPERS_PATH}) |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 294 | else(WIN32) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 295 | # Unix. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 296 | if (NOT LWS_WITHOUT_DAEMONIZE) |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 297 | list(APPEND SOURCES |
| 298 | lib/daemonize.c |
| 299 | ) |
| 300 | endif() |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 301 | endif(WIN32) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 302 | |
| 303 | if (UNIX) |
Joakim Soderberg | fcec61c | 2013-02-22 09:28:02 +0800 | [diff] [blame] | 304 | if (NOT HAVE_GETIFADDRS) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 305 | list(APPEND HDR_PRIVATE lib/getifaddrs.h) |
| 306 | list(APPEND SOURCES lib/getifaddrs.c) |
| 307 | endif() |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 308 | endif(UNIX) |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 309 | |
Andy Green | da3f6ff | 2013-03-16 12:32:59 +0800 | [diff] [blame] | 310 | |
Joakim Soderberg | c2012e4 | 2013-03-23 08:55:02 +0800 | [diff] [blame] | 311 | if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) |
pmcdona | 0a0a7eb | 2013-12-18 10:17:25 +0800 | [diff] [blame] | 312 | if (UNIX) |
Erland Isaksson | 578a24d | 2013-09-18 09:00:52 +0800 | [diff] [blame] | 313 | set( CMAKE_C_FLAGS "-Wall -Werror -O4 -fvisibility=hidden ${CMAKE_C_FLAGS}" ) |
pmcdona | 0a0a7eb | 2013-12-18 10:17:25 +0800 | [diff] [blame] | 314 | else(UNIX) |
| 315 | set( CMAKE_C_FLAGS "-Wall -O4 -fvisibility=hidden ${CMAKE_C_FLAGS}" ) |
| 316 | endif(UNIX) |
Joakim Soderberg | c2012e4 | 2013-03-23 08:55:02 +0800 | [diff] [blame] | 317 | endif () |
Andy Green | da3f6ff | 2013-03-16 12:32:59 +0800 | [diff] [blame] | 318 | |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 319 | source_group("Headers Private" FILES ${HDR_PRIVATE}) |
| 320 | source_group("Headers Public" FILES ${HDR_PUBLIC}) |
| 321 | source_group("Sources" FILES ${SOURCES}) |
| 322 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 323 | # |
| 324 | # Create the lib. |
| 325 | # |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 326 | add_library(websockets STATIC |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 327 | ${HDR_PRIVATE} |
| 328 | ${HDR_PUBLIC} |
| 329 | ${SOURCES}) |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 330 | add_library(websockets_shared SHARED |
| 331 | ${HDR_PRIVATE} |
| 332 | ${HDR_PUBLIC} |
| 333 | ${SOURCES}) |
| 334 | |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 335 | if (WIN32) |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 336 | # On Windows libs have the same file ending (.lib) |
| 337 | # for both static and shared libraries, so we |
| 338 | # need a unique name for the static one. |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 339 | set_target_properties(websockets |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 340 | PROPERTIES |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 341 | OUTPUT_NAME websockets_static) |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 342 | |
| 343 | # Compile as DLL (export function declarations) |
| 344 | set_property( |
| 345 | TARGET websockets_shared |
| 346 | PROPERTY COMPILE_DEFINITIONS |
| 347 | LWS_DLL |
| 348 | LWS_INTERNAL |
| 349 | ) |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 350 | endif(WIN32) |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 351 | |
| 352 | # We want the shared lib to be named "libwebsockets" |
| 353 | # not "libwebsocket_shared". |
| 354 | set_target_properties(websockets_shared |
| 355 | PROPERTIES |
| 356 | OUTPUT_NAME websockets) |
Joakim Soderberg | f83585f | 2013-02-13 09:29:09 +0800 | [diff] [blame] | 357 | |
| 358 | # Set the so version of the lib. |
Andy Green | 19c1a99 | 2013-03-10 06:59:01 +0800 | [diff] [blame] | 359 | # Equivalent to LDFLAGS=-version-info x:x:x |
Joakim Soderberg | f83585f | 2013-02-13 09:29:09 +0800 | [diff] [blame] | 360 | if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 361 | foreach(lib websockets websockets_shared) |
| 362 | set_target_properties(${lib} |
| 363 | PROPERTIES |
| 364 | SOVERSION ${SOVERSION}) |
| 365 | endforeach() |
Joakim Soderberg | f83585f | 2013-02-13 09:29:09 +0800 | [diff] [blame] | 366 | endif() |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 367 | |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 368 | set(LIB_LIST) |
| 369 | |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 370 | # |
| 371 | # Find libraries. |
| 372 | # |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 373 | |
| 374 | # |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 375 | # ZLIB (Only needed for deflate extensions). |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 376 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 377 | if (NOT LWS_WITHOUT_EXTENSIONS) |
| 378 | if (WIN32 AND NOT LWS_USE_EXTERNAL_ZLIB) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 379 | message("Using included Zlib version") |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 380 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 381 | # Compile ZLib if needed. |
| 382 | set(WIN32_ZLIB_PATH "win32port/zlib") |
| 383 | set(ZLIB_SRCS |
| 384 | ${WIN32_ZLIB_PATH}/adler32.c |
| 385 | ${WIN32_ZLIB_PATH}/compress.c |
| 386 | ${WIN32_ZLIB_PATH}/crc32.c |
| 387 | ${WIN32_ZLIB_PATH}/deflate.c |
| 388 | ${WIN32_ZLIB_PATH}/gzclose.c |
| 389 | ${WIN32_ZLIB_PATH}/gzio.c |
| 390 | ${WIN32_ZLIB_PATH}/gzlib.c |
| 391 | ${WIN32_ZLIB_PATH}/gzread.c |
| 392 | ${WIN32_ZLIB_PATH}/gzwrite.c |
| 393 | ${WIN32_ZLIB_PATH}/infback.c |
| 394 | ${WIN32_ZLIB_PATH}/inffast.c |
| 395 | ${WIN32_ZLIB_PATH}/inflate.c |
| 396 | ${WIN32_ZLIB_PATH}/inftrees.c |
| 397 | ${WIN32_ZLIB_PATH}/trees.c |
| 398 | ${WIN32_ZLIB_PATH}/uncompr.c |
| 399 | ${WIN32_ZLIB_PATH}/zutil.c |
| 400 | ) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 401 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 402 | # Create the library. |
| 403 | add_library(ZLIB STATIC ${ZLIB_SRCS}) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 404 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 405 | # Set the same variables as find_package would. |
| 406 | set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH}) |
| 407 | get_property(ZLIB_LIBRARIES TARGET ZLIB PROPERTY LOCATION) |
| 408 | set(ZLIB_FOUND 1) |
| 409 | else() |
| 410 | find_package(ZLIB REQUIRED) |
| 411 | endif() |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 412 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 413 | # Make sure ZLib is compiled before the libs. |
| 414 | foreach (lib websockets websockets_shared) |
| 415 | add_dependencies(${lib} ZLIB) |
| 416 | endforeach() |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 417 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 418 | message("ZLib include dirs: ${ZLIB_INCLUDE_DIRS}") |
| 419 | message("ZLib libraries: ${ZLIB_LIBRARIES}") |
| 420 | include_directories(${ZLIB_INCLUDE_DIRS}) |
| 421 | list(APPEND LIB_LIST ${ZLIB_LIBRARIES}) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 422 | endif(NOT LWS_WITHOUT_EXTENSIONS) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 423 | |
| 424 | # |
| 425 | # OpenSSL |
| 426 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 427 | if (LWS_WITH_SSL) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 428 | message("Compiling with SSL support") |
| 429 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 430 | if (LWS_USE_CYASSL) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 431 | # Use CyaSSL as OpenSSL replacement. |
Joakim Söderberg | cb4156d | 2013-02-06 15:30:56 +0900 | [diff] [blame] | 432 | # TODO: Add a find_package command for this also. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 433 | message("CyaSSL include dir: ${LWS_CYASSL_INCLUDE_DIRS}") |
| 434 | message("CyaSSL libraries: ${LWS_CYASSL_LIB}") |
Joakim Söderberg | cb4156d | 2013-02-06 15:30:56 +0900 | [diff] [blame] | 435 | |
Joakim Soderberg | 7df9908 | 2013-02-07 20:24:19 +0800 | [diff] [blame] | 436 | # Additional to the root directory we need to include |
| 437 | # the cyassl/ subdirectory which contains the OpenSSL |
| 438 | # compatability layer headers. |
John Clark | 388dc7d | 2014-03-01 22:24:47 -0500 | [diff] [blame] | 439 | foreach(inc ${LWS_CYASSL_INCLUDE_DIRS}) |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 440 | include_directories("${inc}" "${inc}/cyassl") |
Joakim Soderberg | 7df9908 | 2013-02-07 20:24:19 +0800 | [diff] [blame] | 441 | endforeach() |
| 442 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 443 | list(APPEND LIB_LIST "${LWS_CYASSL_LIB}") |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 444 | else() |
| 445 | # TODO: Add support for STATIC also. |
| 446 | find_package(OpenSSL REQUIRED) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 447 | |
Joakim Söderberg | cb4156d | 2013-02-06 15:30:56 +0900 | [diff] [blame] | 448 | message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") |
| 449 | message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") |
Joakim Soderberg | add3926 | 2013-02-06 15:25:26 +0900 | [diff] [blame] | 450 | |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 451 | include_directories("${OPENSSL_INCLUDE_DIR}") |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 452 | list(APPEND LIB_LIST ${OPENSSL_LIBRARIES}) |
Joakim Söderberg | cb4156d | 2013-02-06 15:30:56 +0900 | [diff] [blame] | 453 | endif() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 454 | endif(LWS_WITH_SSL) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 455 | |
| 456 | # |
| 457 | # Platform specific libs. |
| 458 | # |
Patrick Gansterer | 5b71aac | 2014-02-28 01:31:39 +0100 | [diff] [blame] | 459 | if (WINCE) |
| 460 | list(APPEND LIB_LIST ws2.lib) |
| 461 | elseif (WIN32) |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 462 | list(APPEND LIB_LIST ws2_32.lib) |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 463 | endif() |
| 464 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 465 | if (UNIX) |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 466 | list(APPEND LIB_LIST m) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 467 | endif() |
Joakim Soderberg | 08e434e | 2013-02-01 14:52:53 +0100 | [diff] [blame] | 468 | |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 469 | # Setup the linking for all libs. |
| 470 | foreach (lib websockets websockets_shared) |
| 471 | target_link_libraries(${lib} ${LIB_LIST}) |
| 472 | endforeach() |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 473 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 474 | # |
| 475 | # Test applications |
| 476 | # |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 477 | set(TEST_APP_LIST) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 478 | if (NOT LWS_WITHOUT_TESTAPPS) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 479 | # |
| 480 | # Helper function for adding a test app. |
| 481 | # |
Joakim Soderberg | 11a8cda | 2013-02-22 09:28:06 +0800 | [diff] [blame] | 482 | macro(create_test_app TEST_NAME MAIN_SRC WIN32_SRCS WIN32_HDRS) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 483 | |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 484 | set(TEST_SRCS ${MAIN_SRC}) |
| 485 | set(TEST_HDR) |
| 486 | |
| 487 | if (WIN32) |
| 488 | list(APPEND TEST_SRCS |
| 489 | ${WIN32_HELPERS_PATH}/getopt.c |
| 490 | ${WIN32_HELPERS_PATH}/getopt_long.c |
| 491 | ${WIN32_HELPERS_PATH}/gettimeofday.c |
| 492 | ${WIN32_SRCS}) |
| 493 | |
| 494 | list(APPEND TEST_HDR |
| 495 | ${WIN32_HELPERS_PATH}/getopt.h |
| 496 | ${WIN32_HELPERS_PATH}/gettimeofday.h |
| 497 | ${WIN32_HDRS}) |
| 498 | endif(WIN32) |
| 499 | |
Joakim Soderberg | 0848353 | 2013-02-13 09:29:17 +0800 | [diff] [blame] | 500 | source_group("Headers Private" FILES ${TEST_HDR}) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 501 | source_group("Sources" FILES ${TEST_SRCS}) |
| 502 | add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR}) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 503 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 504 | if (LWS_LINK_TESTAPPS_DYNAMIC) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 505 | target_link_libraries(${TEST_NAME} websockets_shared) |
| 506 | add_dependencies(${TEST_NAME} websockets_shared) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 507 | else(LWS_LINK_TESTAPPS_DYNAMIC) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 508 | target_link_libraries(${TEST_NAME} websockets) |
| 509 | add_dependencies(${TEST_NAME} websockets) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 510 | endif(LWS_LINK_TESTAPPS_DYNAMIC) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 511 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 512 | # Set test app specific defines. |
| 513 | set_property(TARGET ${TEST_NAME} |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 514 | PROPERTY COMPILE_DEFINITIONS |
Andy Green | 63b3b95 | 2013-03-09 12:51:43 +0800 | [diff] [blame] | 515 | INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" |
Joakim Soderberg | d2edfec | 2013-02-06 15:27:27 +0900 | [diff] [blame] | 516 | ) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 517 | |
| 518 | # Prefix the binary names with libwebsockets. |
| 519 | set_target_properties(${TEST_NAME} |
| 520 | PROPERTIES |
| 521 | OUTPUT_NAME libwebsockets-${TEST_NAME}) |
| 522 | |
| 523 | # Add to the list of tests. |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 524 | list(APPEND TEST_APP_LIST ${TEST_NAME}) |
Joakim Soderberg | 11a8cda | 2013-02-22 09:28:06 +0800 | [diff] [blame] | 525 | endmacro() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 526 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 527 | if (LWS_WITH_SSL AND NOT LWS_USE_CYASSL) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 528 | message("Searching for OpenSSL executable and dlls") |
| 529 | find_package(OpenSSLbins) |
| 530 | message("OpenSSL executable: ${OPENSSL_EXECUTABLE}") |
| 531 | endif() |
| 532 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 533 | if (NOT LWS_WITHOUT_SERVER) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 534 | # |
| 535 | # test-server |
| 536 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 537 | if (NOT LWS_WITHOUT_TEST_SERVER) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 538 | create_test_app(test-server |
| 539 | "test-server/test-server.c" |
| 540 | "" |
| 541 | "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h") |
| 542 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 543 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 544 | # |
| 545 | # test-server-extpoll |
| 546 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 547 | if (NOT LWS_WITHOUT_TEST_SERVER_EXTPOLL) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 548 | create_test_app(test-server-extpoll |
| 549 | "test-server/test-server.c" |
| 550 | "win32port/win32helpers/websock-w32.c" |
| 551 | "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h") |
| 552 | # Set defines for this executable only. |
| 553 | set_property( |
| 554 | TARGET test-server-extpoll |
| 555 | PROPERTY COMPILE_DEFINITIONS |
| 556 | EXTERNAL_POLL |
Andy Green | 63b3b95 | 2013-03-09 12:51:43 +0800 | [diff] [blame] | 557 | INSTALL_DATADIR="${CMAKE_INSTALL_PREFIX}/share" |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 558 | ) |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 559 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 560 | # We need to link against winsock code. |
| 561 | if (WIN32) |
| 562 | target_link_libraries(test-server-extpoll ws2_32.lib) |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 563 | endif(WIN32) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 564 | endif() |
| 565 | |
| 566 | # Data files for running the test server. |
| 567 | set(TEST_SERVER_DATA |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 568 | "${PROJECT_SOURCE_DIR}/test-server/favicon.ico" |
| 569 | "${PROJECT_SOURCE_DIR}/test-server/leaf.jpg" |
| 570 | "${PROJECT_SOURCE_DIR}/test-server/libwebsockets.org-logo.png" |
| 571 | "${PROJECT_SOURCE_DIR}/test-server/test.html") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 572 | |
| 573 | # Generate self-signed SSL certs for the test-server. |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 574 | 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] | 575 | message("Generating SSL Certificates for the test-server...") |
| 576 | |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 577 | set(TEST_SERVER_SSL_KEY "${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem") |
| 578 | 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] | 579 | |
| 580 | if (WIN32) |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 581 | file(WRITE "${PROJECT_BINARY_DIR}/openssl_input.txt" |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 582 | "GB\n" |
| 583 | "Erewhon\n" |
| 584 | "All around\n" |
| 585 | "libwebsockets-test\n" |
| 586 | "localhost\n" |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 587 | "none@invalid.org\n\n" |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 588 | ) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 589 | |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 590 | # The "type" command is a bit picky with paths. |
| 591 | file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 592 | message("OPENSSL_INPUT_WIN_PATH = ${OPENSSL_INPUT_WIN_PATH}") |
| 593 | 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] | 594 | |
| 595 | execute_process( |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 596 | COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}" |
| 597 | COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" |
| 598 | RESULT_VARIABLE OPENSSL_RETURN_CODE) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 599 | |
Joakim Soderberg | c7ed2be | 2013-02-22 09:28:17 +0800 | [diff] [blame] | 600 | message("\n") |
| 601 | |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 602 | if (OPENSSL_RETURN_CODE) |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 603 | message(WARNING "!!! Failed to generate SSL certificate for Test Server using cmd.exe !!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}") |
| 604 | else() |
| 605 | message("SUCCSESFULLY generated SSL certificate") |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 606 | endif() |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 607 | else() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 608 | # Unix. |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 609 | execute_process( |
| 610 | 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] | 611 | COMMAND "${OPENSSL_EXECUTABLE}" |
| 612 | req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}" |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 613 | RESULT_VARIABLE OPENSSL_RETURN_CODE) |
| 614 | |
| 615 | if (OPENSSL_RETURN_CODE) |
| 616 | message(WARNING "!!! Failed to generate SSL certificate for Test Server!!!:\nOpenSSL return code = ${OPENSSL_RETURN_CODE}") |
| 617 | else() |
| 618 | message("SUCCSESFULLY generated SSL certificate") |
| 619 | endif() |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 620 | endif() |
| 621 | |
| 622 | list(APPEND TEST_SERVER_DATA |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 623 | "${TEST_SERVER_SSL_KEY}" |
| 624 | "${TEST_SERVER_SSL_CERT}") |
Joakim Soderberg | f272cb0 | 2013-02-13 09:29:26 +0800 | [diff] [blame] | 625 | endif() |
Joakim Soderberg | c7ed2be | 2013-02-22 09:28:17 +0800 | [diff] [blame] | 626 | |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 627 | add_custom_command(TARGET test-server |
| 628 | POST_BUILD |
| 629 | COMMAND "${CMAKE_COMMAND}" -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server") |
| 630 | |
Joakim Soderberg | c7ed2be | 2013-02-22 09:28:17 +0800 | [diff] [blame] | 631 | # Copy the file needed to run the server so that the test apps can |
| 632 | # reach them from their default output location |
| 633 | foreach (TEST_FILE ${TEST_SERVER_DATA}) |
Joakim Soderberg | 6596e4b | 2014-02-18 13:38:14 +0100 | [diff] [blame] | 634 | if (EXISTS ${TEST_FILE}) |
| 635 | add_custom_command(TARGET test-server |
| 636 | POST_BUILD |
| 637 | COMMAND "${CMAKE_COMMAND}" -E copy "${TEST_FILE}" "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM) |
| 638 | endif() |
Joakim Soderberg | c7ed2be | 2013-02-22 09:28:17 +0800 | [diff] [blame] | 639 | endforeach() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 640 | endif(NOT LWS_WITHOUT_SERVER) |
Joakim Söderberg | 68e8d73 | 2013-02-06 15:27:39 +0900 | [diff] [blame] | 641 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 642 | if (NOT LWS_WITHOUT_CLIENT) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 643 | # |
| 644 | # test-client |
| 645 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 646 | if (NOT LWS_WITHOUT_TEST_CLIENT) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 647 | create_test_app(test-client |
| 648 | "test-server/test-client.c" |
| 649 | "" |
| 650 | "") |
| 651 | endif() |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 652 | |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 653 | # |
| 654 | # test-fraggle |
| 655 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 656 | if (NOT LWS_WITHOUT_TEST_FRAGGLE) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 657 | create_test_app(test-fraggle |
| 658 | "test-server/test-fraggle.c" |
| 659 | "" |
| 660 | "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h") |
| 661 | endif() |
| 662 | |
| 663 | # |
| 664 | # test-ping |
| 665 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 666 | if (NOT LWS_WITHOUT_TEST_PING) |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 667 | create_test_app(test-ping |
| 668 | "test-server/test-ping.c" |
| 669 | "" |
| 670 | "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h") |
| 671 | endif() |
Andy Green | 27696f2 | 2013-03-10 08:09:25 +0800 | [diff] [blame] | 672 | # |
| 673 | # test-echo |
| 674 | # |
| 675 | if (NOT WITHOUT_TEST_ECHO) |
| 676 | create_test_app(test-echo |
| 677 | "test-server/test-echo.c" |
| 678 | "" |
| 679 | "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h") |
| 680 | endif() |
| 681 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 682 | endif(NOT LWS_WITHOUT_CLIENT) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 683 | |
| 684 | # |
| 685 | # Copy OpenSSL dlls to the output directory on Windows. |
| 686 | # (Otherwise we'll get an error when trying to run) |
| 687 | # |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 688 | if (WIN32 AND LWS_WITH_SSL AND NOT LWS_USE_CYASSL) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 689 | if(OPENSSL_BIN_FOUND) |
Joakim Soderberg | 20aedc8 | 2013-02-22 09:28:11 +0800 | [diff] [blame] | 690 | message("OpenSSL dlls found:") |
| 691 | message(" Libeay: ${LIBEAY_BIN}") |
| 692 | message(" SSLeay: ${SSLEAY_BIN}") |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 693 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 694 | foreach(TARGET_BIN ${TEST_APP_LIST}) |
Joakim Soderberg | 4c53123 | 2013-02-06 15:26:58 +0900 | [diff] [blame] | 695 | add_custom_command(TARGET ${TARGET_BIN} |
| 696 | POST_BUILD |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 697 | 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] | 698 | |
| 699 | add_custom_command(TARGET ${TARGET_BIN} |
| 700 | POST_BUILD |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 701 | 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] | 702 | endforeach() |
| 703 | endif() |
| 704 | endif() |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 705 | endif(NOT LWS_WITHOUT_TESTAPPS) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 706 | |
| 707 | if (UNIX) |
| 708 | # Generate documentation. |
| 709 | # TODO: Fix this on Windows. |
| 710 | message("Generating API documentation") |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 711 | file(GLOB C_FILES "${PROJECT_SOURCE_DIR}/lib/*.c") |
| 712 | 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] | 713 | |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 714 | execute_process( |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 715 | COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -html ${C_FILES} ${HDR_PUBLIC} |
| 716 | OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.html" |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 717 | ERROR_QUIET) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 718 | |
| 719 | execute_process( |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 720 | COMMAND "${PROJECT_SOURCE_DIR}/scripts/kernel-doc" -text ${C_FILES} ${HDR_PUBLIC} |
| 721 | OUTPUT_FILE "${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.txt" |
Joakim Soderberg | 7eadd58 | 2013-02-22 09:28:04 +0800 | [diff] [blame] | 722 | ERROR_QUIET) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 723 | |
| 724 | # Generate and install pkgconfig. |
| 725 | # (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] | 726 | file(WRITE "${PROJECT_BINARY_DIR}/libwebsockets.pc" |
Andy Green | 0f3e413 | 2014-02-27 07:28:45 +0800 | [diff] [blame] | 727 | "prefix=\"${CMAKE_INSTALL_PREFIX}\" |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 728 | exec_prefix=\${prefix} |
Andy Green | 975423c | 2013-02-26 11:58:45 +0800 | [diff] [blame] | 729 | libdir=\${exec_prefix}/lib${LIB_SUFFIX} |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 730 | includedir=\${prefix}/include |
| 731 | |
| 732 | Name: libwebsockets |
| 733 | Description: Websockets server and client library |
Andy Green | e919af8 | 2014-02-15 14:45:14 +0800 | [diff] [blame] | 734 | Version: ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR} |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 735 | |
| 736 | Libs: -L\${libdir} -lwebsockets |
| 737 | Cflags: -I\${includedir}" |
| 738 | ) |
| 739 | |
Markus Elfring | 299244f | 2013-10-26 20:03:43 +0800 | [diff] [blame] | 740 | install(FILES "${PROJECT_BINARY_DIR}/libwebsockets.pc" |
Andy Green | c8c1662 | 2013-03-10 08:10:19 +0800 | [diff] [blame] | 741 | DESTINATION lib${LIB_SUFFIX}/pkgconfig) |
Edwin van den Oetelaar | 15a38a7 | 2013-03-10 06:53:57 +0800 | [diff] [blame] | 742 | endif(UNIX) |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 743 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 744 | # |
| 745 | # Installation preparations. |
| 746 | # |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 747 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 748 | if(WIN32 AND NOT CYGWIN) |
| 749 | set(DEF_INSTALL_CMAKE_DIR cmake) |
| 750 | else() |
| 751 | set(DEF_INSTALL_CMAKE_DIR lib/cmake/libwebsockets) |
| 752 | endif() |
| 753 | |
| 754 | set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") |
| 755 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 756 | # Export targets (This is used for other CMake projects to easily find the libraries and include files). |
| 757 | export(TARGETS websockets websockets_shared |
| 758 | FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake") |
| 759 | export(PACKAGE libwebsockets) |
| 760 | |
| 761 | # Generate the config file for the build-tree. |
| 762 | set(LWS__INCLUDE_DIRS |
| 763 | "${PROJECT_SOURCE_DIR}/lib" |
| 764 | "${PROJECT_BINARY_DIR}") |
| 765 | set(LIBWEBSOCKETS_INCLUDE_DIRS ${LWS__INCLUDE_DIRS} CACHE PATH "Libwebsockets include directories") |
| 766 | configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in |
| 767 | ${PROJECT_BINARY_DIR}/LibwebsocketsConfig.cmake |
| 768 | @ONLY) |
| 769 | |
| 770 | # Generate the config file for the installation tree. |
Patrick Gansterer | e04ec35 | 2014-02-28 16:29:28 +0100 | [diff] [blame] | 771 | get_filename_component(LWS_ABSOLUTE_INSTALL_CMAKE_DIR ${LWS_INSTALL_CMAKE_DIR} ABSOLUTE) |
| 772 | 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] | 773 | file(RELATIVE_PATH |
| 774 | REL_INCLUDE_DIR |
Patrick Gansterer | e04ec35 | 2014-02-28 16:29:28 +0100 | [diff] [blame] | 775 | "${LWS_ABSOLUTE_INSTALL_CMAKE_DIR}" |
| 776 | "${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] | 777 | |
| 778 | # Note the EVENT_CMAKE_DIR is defined in JanssonConfig.cmake.in, |
| 779 | # we escape it here so it's evaluated when it is included instead |
| 780 | # so that the include dirs are given relative to where the |
| 781 | # config file is located. |
| 782 | set(LWS__INCLUDE_DIRS |
| 783 | "\${LWS_CMAKE_DIR}/${REL_INCLUDE_DIR}") |
| 784 | configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfig.cmake.in |
| 785 | ${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/LibwebsocketsConfig.cmake |
| 786 | @ONLY) |
| 787 | |
| 788 | # Generate version info for both build-tree and install-tree. |
| 789 | configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in |
| 790 | ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake |
| 791 | @ONLY) |
| 792 | |
| 793 | set_target_properties(websockets websockets_shared |
| 794 | PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}") |
| 795 | |
| 796 | # |
| 797 | # Installation. |
| 798 | # |
| 799 | |
| 800 | # Install libs and headers. |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 801 | install(TARGETS websockets websockets_shared |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 802 | EXPORT LibwebsocketsTargets |
| 803 | LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries |
| 804 | ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries |
| 805 | RUNTIME DESTINATION "${LWS_INSTALL_BIN_DIR}" COMPONENT libraries # Windows DLLs |
| 806 | PUBLIC_HEADER DESTINATION "${LWS_INSTALL_INCLUDE_DIR}" COMPONENT dev) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 807 | set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries") |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 808 | set(CPACK_COMPONENT_DEV_DISPLAY_NAME "Development files") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 809 | |
| 810 | # Install test apps. |
Andy Green | 7f54e76 | 2014-02-21 18:48:05 +0800 | [diff] [blame] | 811 | if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_CLIENT) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 812 | install(TARGETS test-client ${TEST_APP_LIST} |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 813 | RUNTIME DESTINATION ${LWS_INSTALL_EXAMPLES_DIR} |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 814 | COMPONENT examples) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 815 | set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example files") |
Joakim Söderberg | 6ac9709 | 2013-02-19 10:14:37 +0800 | [diff] [blame] | 816 | endif() |
| 817 | |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 818 | # Programs shared files used by the test-server. |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 819 | if (NOT LWS_WITHOUT_TESTAPPS AND NOT LWS_WITHOUT_SERVER) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 820 | install(FILES ${TEST_SERVER_DATA} |
| 821 | DESTINATION share/libwebsockets-test-server |
| 822 | COMPONENT examples) |
| 823 | endif() |
| 824 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 825 | # Install exports for the install-tree. |
| 826 | install(EXPORT LibwebsocketsTargets |
| 827 | DESTINATION "${LWS_INSTALL_CMAKE_DIR}" COMPONENT dev) |
| 828 | |
Andy Green | 2aab3f9 | 2013-03-10 08:11:48 +0800 | [diff] [blame] | 829 | # build subdir is not part of sources |
| 830 | set(CPACK_SOURCE_IGNORE_FILES $(CPACK_SOURCE_IGNORE_FILES) ".git" "build" "tgz" "tar.gz") |
| 831 | |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 832 | # 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] | 833 | add_custom_target(dist COMMAND "${CMAKE_MAKE_PROGRAM}" package_source) |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 834 | |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 835 | include(UseRPMTools) |
| 836 | if (RPMTools_FOUND) |
Tomas Cejka | efda177 | 2013-04-11 08:13:13 +0800 | [diff] [blame] | 837 | RPMTools_ADD_RPM_TARGETS(libwebsockets libwebsockets.spec) |
Joakim Soderberg | 6744555 | 2014-02-15 13:48:56 +0800 | [diff] [blame] | 838 | endif() |
| 839 | |
| 840 | message("---------------------------------------------------------------------") |
| 841 | message(" Settings: (For more help do cmake -LH <srcpath>") |
| 842 | message("---------------------------------------------------------------------") |
| 843 | message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)") |
| 844 | message(" LWS_USE_CYASSL = ${LWS_USE_CYASSL} (CyaSSL replacement for OpenSSL)") |
| 845 | if (LWS_USE_CYASSL) |
| 846 | message(" LWS_CYASSL_LIB = ${LWS_CYASSL_LIB}") |
| 847 | message(" LWS_CYASSL_INCLUDE_DIRS = ${LWS_CYASSL_INCLUDE_DIRS}") |
| 848 | endif() |
| 849 | message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}") |
| 850 | message(" LWS_WITHOUT_CLIENT = ${LWS_WITHOUT_CLIENT}") |
| 851 | message(" LWS_WITHOUT_SERVER = ${LWS_WITHOUT_SERVER}") |
| 852 | message(" LWS_LINK_TESTAPPS_DYNAMIC = ${LWS_LINK_TESTAPPS_DYNAMIC}") |
| 853 | message(" LWS_WITHOUT_TESTAPPS = ${LWS_WITHOUT_TESTAPPS}") |
| 854 | message(" LWS_WITHOUT_TEST_SERVER = ${LWS_WITHOUT_TEST_SERVER}") |
| 855 | message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}") |
| 856 | message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}") |
| 857 | message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}") |
| 858 | message(" LWS_WITHOUT_TEST_FRAGGLE = ${LWS_WITHOUT_TEST_FRAGGLE}") |
| 859 | message(" LWS_WITHOUT_DEBUG = ${LWS_WITHOUT_DEBUG}") |
| 860 | message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}") |
| 861 | message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}") |
| 862 | message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}") |
| 863 | message("---------------------------------------------------------------------") |
| 864 | |
| 865 | # These will be available to parent projects including libwebsockets using add_subdirectory() |
| 866 | set(LIBWEBSOCKETS_LIBRARIES websocket websockets_shared CACHE STRING "Libwebsocket libraries") |
| 867 | set(LIBWEBSOCKETS_LIBRARIES_STATIC websocket CACHE STRING "Libwebsocket static library") |
| 868 | set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library") |
Tomas Cejka | efda177 | 2013-04-11 08:13:13 +0800 | [diff] [blame] | 869 | |
Joakim Soderberg | b37827b | 2013-02-22 09:28:08 +0800 | [diff] [blame] | 870 | # This must always be last! |
| 871 | include(CPack) |