project(libwebsockets)
set(PACKAGE "libwebsockets")
-set(PACKAGE_VERSION "1.2")
-set(PACKAGE_BUGREPORT "andy@warmcat.com")
-set(PACKAGE_NAME "${PACKAGE}")
-set(PACKAGE_STRING "${PACKAGE} ${PACKAGE_VERSION}")
-set(PACKAGE_TARNAME "${PACKAGE}")
-set(PACKAGE_URL "http://libwebsockets.org")
-set(VERSION "{PACKAGE_VERSION}")
+set(CPACK_PACKAGE_NAME "${PACKAGE}")
+set(CPACK_PACKAGE_VERSION_MAJOR "1")
+set(CPACK_PACKAGE_VERSION_MINOR "2")
+set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
+set(CPACK_PACKAGE_VENDOR "andy@warmcat.com")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}")
set(SOVERSION "3.0.0")
+set(CPACK_SOURCE_GENERATOR "TGZ")
+set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
+set(VERSION "${CPACK_PACKAGE_VERSION}")
-set(LWS_LIBRARY_VERSION ${PACKAGE_VERSION})
+set(LWS_LIBRARY_VERSION ${CPACK_PACKAGE_VERSION})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
# Try to find the current Git hash.
option(WITH_SSL "Include SSL support (default OpenSSL, CyaSSL if USE_CYASSL is set)" ON)
option(USE_EXTERNAL_ZLIB "Search the system for ZLib instead of using the included one (on Windows)" OFF)
option(USE_CYASSL "Use CyaSSL replacement for OpenSSL. When settings this, you also need to specify CYASSL_LIB and CYASSL_INCLUDE_DIRS" OFF)
-option(WITH_BUILTIN_GETIFADDRS "Use BSD getifaddrs implementation from libwebsockets... default is your libc provides it" OFF)
-option(WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
+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)
option(WITHOUT_CLIENT "Don't build the client part of the library" OFF)
option(WITHOUT_SERVER "Don't build the server part of the library" OFF)
-option(WITHOUT_SERVER_EXTPOLL "Don't build a server version that uses external poll" OFF)
-option(WITH_LIBCRYPTO "Use libcrypto MD5 and SHA1 implementations" ON)
-option(WITHOUT_PING "Don't build the ping test application" OFF)
+#option(WITH_LIBCRYPTO "Use libcrypto MD5 and SHA1 implementations" ON)
+option(LINK_TESTAPPS_DYNAMIC "Link the test apps to the shared version of the library. Default is to link statically" OFF)
+option(WITHOUT_TESTAPPS "Don't build the libwebsocket-test-apps" OFF)
+option(WITHOUT_TEST_SERVER "Don't build the test server" OFF)
+option(WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that uses external poll" OFF)
+option(WITHOUT_TEST_PING "Don't build the ping test application" OFF)
+option(WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
+option(WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF)
option(WITHOUT_DEBUG "Don't compile debug related code" OFF)
option(WITHOUT_EXTENSIONS "Don't compile with extensions" OFF)
option(WITH_LATENCY "Build latency measuring code into the library" OFF)
option(WITHOUT_DAEMONIZE "Don't build the daemonization api" OFF)
+option(WITH_SD_DAEMON "Build support for systemd based socket activation" OFF)
+
+if (WITHOUT_CLIENT AND WITHOUT_SERVER)
+ message(FATAL_ERROR "Makes no sense to compile without both client or server.")
+endif()
-# The base dir where the SSL dirs should be looked for.
+# The base dir where the test-apps look for the SSL certs.
set(SSL_CERT_DIR CACHE STRING "")
set(SSL_CLIENT_CERT_DIR CACHE STRING "")
if ("${SSL_CERT_DIR}" STREQUAL "")
- set(SSL_CERT_DIR ".")
+ set(SSL_CERT_DIR "../share")
endif()
if ("${SSL_CLIENT_CERT_DIR}" STREQUAL "")
- set(LWS_OPENSSL_CLIENT_CERTS ".")
+ if (WIN32)
+ set(LWS_OPENSSL_CLIENT_CERTS ".")
+ else()
+ set(LWS_OPENSSL_CLIENT_CERTS "/etc/pki/tls/certs/")
+ endif()
else()
set(LWS_OPENSSL_CLIENT_CERTS "${SSL_CLIENT_CERT_DIR}")
endif()
set(LWS_NO_CLIENT 1)
endif()
+if (WITHOUT_DEBUG)
+ set(_DEBUG 0)
+else()
+ set(_DEBUG 1)
+endif()
+
if (MINGW)
set(LWS_MINGW_SUPPORT 1)
endif()
CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK)
CHECK_FUNCTION_EXISTS(getifaddrs HAVE_GETIFADDRS)
-if (WITH_BUILTIN_GETIFADDRS)
- if (HAVE_GETIFADDRS)
- 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)")
+if (NOT HAVE_GETIFADDRS)
+ if (WITHOUT_BUILTIN_GETIFADDRS)
+ message(FATAL_ERROR "No getifaddrs was found on the system. Turn off the WITHOUT_BUILTIN_GETIFADDRS compile option to use the supplied BSD version.")
endif()
+
set(LWS_BUILTIN_GETIFADDRS 1)
endif()
# Some IDEs use this for nicer file structure.
set(HDR_PRIVATE
lib/private-libwebsockets.h
- lib/extension-deflate-frame.h
- lib/extension-deflate-stream.h
${PROJECT_BINARY_DIR}/lws_config.h
)
set(HDR_PUBLIC
- lib/libwebsockets.h
+ ${PROJECT_SOURCE_DIR}/lib/libwebsockets.h
)
set(SOURCES
lib/base64-decode.c
- lib/client.c
- lib/client-handshake.c
- lib/client-parser.c
- lib/extension.c
- lib/extension-deflate-frame.c
- lib/extension-deflate-stream.c
lib/handshake.c
lib/libwebsockets.c
lib/output.c
lib/parsers.c
- lib/server.c
- lib/server-handshake.c
lib/sha-1.c
)
+if (NOT WITHOUT_CLIENT)
+ list(APPEND SOURCES
+ lib/client.c
+ lib/client-handshake.c
+ lib/client-parser.c
+ )
+endif()
+
+if (NOT WITHOUT_SERVER)
+ list(APPEND SOURCES
+ lib/server.c
+ lib/server-handshake.c
+ )
+endif()
+
+if (NOT WITHOUT_EXTENSIONS)
+ list(APPEND HDR_PRIVATE
+ lib/extension-deflate-frame.h
+ lib/extension-deflate-stream.h
+ )
+
+ list(APPEND SOURCES
+ lib/extension.c
+ lib/extension-deflate-frame.c
+ lib/extension-deflate-stream.c
+ )
+endif()
+
# Add helper files for Windows.
if (WIN32)
set(WIN32_HELPERS_PATH win32port/win32helpers)
${WIN32_HELPERS_PATH}/websock-w32.h
${WIN32_HELPERS_PATH}/gettimeofday.h
)
-
+if (MINGW)
+ list(APPEND SOURCES
+ ${WIN32_HELPERS_PATH}/gettimeofday.c
+ )
+else()
list(APPEND SOURCES
${WIN32_HELPERS_PATH}/websock-w32.c
${WIN32_HELPERS_PATH}/gettimeofday.c
)
-
+endif()
include_directories(${WIN32_HELPERS_PATH})
else()
# Unix.
endif()
if (UNIX)
- if (!WITH_BUILTIN_GETIFADDRS)
+ if (NOT HAVE_GETIFADDRS)
list(APPEND HDR_PRIVATE lib/getifaddrs.h)
list(APPEND SOURCES lib/getifaddrs.c)
endif()
#
#
-# ZLIB.
+# SD_DAEMON (Only needed if systemd socket activation is desired.)
#
-if (WIN32 AND NOT USE_EXTERNAL_ZLIB)
- message("Using included Zlib version")
-
- # Compile ZLib if needed.
- set(WIN32_ZLIB_PATH "win32port/zlib")
- set(ZLIB_SRCS
- ${WIN32_ZLIB_PATH}/adler32.c
- ${WIN32_ZLIB_PATH}/compress.c
- ${WIN32_ZLIB_PATH}/crc32.c
- ${WIN32_ZLIB_PATH}/deflate.c
- ${WIN32_ZLIB_PATH}/gzclose.c
- ${WIN32_ZLIB_PATH}/gzio.c
- ${WIN32_ZLIB_PATH}/gzlib.c
- ${WIN32_ZLIB_PATH}/gzread.c
- ${WIN32_ZLIB_PATH}/gzwrite.c
- ${WIN32_ZLIB_PATH}/infback.c
- ${WIN32_ZLIB_PATH}/inffast.c
- ${WIN32_ZLIB_PATH}/inflate.c
- ${WIN32_ZLIB_PATH}/inftrees.c
- ${WIN32_ZLIB_PATH}/trees.c
- ${WIN32_ZLIB_PATH}/uncompr.c
- ${WIN32_ZLIB_PATH}/zutil.c
- )
+if (WITH_SD_DAEMON)
+ find_package(PkgConfig)
+ pkg_check_modules(SD_DAEMON REQUIRED libsystemd-daemon)
+
+ include_directories(${SD_DAEMON_INCLUDE_DIRS})
+ list(APPEND LIB_LIST ${SD_DAEMON_LIBRARIES})
+ add_definitions(${SD_DAEMON_CFLAGS_OTHER})
+ add_definitions(-DHAVE_SYSTEMD_DAEMON)
+endif()
- # Create the library.
- add_library(ZLIB STATIC ${ZLIB_SRCS})
+#
+# ZLIB (Only needed for deflate extensions).
+#
+if (NOT WITHOUT_EXTENSIONS)
+ if (WIN32 AND NOT USE_EXTERNAL_ZLIB)
+ message("Using included Zlib version")
+
+ # Compile ZLib if needed.
+ set(WIN32_ZLIB_PATH "win32port/zlib")
+ set(ZLIB_SRCS
+ ${WIN32_ZLIB_PATH}/adler32.c
+ ${WIN32_ZLIB_PATH}/compress.c
+ ${WIN32_ZLIB_PATH}/crc32.c
+ ${WIN32_ZLIB_PATH}/deflate.c
+ ${WIN32_ZLIB_PATH}/gzclose.c
+ ${WIN32_ZLIB_PATH}/gzio.c
+ ${WIN32_ZLIB_PATH}/gzlib.c
+ ${WIN32_ZLIB_PATH}/gzread.c
+ ${WIN32_ZLIB_PATH}/gzwrite.c
+ ${WIN32_ZLIB_PATH}/infback.c
+ ${WIN32_ZLIB_PATH}/inffast.c
+ ${WIN32_ZLIB_PATH}/inflate.c
+ ${WIN32_ZLIB_PATH}/inftrees.c
+ ${WIN32_ZLIB_PATH}/trees.c
+ ${WIN32_ZLIB_PATH}/uncompr.c
+ ${WIN32_ZLIB_PATH}/zutil.c
+ )
- # Set the same variables as find_package would.
- set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
- get_property(ZLIB_LIBRARIES TARGET ZLIB PROPERTY LOCATION)
- set(ZLIB_FOUND 1)
-else()
- find_package(ZLIB REQUIRED)
-endif()
+ # Create the library.
+ add_library(ZLIB STATIC ${ZLIB_SRCS})
-# Make sure ZLib is compiled before the libs.
-foreach (lib websockets websockets_shared)
- add_dependencies(${lib} ZLIB)
-endforeach()
+ # Set the same variables as find_package would.
+ set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
+ get_property(ZLIB_LIBRARIES TARGET ZLIB PROPERTY LOCATION)
+ set(ZLIB_FOUND 1)
+ else()
+ find_package(ZLIB REQUIRED)
+ endif()
-message("ZLib include dirs: ${ZLIB_INCLUDE_DIRS}")
-message("ZLib libraries: ${ZLIB_LIBRARIES}")
-include_directories(${ZLIB_INCLUDE_DIRS})
-list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
+ # Make sure ZLib is compiled before the libs.
+ foreach (lib websockets websockets_shared)
+ add_dependencies(${lib} ZLIB)
+ endforeach()
+
+ message("ZLib include dirs: ${ZLIB_INCLUDE_DIRS}")
+ message("ZLib libraries: ${ZLIB_LIBRARIES}")
+ include_directories(${ZLIB_INCLUDE_DIRS})
+ list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
+endif(NOT WITHOUT_EXTENSIONS)
#
# OpenSSL
#
# Test applications
#
+set(TEST_APP_LIST)
if (NOT WITHOUT_TESTAPPS)
#
# Helper function for adding a test app.
#
- function(create_test_app TEST_NAME MAIN_SRC WIN32_SRCS WIN32_HDRS)
+ macro(create_test_app TEST_NAME MAIN_SRC WIN32_SRCS WIN32_HDRS)
set(TEST_SRCS ${MAIN_SRC})
set(TEST_HDR)
source_group("Headers Private" FILES ${TEST_HDR})
source_group("Sources" FILES ${TEST_SRCS})
add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
- target_link_libraries(${TEST_NAME} websockets)
- add_dependencies(${TEST_NAME} websockets)
- set_property(
- TARGET ${TEST_NAME}
+
+ if (LINK_TESTAPPS_DYNAMIC)
+ target_link_libraries(${TEST_NAME} websockets_shared)
+ add_dependencies(${TEST_NAME} websockets_shared)
+ else()
+ target_link_libraries(${TEST_NAME} websockets)
+ add_dependencies(${TEST_NAME} websockets)
+ endif()
+
+ # Set test app specific defines.
+ set_property(TARGET ${TEST_NAME}
PROPERTY COMPILE_DEFINITIONS
INSTALL_DATADIR="${SSL_CERT_DIR}"
)
- endfunction()
- #
- # test-client
- #
- if (NOT WITHOUT_CLIENT)
- create_test_app(test-client
- "test-server/test-client.c"
- ""
- "")
+ # Prefix the binary names with libwebsockets.
+ set_target_properties(${TEST_NAME}
+ PROPERTIES
+ OUTPUT_NAME libwebsockets-${TEST_NAME})
+
+ # Add to the list of tests.
+ list(APPEND TEST_APP_LIST ${TEST_NAME})
+ endmacro()
+
+ if (WITH_SSL AND NOT USE_CYASSL)
+ message("Searching for OpenSSL executable and dlls")
+ find_package(OpenSSLbins)
+ message("OpenSSL executable: ${OPENSSL_EXECUTABLE}")
endif()
- #
- # test-server
- #
if (NOT WITHOUT_SERVER)
- create_test_app(test-server
- "test-server/test-server.c"
- ""
- "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h")
- endif()
+ #
+ # test-server
+ #
+ if (NOT WITHOUT_TEST_SERVER)
+ create_test_app(test-server
+ "test-server/test-server.c"
+ ""
+ "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h")
+ endif()
- #
- # test-server-extpoll
- #
- if (NOT WITHOUT_SERVER AND NOT WITHOUT_SERVER_EXTPOLL)
- create_test_app(test-server-extpoll
- "test-server/test-server.c"
- "win32port/win32helpers/websock-w32.c"
- "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h")
-
- # Set defines for this executable only.
- set_property(
- TARGET test-server-extpoll
- PROPERTY COMPILE_DEFINITIONS
- EXTERNAL_POLL
- INSTALL_DATADIR="${SSL_CERT_DIR}"
- )
+ #
+ # test-server-extpoll
+ #
+ if (NOT WITHOUT_TEST_SERVER_EXTPOLL)
+ create_test_app(test-server-extpoll
+ "test-server/test-server.c"
+ "win32port/win32helpers/websock-w32.c"
+ "${WIN32_HELPERS_PATH}/netdb.h;${WIN32_HELPERS_PATH}/strings.h;${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/websock-w32.h")
+ # Set defines for this executable only.
+ set_property(
+ TARGET test-server-extpoll
+ PROPERTY COMPILE_DEFINITIONS
+ EXTERNAL_POLL
+ INSTALL_DATADIR="${SSL_CERT_DIR}"
+ )
+
+ # We need to link against winsock code.
+ if (WIN32)
+ target_link_libraries(test-server-extpoll ws2_32.lib)
+ endif()
+ endif()
- # We need to link against winsock code.
- if (WIN32)
- target_link_libraries(test-server-extpoll ws2_32.lib)
+ # Data files for running the test server.
+ set(TEST_SERVER_DATA
+ ${PROJECT_SOURCE_DIR}/test-server/favicon.ico
+ ${PROJECT_SOURCE_DIR}/test-server/leaf.jpg
+ ${PROJECT_SOURCE_DIR}/test-server/libwebsockets.org-logo.png
+ ${PROJECT_SOURCE_DIR}/test-server/test.html)
+
+ # Generate self-signed SSL certs for the test-server.
+ if (WITH_SSL AND OPENSSL_EXECUTABLE)
+ message("Generating SSL Certificates for the test-server...")
+
+ set(TEST_SERVER_SSL_KEY ${PROJECT_BINARY_DIR}/libwebsockets-test-server.key.pem)
+ set(TEST_SERVER_SSL_CERT ${PROJECT_BINARY_DIR}/libwebsockets-test-server.pem)
+
+ if (WIN32)
+ file(WRITE ${PROJECT_BINARY_DIR}/openssl_input.txt
+ "GB\n"
+ "Erewhon\n"
+ "All around\n"
+ "libwebsockets-test\n"
+ "localhost\n"
+ "none@invalid.org\n\n"
+ )
+
+ # The "type" command is a bit picky with paths.
+ file(TO_NATIVE_PATH "${PROJECT_BINARY_DIR}/openssl_input.txt" OPENSSL_INPUT_WIN_PATH)
+
+ execute_process(
+ COMMAND cmd /c type "${OPENSSL_INPUT_WIN_PATH}"
+ COMMAND "${OPENSSL_EXECUTABLE}" req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout "${TEST_SERVER_SSL_KEY}" -out "${TEST_SERVER_SSL_CERT}"
+ RESULT_VARIABLE OPENSSL_RETURN_CODE)
+
+ message("\n")
+
+ if (OPENSSL_RETURN_CODE)
+ message("!!! Failed to generate SSL certificate:\n${OPENSSL_RETURN_CODE} !!!")
+ endif()
+ else()
+ execute_process(
+ COMMAND printf "GB\\nErewhon\\nAll around\\nlibwebsockets-test\\n\\nlocalhost\\nnone@invalid.org\\n"
+ COMMAND ${OPENSSL_EXECUTABLE}
+ req -new -newkey rsa:1024 -days 10000 -nodes -x509 -keyout ${TEST_SERVER_SSL_KEY} -out ${TEST_SERVER_SSL_CERT}
+ )
+ endif()
+
+ list(APPEND TEST_SERVER_DATA
+ ${TEST_SERVER_SSL_KEY}
+ ${TEST_SERVER_SSL_CERT})
endif()
- endif()
- #
- # test-fraggle
- #
- if (NOT WITHOUT_FRAGGLE)
- create_test_app(test-fraggle
- "test-server/test-fraggle.c"
- ""
- "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
- endif()
+ # Copy the file needed to run the server so that the test apps can
+ # reach them from their default output location
+ foreach (TEST_FILE ${TEST_SERVER_DATA})
+ add_custom_command(TARGET test-server
+ POST_BUILD
+ COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server"
+ COMMAND ${CMAKE_COMMAND} -E copy ${TEST_FILE} "$<TARGET_FILE_DIR:test-server>/../share/libwebsockets-test-server" VERBATIM)
+ endforeach()
+ endif(NOT WITHOUT_SERVER)
- #
- # test-ping
- #
- if (NOT WITHOUT_PING)
- create_test_app(test-ping
- "test-server/test-ping.c"
- ""
- "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
- endif()
+ if (NOT WITHOUT_CLIENT)
+ #
+ # test-client
+ #
+ if (NOT WITHOUT_TEST_CLIENT)
+ create_test_app(test-client
+ "test-server/test-client.c"
+ ""
+ "")
+ endif()
+
+ #
+ # test-fraggle
+ #
+ if (NOT WITHOUT_TEST_FRAGGLE)
+ create_test_app(test-fraggle
+ "test-server/test-fraggle.c"
+ ""
+ "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
+ endif()
+
+ #
+ # test-ping
+ #
+ if (NOT WITHOUT_TEST_PING)
+ create_test_app(test-ping
+ "test-server/test-ping.c"
+ ""
+ "${WIN32_HELPERS_PATH}/unistd.h;${WIN32_HELPERS_PATH}/sys/time.h")
+ endif()
+ endif(NOT WITHOUT_CLIENT)
#
# Copy OpenSSL dlls to the output directory on Windows.
# (Otherwise we'll get an error when trying to run)
#
if (WIN32 AND WITH_SSL AND NOT USE_CYASSL)
-
- message("Searching for OpenSSL dlls")
- find_package(OpenSSLbins)
-
if(OPENSSL_BIN_FOUND)
- message("OpenSSL dlls found, copying to output directory")
- message("Libeay: ${LIBEAY_BIN}")
- message("SSLeay: ${SSLEAY_BIN}")
-
- foreach(TARGET_BIN
- test-client
- test-server
- test-server-extpoll
- test-fraggle
- test-echo
- test-ping
- )
+ message("OpenSSL dlls found:")
+ message(" Libeay: ${LIBEAY_BIN}")
+ message(" SSLeay: ${SSLEAY_BIN}")
+
+ foreach(TARGET_BIN ${TEST_APP_LIST})
add_custom_command(TARGET ${TARGET_BIN}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${LIBEAY_BIN} $<TARGET_FILE_DIR:${TARGET_BIN}> VERBATIM)
endif()
endif()
endif(NOT WITHOUT_TESTAPPS)
+
+if (UNIX)
+ # Generate documentation.
+ # TODO: Fix this on Windows.
+ message("Generating API documentation")
+ file(GLOB C_FILES ${PROJECT_SOURCE_DIR}/lib/*.c)
+ execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/doc/)
+
+ execute_process(
+ COMMAND ${PROJECT_SOURCE_DIR}/scripts/kernel-doc -html ${C_FILES} ${HDR_PUBLIC}
+ OUTPUT_FILE ${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.html
+ ERROR_QUIET)
+
+ execute_process(
+ COMMAND ${PROJECT_SOURCE_DIR}/scripts/kernel-doc -text ${C_FILES} ${HDR_PUBLIC}
+ OUTPUT_FILE ${PROJECT_BINARY_DIR}/doc/libwebsockets-api-doc.txt
+ ERROR_QUIET)
+
+# Generate and install pkgconfig.
+# (This is not indented, because the tabs will be part of the output)
+file(WRITE ${PROJECT_BINARY_DIR}/libwebsockets.pc
+"prefix=/usr/local
+exec_prefix=\${prefix}
+libdir=\${exec_prefix}/lib${LIB_SUFFIX}
+includedir=\${prefix}/include
+
+Name: libwebsockets
+Description: Websockets server and client library
+Version: ${PACKAGE_VERSION}
+
+Libs: -L\${libdir} -lwebsockets
+Cflags: -I\${includedir}"
+)
+
+ install(FILES ${PROJECT_BINARY_DIR}/libwebsockets.pc
+ DESTINATION lib${LIB_SUFFIX}/pkgconfig)
+endif()
+
+# Install headers.
+install(FILES ${HDR_PUBLIC}
+ DESTINATION include
+ COMPONENT headers)
+set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Header files")
+
+# Install libs.
+install(TARGETS websockets websockets_shared
+ LIBRARY DESTINATION lib${LIB_SUFFIX}
+ ARCHIVE DESTINATION lib${LIB_SUFFIX}
+ COMPONENT libraries)
+set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")
+
+# Install test apps.
+if (NOT WITHOUT_TESTAPPS)
+ install(TARGETS test-client ${TEST_APP_LIST}
+ RUNTIME DESTINATION bin
+ COMPONENT examples)
+ set(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example Install")
+endif()
+
+# Programs shared files used by the test-server.
+if (NOT WITHOUT_TESTAPPS AND NOT WITHOUT_SERVER)
+ install(FILES ${TEST_SERVER_DATA}
+ DESTINATION share/libwebsockets-test-server
+ COMPONENT examples)
+endif()
+
+# Most people are more used to "make dist" compared to "make package_source"
+add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
+
+# This must always be last!
+include(CPack)