1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00
libwebsockets/lib/plat/unix/CMakeLists.txt
Daniel Danzberger 4c50636912 unix: Fix linker errors when building without sdevent
When building without systemd event support (-DLWS_WITH_SDEVENT=OFF) on
a system that has libsystemd headers installed, lib/plat/unix-systemd.c
is build in anyway.
The final libwebsockets library has then references to symbols from
libsystemd even though it won't be linked.

Resulting in the follwoing linker errros:
--
/usr/bin/ld: /usr/local/lib/libwebsockets.so: undefined reference to `sd_is_socket_inet'
/usr/bin/ld: /usr/local/lib/libwebsockets.so: undefined reference to `sd_is_socket_unix'
/usr/bin/ld: /usr/local/lib/libwebsockets.so: undefined reference to `sd_listen_fds'
--

This commit ensures that unix-system.c is only build when LWS_WITH_SDEVENT is set and
the system has libsystemd headers installed.

Signed-off-by: Daniel Danzberger <dd@embedd.com>
2025-03-01 08:13:50 +00:00

115 lines
3.2 KiB
CMake

#
# libwebsockets - small server side websockets and web server implementation
#
# Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
#
# The strategy is to only export to PARENT_SCOPE
#
# - changes to LIB_LIST
# - changes to SOURCES
# - includes via include_directories
#
# and keep everything else private
include_directories(.)
execute_process( COMMAND grep -c illumos /lib/ld.so.1
OUTPUT_VARIABLE ILLUMOS ERROR_QUIET )
# Chomp the \n at end of output.
string(REGEX REPLACE "[\n]+" "" ILLUMOS "${ILLUMOS}")
if (NOT ${ILLUMOS} MATCHES "0")
set(ILLUMOS 1)
endif()
set(LWS_PLAT_UNIX 1)
list(APPEND SOURCES
plat/unix/unix-caps.c
plat/unix/unix-misc.c
plat/unix/unix-init.c
)
if (LWS_WITH_FILE_OPS)
list(APPEND SOURCES plat/unix/unix-file.c)
endif()
if (LWS_WITH_NETWORK)
list(APPEND SOURCES
plat/unix/unix-pipe.c
plat/unix/unix-service.c
plat/unix/unix-sockets.c
plat/unix/unix-fds.c
)
if (LWS_WITH_SYS_ASYNC_DNS)
if (LWS_PLAT_ANDROID)
list(APPEND SOURCES plat/unix/android/android-resolv.c)
else()
list(APPEND SOURCES plat/unix/unix-resolv.c)
endif()
endif()
if (LWS_WITH_SDEVENT AND LWS_HAVE_SYSTEMD_H)
list(APPEND SOURCES
plat/unix/unix-systemd.c
)
list(APPEND LIB_LIST_AT_END systemd)
endif()
endif()
if (LWS_WITH_PLUGINS_API)
list(APPEND SOURCES plat/unix/unix-plugins.c)
endif()
if (LWS_WITH_SPAWN)
list(APPEND SOURCES plat/unix/unix-spawn.c)
endif()
if (HAIKU)
set(CMAKE_REQUIRED_LIBRARIES network)
list(APPEND LIB_LIST_AT_END network)
endif()
IF (CMAKE_SYSTEM_NAME STREQUAL Linux AND NOT LWS_WITHOUT_EVENTFD)
CHECK_FUNCTION_EXISTS(eventfd_read LWS_HAVE_EVENTFD)
endif()
list(APPEND LIB_LIST_AT_END m)
if (ILLUMOS)
list(APPEND LIB_LIST_AT_END socket)
endif()
if (LWS_HAVE_LIBCAP)
list(APPEND LIB_LIST_AT_END cap)
endif()
if (${CMAKE_SYSTEM_NAME} MATCHES "QNX")
list(APPEND LIB_LIST_AT_END socket)
endif()
list(APPEND LIB_LIST_AT_END ${CMAKE_DL_LIBS})
#
# Keep explicit parent scope exports at end
#
exports_to_parent_scope()
set(LWS_PLAT_UNIX ${LWS_PLAT_UNIX} PARENT_SCOPE)
set(ILLUMOS ${ILLUMOS} PARENT_SCOPE)
set(LIB_LIST_AT_END ${LIB_LIST_AT_END} PARENT_SCOPE)
set(LWS_PLAT_UNIX ${LWS_PLAT_UNIX} PARENT_SCOPE)