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

Establish a new distributed CMake architecture with CMake code related to a source directory moving to be in the subdir in its own CMakeLists.txt. In particular, there's now one in ./lib which calls through to ones further down the directory tree like ./lib/plat/xxx, ./lib/roles/xxx etc. This cuts the main CMakelists.txt from 98KB -> 33KB, about a 66% reduction, and it's much easier to maintain sub-CMakeLists.txt that are in the same directory as the sources they manage, and conceal all the details that that level. Child CMakelists.txt become responsible for: - include_directories() definition (this is not supported by CMake directly, it passes it back up via PARENT_SCOPE vars in helper macros) - Addition child CMakeLists.txt inclusion, for example toplevel -> role -> role subdir - Source file addition to the build - Dependent library path resolution... this is now a private thing in the child CMakeLists.txt, it just passes back any adaptations to include_directories() and the LIB_LIST without filling the parent namespace with the details
84 lines
3.3 KiB
CMake
84 lines
3.3 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(CheckCSourceCompiles)
|
|
include(LwsCheckRequirements)
|
|
|
|
set(SAMP lws-minimal-http-server-eventlib-foreign)
|
|
set(SRCS minimal-http-server-eventlib-foreign.c)
|
|
|
|
set(requirements 1)
|
|
require_lws_config(LWS_ROLE_H1 1 requirements)
|
|
require_lws_config(LWS_WITH_SERVER 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})
|
|
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})
|
|
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})
|
|
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})
|
|
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})
|
|
add_dependencies(${SAMP} websockets_shared)
|
|
else()
|
|
target_link_libraries(${SAMP} websockets ${extralibs})
|
|
endif()
|
|
endif()
|