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