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