Fixed CMake compile options.
[profile/ivi/libwebsockets.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.6)
2
3 project(libwebsockets)
4
5 set(PACKAGE "libwebsockets")
6 set(PACKAGE_VERSION "1.2")
7 set(PACKAGE_BUGREPORT "andy@warmcat.com")
8 set(PACKAGE_NAME "${PACKAGE}")
9 set(PACKAGE_STRING "${PACKAGE} ${PACKAGE_VERSION}")
10 set(PACKAGE_TARNAME "${PACKAGE}")
11 set(PACKAGE_URL "http://libwebsockets.org")
12 set(VERSION "{PACKAGE_VERSION}")
13 set(SOVERSION "3.0.0")
14
15 set(LWS_LIBRARY_VERSION ${PACKAGE_VERSION})
16 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
17
18 # Try to find the current Git hash.
19 find_package(Git)
20 if(GIT_EXECUTABLE)
21         execute_process(
22     COMMAND "${GIT_EXECUTABLE}" log -n 1 --pretty=%h
23     OUTPUT_VARIABLE GIT_HASH
24     OUTPUT_STRIP_TRAILING_WHITESPACE
25     )
26
27     set(LWS_BUILD_HASH ${GIT_HASH})
28     message("Git commit hash: ${LWS_BUILD_HASH}")
29 endif()
30
31 option(WITH_SSL "Include SSL support (default OpenSSL, CyaSSL if USE_CYASSL is set)" ON)
32 option(USE_EXTERNAL_ZLIB "Search the system for ZLib instead of using the included one (on Windows)" OFF)
33 option(USE_CYASSL "Use CyaSSL replacement for OpenSSL. When settings this, you also need to specify CYASSL_LIB and CYASSL_INCLUDE_DIRS" OFF)
34 option(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)
35 option(WITHOUT_CLIENT "Don't build the client part of the library" OFF)
36 option(WITHOUT_SERVER "Don't build the server part of the library" OFF)
37 #option(WITH_LIBCRYPTO "Use libcrypto MD5 and SHA1 implementations" ON)
38 option(WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
39 option(WITHOUT_TEST_SERVER "Don't build the test server" OFF)
40 option(WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF)
41 option(WITHOUT_TEST_PING "Don't build the ping test application" OFF)
42 option(WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
43 option(WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF)
44 option(WITHOUT_DEBUG "Don't compile debug related code" OFF)
45 option(WITHOUT_EXTENSIONS "Don't compile with extensions" OFF)
46 option(WITH_LATENCY "Build latency measuring code into the library" OFF)
47 option(WITHOUT_DAEMONIZE "Don't build the daemonization api" OFF)
48
49 if (WITHOUT_CLIENT AND WITHOUT_SERVER)
50         message(FATAL_ERROR "Makes no sense to compile without both client or server.")
51 endif()
52
53 # The base dir where the SSL dirs should be looked for.
54 set(SSL_CERT_DIR CACHE STRING "")
55 set(SSL_CLIENT_CERT_DIR CACHE STRING "")
56
57 if ("${SSL_CERT_DIR}" STREQUAL "")
58         set(SSL_CERT_DIR "$ENV{DESTDIR}/usr/local/share")
59 endif()
60
61 if ("${SSL_CLIENT_CERT_DIR}" STREQUAL "")
62         if (WIN32)
63                 set(LWS_OPENSSL_CLIENT_CERTS ".")
64         else()
65                 set(LWS_OPENSSL_CLIENT_CERTS "/etc/pki/tls/certs/")
66         endif()
67 else()
68         set(LWS_OPENSSL_CLIENT_CERTS "${SSL_CLIENT_CERT_DIR}")
69 endif()
70
71 set(CYASSL_LIB CACHE STRING "")
72 set(CYASSL_INCLUDE_DIRS CACHE STRING "")
73
74 if (USE_CYASSL)
75         if ("${CYASSL_LIB}" STREQUAL "" OR "${CYASSL_INCLUDE_DIRS}" STREQUAL "")
76                 message(FATAL_ERROR "You must set CYASSL_LIB and CYASSL_INCLUDE_DIRS when USE_CYASSL is turned on")
77         endif()
78 endif()
79
80 if (WITHOUT_EXTENSIONS)
81         set(LWS_NO_EXTENSIONS 1)
82 endif()
83
84 if (WITH_SSL)
85         set(LWS_OPENSSL_SUPPORT 1)
86 endif()
87
88 if (WITH_LATENCY)
89         set(LWS_LATENCY 1)
90 endif()
91
92 if (WITHOUT_DAEMONIZE)
93         set(LWS_NO_DAEMONIZE 1)
94 endif()
95
96 if (WITHOUT_SERVER)
97         set(LWS_NO_SERVER 1)
98 endif()
99
100 if (WITHOUT_CLIENT)
101         set(LWS_NO_CLIENT 1)
102 endif()
103
104 if (MINGW)
105         set(LWS_MINGW_SUPPORT 1)
106 endif()
107
108 include_directories(${PROJECT_BINARY_DIR})
109
110 include(CheckCSourceCompiles)
111
112 # Check for different inline keyword versions.
113 foreach(KEYWORD "inline" "__inline__" "__inline")
114         set(CMAKE_REQUIRED_DEFINITIONS "-DKEYWORD=${KEYWORD}")
115         CHECK_C_SOURCE_COMPILES(
116                 "
117                 #include <stdio.h>
118                 KEYWORD void a() {}
119                 int main(int argc, char **argv) { a(); return 0; }
120                 " HAVE_${KEYWORD})
121 endforeach()
122
123 if (NOT HAVE_inline)
124         if (HAVE___inline__)
125                 set(inline __inline__)
126         elseif(HAVE___inline)
127                 set(inline __inline)
128         endif()
129 endif()
130
131 # Put the libaries and binaries that get built into directories at the
132 # top of the build tree rather than in hard-to-find leaf directories. 
133 SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
134 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
135 SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
136
137 # So we can include the CMake generated config file only when
138 # building with CMAKE.
139 add_definitions(-DCMAKE_BUILD)
140
141 include(CheckFunctionExists)
142 include(CheckIncludeFile)
143 include(CheckIncludeFiles)
144 include(CheckLibraryExists)
145
146 CHECK_FUNCTION_EXISTS(bzero HAVE_BZERO)
147 CHECK_FUNCTION_EXISTS(fork HAVE_FORK)
148 CHECK_FUNCTION_EXISTS(malloc HAVE_MALLOC)
149 CHECK_FUNCTION_EXISTS(memset HAVE_MEMSET)
150 CHECK_FUNCTION_EXISTS(realloc HAVE_REALLOC)
151 CHECK_FUNCTION_EXISTS(socket HAVE_SOCKET)
152 CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR)
153 CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK)
154 CHECK_FUNCTION_EXISTS(getifaddrs HAVE_GETIFADDRS)
155
156 if (NOT HAVE_GETIFADDRS)
157         if (WITHOUT_BUILTIN_GETIFADDRS)
158                 message(FATAL_ERROR "No getifaddrs was found on the system. Turn off the WITHOUT_BUILTIN_GETIFADDRS compile option to use the supplied BSD version.")
159         endif()
160
161         set(LWS_BUILTIN_GETIFADDRS 1)
162 endif()
163
164 CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H)
165 CHECK_INCLUDE_FILE(fcntl.h HAVE_FCNTL_H)
166 CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H)
167 CHECK_INCLUDE_FILE(memory.h HAVE_MEMORY_H)
168 CHECK_INCLUDE_FILE(netinet/in.h HAVE_NETINET_IN_H)
169 CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
170 CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H)
171 CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H)
172 CHECK_INCLUDE_FILE(string.h HAVE_STRING_H)
173 CHECK_INCLUDE_FILE(sys/prctl.h HAVE_SYS_PRCTL_H)
174 CHECK_INCLUDE_FILE(sys/socket.h HAVE_SYS_SOCKET_H)
175 CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H)
176 CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
177 CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
178 CHECK_INCLUDE_FILE(vfork.h HAVE_VFORK_H)
179 CHECK_INCLUDE_FILE(zlib.h HAVE_ZLIB_H)
180
181 # TODO: These can be tested if they actually work also...
182 set(HAVE_WORKING_FORK HAVE_FORK)
183 set(HAVE_WORKING_VFORK HAVE_VFORK)
184
185 CHECK_INCLUDE_FILES("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
186
187 if (NOT HAVE_SYS_TYPES_H)
188         set(pid_t int)
189         set(size_t "unsigned int")
190 endif()
191
192 if (NOT HAVE_MALLOC)
193         set(malloc rpl_malloc)
194 endif()
195
196 if (NOT HAVE_REALLOC)
197         set(realloc rpl_realloc)
198 endif()
199
200 # Generate the config.h that includes all the compilation settings.
201 configure_file(
202                 ${PROJECT_SOURCE_DIR}/config.h.cmake 
203                 ${PROJECT_BINARY_DIR}/lws_config.h)
204
205 if (MSVC)
206         # Turn off stupid microsoft security warnings.
207         add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
208 endif()
209
210 include_directories(${PROJECT_SOURCE_DIR}/lib)
211
212 # Group headers and sources.
213 # Some IDEs use this for nicer file structure.
214 set(HDR_PRIVATE
215         lib/private-libwebsockets.h
216         ${PROJECT_BINARY_DIR}/lws_config.h
217         )
218
219 set(HDR_PUBLIC  
220         ${PROJECT_SOURCE_DIR}/lib/libwebsockets.h
221         )
222
223 set(SOURCES
224         lib/base64-decode.c
225         lib/handshake.c
226         lib/libwebsockets.c
227         lib/output.c
228         lib/parsers.c
229         lib/sha-1.c
230         )
231
232 if (NOT WITHOUT_CLIENT)
233         list(APPEND SOURCES
234                 lib/client.c
235                 lib/client-handshake.c
236                 lib/client-parser.c
237                 )
238 endif()
239
240 if (NOT WITHOUT_SERVER)
241         list(APPEND SOURCES
242                 lib/server.c
243                 lib/server-handshake.c
244                 )
245 endif()
246
247 if (NOT WITHOUT_EXTENSIONS)
248         list(APPEND HDR_PRIVATE
249                 lib/extension-deflate-frame.h
250                 lib/extension-deflate-stream.h
251                 )
252
253         list(APPEND SOURCES
254                 lib/extension.c
255                 lib/extension-deflate-frame.c
256                 lib/extension-deflate-stream.c
257                 )
258 endif()
259
260 # Add helper files for Windows.
261 if (WIN32)
262         set(WIN32_HELPERS_PATH win32port/win32helpers)
263
264         list(APPEND HDR_PRIVATE
265                 ${WIN32_HELPERS_PATH}/websock-w32.h
266                 ${WIN32_HELPERS_PATH}/gettimeofday.h
267                 )
268
269         list(APPEND SOURCES 
270                 ${WIN32_HELPERS_PATH}/websock-w32.c
271                 ${WIN32_HELPERS_PATH}/gettimeofday.c
272                 )
273
274         include_directories(${WIN32_HELPERS_PATH})
275 else()
276         # Unix.
277         if (NOT WITHOUT_DAEMONIZE)
278                 list(APPEND SOURCES
279                         lib/daemonize.c
280                         )
281         endif()
282 endif()
283
284 if (UNIX)
285         if (NOT HAVE_GETIFADDRS)
286                 list(APPEND HDR_PRIVATE lib/getifaddrs.h)
287                 list(APPEND SOURCES lib/getifaddrs.c)
288         endif()
289 endif()
290
291 source_group("Headers Private"  FILES ${HDR_PRIVATE})
292 source_group("Headers Public"   FILES ${HDR_PUBLIC})
293 source_group("Sources"          FILES ${SOURCES})
294
295 #
296 # Create the lib.
297 #
298 add_library(websockets STATIC
299                         ${HDR_PRIVATE}
300                         ${HDR_PUBLIC}
301                         ${SOURCES})
302 add_library(websockets_shared SHARED
303                         ${HDR_PRIVATE}
304                         ${HDR_PUBLIC}
305                         ${SOURCES})
306
307 if (WIN32)
308         # On Windows libs have the same file ending (.lib)
309         # for both static and shared libraries, so we
310         # need a unique name for the static one.
311         set_target_properties(websockets 
312                 PROPERTIES
313                 OUTPUT_NAME websockets_static)
314
315         # Compile as DLL (export function declarations)
316         set_property(
317                 TARGET websockets_shared
318                 PROPERTY COMPILE_DEFINITIONS 
319                 LWS_DLL
320                 LWS_INTERNAL
321                 )
322 endif()
323
324 # We want the shared lib to be named "libwebsockets"
325 # not "libwebsocket_shared".
326 set_target_properties(websockets_shared
327                 PROPERTIES 
328                 OUTPUT_NAME websockets)
329
330 # Set the so version of the lib.
331 # Equivalent to LDFLAGS=-version-info 3:0:0
332 if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
333         foreach(lib websockets websockets_shared)
334                 set_target_properties(${lib} 
335                         PROPERTIES
336                         SOVERSION ${SOVERSION})
337         endforeach()
338 endif()
339
340 set(LIB_LIST)
341
342 #
343 # Find libraries.
344 #
345
346 #
347 # ZLIB (Only needed for deflate extensions).
348 #
349 if (NOT WITHOUT_EXTENSIONS)
350         if (WIN32 AND NOT USE_EXTERNAL_ZLIB)
351                 message("Using included Zlib version")
352
353                 # Compile ZLib if needed.
354                 set(WIN32_ZLIB_PATH "win32port/zlib")
355                 set(ZLIB_SRCS
356                         ${WIN32_ZLIB_PATH}/adler32.c
357                         ${WIN32_ZLIB_PATH}/compress.c
358                         ${WIN32_ZLIB_PATH}/crc32.c
359                         ${WIN32_ZLIB_PATH}/deflate.c
360                         ${WIN32_ZLIB_PATH}/gzclose.c
361                         ${WIN32_ZLIB_PATH}/gzio.c
362                         ${WIN32_ZLIB_PATH}/gzlib.c
363                         ${WIN32_ZLIB_PATH}/gzread.c
364                         ${WIN32_ZLIB_PATH}/gzwrite.c
365                         ${WIN32_ZLIB_PATH}/infback.c
366                         ${WIN32_ZLIB_PATH}/inffast.c
367                         ${WIN32_ZLIB_PATH}/inflate.c
368                         ${WIN32_ZLIB_PATH}/inftrees.c
369                         ${WIN32_ZLIB_PATH}/trees.c
370                         ${WIN32_ZLIB_PATH}/uncompr.c
371                         ${WIN32_ZLIB_PATH}/zutil.c
372                 )
373
374                 # Create the library.
375                 add_library(ZLIB STATIC ${ZLIB_SRCS})
376
377                 # Set the same variables as find_package would.
378                 set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
379                 get_property(ZLIB_LIBRARIES TARGET ZLIB PROPERTY LOCATION)
380                 set(ZLIB_FOUND 1)
381         else()
382                 find_package(ZLIB REQUIRED)
383         endif()
384
385         # Make sure ZLib is compiled before the libs.
386         foreach (lib websockets websockets_shared)
387                 add_dependencies(${lib} ZLIB)
388         endforeach()
389
390         message("ZLib include dirs: ${ZLIB_INCLUDE_DIRS}")
391         message("ZLib libraries: ${ZLIB_LIBRARIES}")
392         include_directories(${ZLIB_INCLUDE_DIRS})
393         list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
394 endif(NOT WITHOUT_EXTENSIONS)
395
396 #
397 # OpenSSL
398 #
399 if (WITH_SSL)
400         message("Compiling with SSL support")
401
402         if (USE_CYASSL)
403                 # Use CyaSSL as OpenSSL replacement.
404                 # TODO: Add a find_package command for this also.
405                 message("CyaSSL include dir: ${CYASSL_INCLUDE_DIRS}")
406                 message("CyaSSL libraries: ${CYASSL_LIB}")
407
408                 # Additional to the root directory we need to include
409                 # the cyassl/ subdirectory which contains the OpenSSL
410                 # compatability layer headers.
411                 foreach(inc ${CYASSL_INCLUDE_DIRS})
412                         include_directories(${inc} ${inc}/cyassl)
413                 endforeach()
414
415                 list(APPEND ${LIB_LIST} ${CYASSL_LIB})
416         else()
417                 # TODO: Add support for STATIC also.
418                 find_package(OpenSSL REQUIRED)
419
420                 message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
421                 message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
422
423                 include_directories(${OPENSSL_INCLUDE_DIR})
424                 list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
425         endif()
426 endif(WITH_SSL)
427
428 #
429 # Platform specific libs.
430 #
431 if (WIN32)
432         list(APPEND LIB_LIST ws2_32.lib)
433 endif()
434
435 if (UNIX)
436         list(APPEND LIB_LIST m)
437 endif()
438
439 # Setup the linking for all libs.
440 foreach (lib websockets websockets_shared)
441         target_link_libraries(${lib} ${LIB_LIST})
442 endforeach()
443
444 #
445 # Test applications
446 #
447 set(TEST_APP_LIST)
448 if (NOT WITHOUT_TESTAPPS)
449         #
450         # Helper function for adding a test app.
451         #
452         function(create_test_app TEST_NAME MAIN_SRC WIN32_SRCS WIN32_HDRS)
453                 
454                 set(TEST_SRCS ${MAIN_SRC})
455                 set(TEST_HDR)
456
457                 if (WIN32)
458                         list(APPEND TEST_SRCS 
459                                 ${WIN32_HELPERS_PATH}/getopt.c
460                                 ${WIN32_HELPERS_PATH}/getopt_long.c
461                                 ${WIN32_HELPERS_PATH}/gettimeofday.c
462                                 ${WIN32_SRCS})
463
464                         list(APPEND TEST_HDR 
465                                 ${WIN32_HELPERS_PATH}/getopt.h
466                                 ${WIN32_HELPERS_PATH}/gettimeofday.h
467                                 ${WIN32_HDRS})
468                 endif(WIN32)
469
470                 source_group("Headers Private"   FILES ${TEST_HDR})
471                 source_group("Sources"   FILES ${TEST_SRCS})
472                 add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
473                 target_link_libraries(${TEST_NAME} websockets)
474                 add_dependencies(${TEST_NAME} websockets)
475                 
476                 # Set test app specific defines.
477                 set_property(TARGET ${TEST_NAME}
478                                         PROPERTY COMPILE_DEFINITIONS 
479                                                 INSTALL_DATADIR="${SSL_CERT_DIR}"
480                                         )
481
482                 # Prefix the binary names with libwebsockets.
483                 set_target_properties(${TEST_NAME} 
484                         PROPERTIES
485                         OUTPUT_NAME libwebsockets-${TEST_NAME})
486
487                 # Add to the list of tests.
488                 list(APPEND TEST_APP_LIST ${TEST_NAME})
489         endfunction()
490
491         if (WITH_SSL AND NOT USE_CYASSL)
492                 message("Searching for OpenSSL executable and dlls")
493                 find_package(OpenSSLbins)
494                 message("OpenSSL executable: ${OPENSSL_EXECUTABLE}")
495         endif()
496
497         if (NOT WITHOUT_SERVER)
498                 #
499                 # test-server
500                 #
501                 if (NOT WITHOUT_TEST_SERVER)
502                         create_test_app(test-server
503                                 "test-server/test-server.c"
504                                 ""
505                                 "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h")
506                 endif()
507
508                 #
509                 # test-server-extpoll
510                 #
511                 if (NOT WITHOUT_TEST_SERVER_EXTPOLL)
512                         create_test_app(test-server-extpoll
513                                 "test-server/test-server.c"
514                                 "win32port/win32helpers/websock-w32.c"
515                                 "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h")
516                         # Set defines for this executable only.
517                         set_property(
518                                 TARGET test-server-extpoll
519                                 PROPERTY COMPILE_DEFINITIONS 
520                                         EXTERNAL_POLL 
521                                         INSTALL_DATADIR="${SSL_CERT_DIR}"
522                                 )
523
524                         # We need to link against winsock code.
525                         if (WIN32)
526                                 target_link_libraries(test-server-extpoll ws2_32.lib)
527                         endif()
528                 endif()
529
530                 # Data files for running the test server.
531                 set(TEST_SERVER_DATA
532                         test-server/favicon.ico 
533                         test-server/leaf.jpg
534                         test-server/libwebsockets.org-logo.png
535                         test-server/test.html)
536
537                 # Generate self-signed SSL certs for the test-server.
538                 if (WITH_SSL AND OPENSSL_EXECUTABLE)
539                 
540                         set(TEST_SERVER_SSL_KEY ${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem)
541                         set(TEST_SERVER_SSL_CERT ${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem)
542
543                         if (WIN32)
544                                 file(WRITE ${PROJECT_BINARY_DIR}/openssl_input.txt
545                                         "GB\n"
546                                         "Erewhon\n"
547                                         "All around\n"
548                                         "libwebsockets-test\n"
549                                         "localhost\n"
550                                         "none@invalid.org\n"
551                                         )
552
553                                 execute_process(
554                                         COMMAND type ${PROJECT_BINARY_DIR}/openssl_input.txt
555                                         COMMAND ${OPENSSL_EXECUTABLE} req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout ${TEST_SERVER_SSL_KEY} -out ${TEST_SERVER_SSL_CERT}
556                                         )
557                         else()
558                                 execute_process(
559                                         COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n"
560                                         COMMAND ${OPENSSL_EXECUTABLE} 
561                                                 req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout ${TEST_SERVER_SSL_KEY} -out ${TEST_SERVER_SSL_CERT}
562                                         )
563                         endif()
564
565                         list(APPEND TEST_SERVER_DATA 
566                                 ${TEST_SERVER_SSL_KEY} 
567                                 ${TEST_SERVER_SSL_CERT})
568                 endif()
569         endif(NOT WITHOUT_SERVER)
570
571         if (NOT WITHOUT_CLIENT)
572                 #
573                 # test-client
574                 #
575                 if (NOT WITHOUT_TEST_CLIENT)
576                         create_test_app(test-client
577                                 "test-server/test-client.c"
578                                 ""
579                                 "")
580                 endif()
581
582                 #
583                 # test-fraggle
584                 #
585                 if (NOT WITHOUT_TEST_FRAGGLE)
586                         create_test_app(test-fraggle
587                                 "test-server/test-fraggle.c"
588                                 ""
589                                 "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
590                 endif()
591
592                 #
593                 # test-ping
594                 #
595                 if (NOT WITHOUT_TEST_PING)
596                         create_test_app(test-ping
597                                 "test-server/test-ping.c"
598                                 ""
599                                 "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
600                 endif()
601         endif(NOT WITHOUT_CLIENT)
602
603         #
604         # Copy OpenSSL dlls to the output directory on Windows.
605         # (Otherwise we'll get an error when trying to run)
606         #
607         if (WIN32 AND WITH_SSL AND NOT USE_CYASSL)
608                 if(OPENSSL_BIN_FOUND)
609                         message("OpenSSL dlls found, copying to output directory")
610                         message("Libeay: ${LIBEAY_BIN}")
611                         message("SSLeay: ${SSLEAY_BIN}")
612
613                         foreach(TARGET_BIN ${TEST_APP_LIST})                    
614                                 add_custom_command(TARGET ${TARGET_BIN}
615                                         POST_BUILD 
616                                         COMMAND ${CMAKE_COMMAND} -E copy ${LIBEAY_BIN} $<TARGET_FILE_DIR:${TARGET_BIN}> VERBATIM)
617                                         
618                                 add_custom_command(TARGET ${TARGET_BIN}
619                                         POST_BUILD 
620                                         COMMAND ${CMAKE_COMMAND} -E copy ${SSLEAY_BIN} $<TARGET_FILE_DIR:${TARGET_BIN}> VERBATIM)
621                         endforeach()
622                 endif()
623         endif()
624 endif(NOT WITHOUT_TESTAPPS)
625
626 if (UNIX)
627         # Generate documentation.
628         # TODO: Fix this on Windows.
629         message("Generating API documentation")
630         file(GLOB C_FILES ${PROJECT_SOURCE_DIR}/lib/*.c)
631         execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/doc/)
632
633         execute_process(
634                 COMMAND ${PROJECT_SOURCE_DIR}/scripts/kernel-doc -html ${C_FILES} ${HDR_PUBLIC} 
635                 OUTPUT_FILE ${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.html
636                 ERROR_QUIET)
637
638         execute_process(
639                 COMMAND ${PROJECT_SOURCE_DIR}/scripts/kernel-doc -text ${C_FILES} ${HDR_PUBLIC}
640                 OUTPUT_FILE ${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.txt
641                 ERROR_QUIET)
642
643 # Generate and install pkgconfig.
644 # (This is not indented, because the tabs will be part of the output)
645 file(WRITE ${PROJECT_BINARY_DIR}/libwebsockets.pc
646 "prefix=/usr/local
647 exec_prefix=\${prefix}
648 libdir=\${exec_prefix}/lib
649 includedir=\${prefix}/include
650
651 Name: libwebsockets
652 Description: Websockets server and client library
653 Version: ${PACKAGE_VERSION}
654
655 Libs: -L\${libdir} -lwebsockets
656 Cflags: -I\${includedir}"
657 )
658
659         install(FILES ${PROJECT_BINARY_DIR}/libwebsockets.pc
660                 DESTINATION /usr/local/include/pkgconfig)
661 endif()
662
663 # Install headers.
664 install(FILES ${HDR_PUBLIC} 
665                 DESTINATION /usr/local/include)
666
667 # Install libs.
668 install(TARGETS websockets websockets_shared
669                 LIBRARY DESTINATION /usr/local/lib
670                 ARCHIVE DESTINATION /usr/local/lib)
671
672 # Install test apps.
673 install(TARGETS ${TEST_APP_LIST}
674                 RUNTIME DESTINATION /usr/local/bin)
675
676 # Install shared files used by the test-server.
677 if (NOT WITHOUT_TESTAPPS AND NOT WITHOUT_SERVER)
678         install(FILES ${TEST_SERVER_DATA}
679                         DESTINATION /usr/local/share/libwebsockets-test-server)
680 endif()
681