mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00

Event lib support as it has been isn't scaling well, at the low level libevent and libev headers have a namespace conflict so they can't both be built into the same image, and at the distro level, binding all the event libs to libwebsockets.so makes a bloaty situation for packaging, lws will drag in all the event libs every time. This patch implements the plan discussed here https://github.com/warmcat/libwebsockets/issues/1980 and refactors the event lib support so they are built into isolated plugins and bound at runtime according to what the application says it wants to use. The event lib plugins can be packaged individually so that only the needed sets of support are installed (perhaps none of them if the user code is OK with the default poll() loop). And dependent user code can mark the specific event loop plugin package as required so pieces are added as needed. The eventlib-foreign example is also refactored to build the selected lib support isolated. A readme is added detailing the changes and how to use them. https://libwebsockets.org/git/libwebsockets/tree/READMEs/README.event-libs.md
91 lines
3.5 KiB
CMake
91 lines
3.5 KiB
CMake
project(lws-minimal-http-server-eventlib-foreign C)
|
|
cmake_minimum_required(VERSION 2.8)
|
|
find_package(libwebsockets CONFIG REQUIRED)
|
|
list(APPEND CMAKE_MODULE_PATH ${LWS_CMAKE_DIR})
|
|
include(CheckIncludeFile)
|
|
include(CheckCSourceCompiles)
|
|
include(LwsCheckRequirements)
|
|
|
|
set(SAMP lws-minimal-http-server-eventlib-foreign)
|
|
set(SRCS minimal-http-server-eventlib-foreign.c)
|
|
|
|
set(requirements 1)
|
|
require_pthreads(requirements)
|
|
require_lws_config(LWS_ROLE_H1 1 requirements)
|
|
require_lws_config(LWS_WITH_SERVER 1 requirements)
|
|
require_lws_config(LWS_WITH_TLS 1 requirements)
|
|
|
|
CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_LIBUV)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBUV)
|
|
CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_LIBEVENT)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBEVENT)
|
|
CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_LIBEV)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_LIBEV)
|
|
CHECK_C_SOURCE_COMPILES("#include <libwebsockets.h>\nint main(void) {\n#if defined(LWS_WITH_GLIB)\n return 0;\n#else\n fail;\n#endif\n return 0;\n}\n" LWS_WITH_GLIB)
|
|
|
|
|
|
if (LWS_WITH_LIBUV)
|
|
find_path(LIBUV_INCLUDE_DIRS NAMES uv.h)
|
|
find_library(LIBUV_LIBRARIES NAMES uv)
|
|
message("libuv include dir: ${LIBUV_INCLUDE_DIRS}")
|
|
message("libuv libraries: ${LIBUV_LIBRARIES}")
|
|
include_directories("${LIBUV_INCLUDE_DIRS}")
|
|
set(extralibs ${extralibs} ${LIBUV_LIBRARIES})
|
|
list(APPEND SRCS libuv.c)
|
|
endif()
|
|
if (LWS_WITH_LIBEVENT)
|
|
find_path(LIBEVENT_INCLUDE_DIRS NAMES event2/event.h)
|
|
find_library(LIBEVENT_LIBRARIES NAMES event)
|
|
message("libevent include dir: ${LIBEVENT_INCLUDE_DIRS}")
|
|
message("libevent libraries: ${LIBEVENT_LIBRARIES}")
|
|
include_directories("${LIBEVENT_INCLUDE_DIRS}")
|
|
set(extralibs ${extralibs} ${LIBEVENT_LIBRARIES})
|
|
list(APPEND SRCS libevent.c)
|
|
endif()
|
|
if (LWS_WITH_LIBEV)
|
|
find_path(LIBEV_INCLUDE_DIRS NAMES ev.h)
|
|
find_library(LIBEV_LIBRARIES NAMES ev)
|
|
message("libev include dir: ${LIBEV_INCLUDE_DIRS}")
|
|
message("libev libraries: ${LIBEV_LIBRARIES}")
|
|
include_directories("${LIBEV_INCLUDE_DIRS}")
|
|
set(extralibs ${extralibs} ${LIBEV_LIBRARIES})
|
|
list(APPEND SRCS libev.c)
|
|
endif()
|
|
if (LWS_WITH_GLIB)
|
|
set(LWS_GLIB_INCLUDE_DIRS CACHE PATH "Path to the glib include directory")
|
|
set(LWS_GLIB_LIBRARIES CACHE PATH "Path to the glib library")
|
|
include (FindPkgConfig)
|
|
if (NOT GLIB_FOUND)
|
|
find_path(GLIB_INCLUDE_DIRS NAMES glib-2.0/glib.h)
|
|
find_library(GLIB_LIBRARIES NAMES glib-2.0)
|
|
if(GLIB_INCLUDE_DIRS AND GLIB_LIBRARIES)
|
|
set(GLIB_FOUND 1)
|
|
endif()
|
|
if (GLIB_INCLUDE_DIRS)
|
|
set(GLIB_INCLUDE_DIRS "${GLIB_INCLUDE_DIRS}/glib-2.0")
|
|
endif()
|
|
endif()
|
|
PKG_SEARCH_MODULE(LWS_GLIB2 glib-2.0)
|
|
if (LWS_GLIB2_FOUND)
|
|
list(APPEND GLIB_INCLUDE_DIRS "${LWS_GLIB2_INCLUDE_DIRS}")
|
|
endif()
|
|
message("glib include dir: ${GLIB_INCLUDE_DIRS}")
|
|
message("glib libraries: ${GLIB_LIBRARIES}")
|
|
include_directories("${GLIB_INCLUDE_DIRS}")
|
|
set(extralibs ${extralibs} ${GLIB_LIBRARIES})
|
|
list(APPEND SRCS glib.c)
|
|
endif()
|
|
|
|
message("Extra libs: ${extralibs}")
|
|
|
|
if (NOT LWS_WITH_LIBUV AND NOT LWS_WITH_LIBEVENT AND NOT LWS_WITH_LIBEV AND NOT LWS_WITH_GLIB)
|
|
set(requirements 0)
|
|
endif()
|
|
|
|
if (requirements)
|
|
add_executable(${SAMP} ${SRCS})
|
|
|
|
if (websockets_shared)
|
|
target_link_libraries(${SAMP} websockets_shared ${extralibs} ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS})
|
|
add_dependencies(${SAMP} websockets_shared)
|
|
else()
|
|
target_link_libraries(${SAMP} websockets ${extralibs} ${PTHREAD_LIB} ${LIBWEBSOCKETS_DEP_LIBS})
|
|
endif()
|
|
endif()
|