TIVI-1932: Add support for systemd based socket activation.
[profile/ivi/libwebsockets.git] / CMakeLists.txt
index 3b507b4..0188cee 100644 (file)
@@ -48,6 +48,7 @@ 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.")
@@ -274,12 +275,16 @@ if (WIN32)
                ${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.
@@ -353,6 +358,19 @@ set(LIB_LIST)
 #
 
 #
+# SD_DAEMON (Only needed if systemd socket activation is desired.)
+#
+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()
+
+#
 # ZLIB (Only needed for deflate extensions).
 #
 if (NOT WITHOUT_EXTENSIONS)
@@ -544,10 +562,10 @@ if (NOT WITHOUT_TESTAPPS)
 
                # Data files for running the test server.
                set(TEST_SERVER_DATA
-                       test-server/favicon.ico 
-                       test-server/leaf.jpg
-                       test-server/libwebsockets.org-logo.png
-                       test-server/test.html)
+                       ${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)
@@ -574,6 +592,8 @@ if (NOT WITHOUT_TESTAPPS)
                                        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()
@@ -589,6 +609,15 @@ if (NOT WITHOUT_TESTAPPS)
                                ${TEST_SERVER_SSL_KEY} 
                                ${TEST_SERVER_SSL_CERT})
                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)
 
        if (NOT WITHOUT_CLIENT)
@@ -668,7 +697,7 @@ if (UNIX)
 file(WRITE ${PROJECT_BINARY_DIR}/libwebsockets.pc
 "prefix=/usr/local
 exec_prefix=\${prefix}
-libdir=\${exec_prefix}/lib
+libdir=\${exec_prefix}/lib${LIB_SUFFIX}
 includedir=\${prefix}/include
 
 Name: libwebsockets
@@ -680,7 +709,7 @@ Cflags: -I\${includedir}"
 )
 
        install(FILES ${PROJECT_BINARY_DIR}/libwebsockets.pc
-               DESTINATION include/pkgconfig)
+               DESTINATION lib${LIB_SUFFIX}/pkgconfig)
 endif()
 
 # Install headers.
@@ -691,8 +720,8 @@ set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Header files")
 
 # Install libs.
 install(TARGETS websockets websockets_shared
-               LIBRARY DESTINATION lib
-               ARCHIVE DESTINATION lib
+               LIBRARY DESTINATION lib${LIB_SUFFIX}
+               ARCHIVE DESTINATION lib${LIB_SUFFIX}
                COMPONENT libraries)
 set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")