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