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