Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,6 @@ set(NSCP_DEF_PLUGIN_LIB
${PLUGIN_API_TARGET}
)

set(ALL_LIB_NAMES)
message(STATUS "Adding libraries")
file(
GLOB ALL_LIB_PROJECTS
Expand All @@ -1035,10 +1034,6 @@ foreach(CURRENT_LIB ${ALL_LIB_PROJECTS})
endif()
message(STATUS " + Library: ${CURRENT_LIB_PATH} (${CURRENT_LIB_NAME})")
add_subdirectory("${CURRENT_LIB_PATH}")
set(ALL_LIB_NAMES
${ALL_LIB_NAMES}
${CURRENT_LIB_NAME}
)
endforeach(
CURRENT_LIB
${ALL_LIB_PROJECTS}
Expand Down
56 changes: 35 additions & 21 deletions build/cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -86,38 +86,46 @@ set(NSCP_WEB_BACKEND
)
set_property(CACHE NSCP_WEB_BACKEND PROPERTY STRINGS mongoose beast)

# Decide whether the nscp_mongoose web library can be built. It is only
# built when the selected backend's dependencies are satisfied:
# mongoose -> the vendored mongoose source is found
# beast -> OpenSSL is available (ServerBeastImpl includes Boost.Asio
# SSL headers, which need OpenSSL headers/libs at compile time
# even when TLS is not enabled at runtime)
# When they are not, we skip building nscp_mongoose rather than failing the
# whole configure; modules/WEBServer/CMakeLists.txt raises a targeted error
# if it is asked to build without the library.
set(NSCP_MONGOOSE_AVAILABLE FALSE)
if(NSCP_WEB_BACKEND STREQUAL "mongoose")
find_package(Mongoose)
# Surface a clear error here instead of letting MONGOOSE_INCLUDE_DIR-NOTFOUND
# propagate into source lists (`${MONGOOSE_INCLUDE_DIR}/mongoose.c`), which
# otherwise fails much later with a cryptic "Cannot find source file".
if(NOT MONGOOSE_FOUND)
if(MONGOOSE_FOUND)
set(NSCP_MONGOOSE_AVAILABLE TRUE)
else()
message(
FATAL_ERROR
"NSCP_WEB_BACKEND=mongoose requires the vendored mongoose source.\n"
"Either set MONGOOSE_SOURCE_DIR (see build.md), or switch to the\n"
"Beast backend with -DNSCP_WEB_BACKEND=beast (the default on Linux\n"
"CI builds)."
STATUS
"NSCP_WEB_BACKEND=mongoose but the vendored mongoose source was not "
"found; nscp_mongoose (and the WEBServer module) will not be built. "
"Set MONGOOSE_SOURCE_DIR (see build.md), or switch to the Beast "
"backend with -DNSCP_WEB_BACKEND=beast (the default on Linux CI "
"builds)."
)
endif()
elseif(NSCP_WEB_BACKEND STREQUAL "beast")
# Beast is header-only; the Boost components (coroutine + context)
# needed by ServerBeastImpl are added below.
# ServerBeastImpl also includes Boost.Asio SSL headers, which require
# OpenSSL headers/libs at compile time even when TLS is not enabled at
# runtime. Fail during configure instead of producing a later compile
# error from missing openssl/ssl.h or unresolved SSL symbols.
if(NOT OPENSSL_FOUND)
if(OPENSSL_FOUND)
set(NSCP_MONGOOSE_AVAILABLE TRUE)
message(STATUS "WEB backend: Boost.Beast (mongoose download skipped)")
else()
message(
FATAL_ERROR
"NSCP_WEB_BACKEND=beast requires OpenSSL.\n"
"ServerBeastImpl includes Boost.Asio SSL headers, so OpenSSL must\n"
"be available at configure/build time even if TLS is not enabled\n"
"at runtime.\n"
STATUS
"NSCP_WEB_BACKEND=beast but OpenSSL was not found; nscp_mongoose "
"(and the WEBServer module) will not be built. ServerBeastImpl "
"includes Boost.Asio SSL headers, so OpenSSL must be available at "
"configure/build time even if TLS is not enabled at runtime. "
"Install/configure OpenSSL, or switch to -DNSCP_WEB_BACKEND=mongoose."
)
endif()
message(STATUS "WEB backend: Boost.Beast (mongoose download skipped)")
else()
message(FATAL_ERROR "Unknown NSCP_WEB_BACKEND='${NSCP_WEB_BACKEND}' (expected mongoose | beast)")
endif()
Comment thread
mickem marked this conversation as resolved.
Expand All @@ -132,8 +140,14 @@ endif()
# unused work — and would force the package list (libboost-coroutine,
# libboost-context on Debian; analogous on RPM) on environments that
# only ever build the mongoose backend (typically Windows).
#
# Gate on NSCP_MONGOOSE_AVAILABLE too: when the Beast backend is selected but
# its dependencies are missing (e.g. OpenSSL not found) the web library is
# skipped, so ServerBeastImpl is never compiled. Requesting coroutine/context
# as *required* COMPONENTS below would then turn an optional, disabled web
# build into a hard Boost.Coroutine/Context requirement and fail configure.
set(_nscp_extra_boost_components)
if(NSCP_WEB_BACKEND STREQUAL "beast")
if(NSCP_WEB_BACKEND STREQUAL "beast" AND NSCP_MONGOOSE_AVAILABLE)
list(APPEND _nscp_extra_boost_components coroutine context)
endif()

Expand Down
17 changes: 16 additions & 1 deletion libs/mongoose-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
cmake_minimum_required(VERSION 3.10)
project(nscp_mongoose)

# Only build the library when the selected web backend's dependencies are
# satisfied (see NSCP_MONGOOSE_AVAILABLE in build/cmake/dependencies.cmake).
# When they are not, skip the target entirely; the WEBServer module raises a
# targeted error if it is asked to build without it.
if(NOT NSCP_MONGOOSE_AVAILABLE)
message(
STATUS
"Skipping nscp_mongoose: NSCP_WEB_BACKEND='${NSCP_WEB_BACKEND}' "
"dependencies are not satisfied."
)
return()
endif()

# Backend-independent sources.
set(SOURCES
Controller.cpp
Expand All @@ -24,8 +37,10 @@ set(SOURCES
if(NSCP_WEB_BACKEND STREQUAL "beast")
list(APPEND SOURCES ServerBeastImpl.cpp)
add_definitions(-DNSCP_WEB_BACKEND_BEAST)
else()
elseif(NSCP_WEB_BACKEND STREQUAL "mongoose")
list(APPEND SOURCES ServerMongooseImpl.cpp ${MONGOOSE_INCLUDE_DIR}/mongoose.c)
else()
message(FATAL_ERROR "Unknown NSCP_WEB_BACKEND='${NSCP_WEB_BACKEND}' (expected mongoose | beast)")
endif()

if(WIN32)
Expand Down
16 changes: 16 additions & 0 deletions modules/WEBServer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ set(TARGET WEBServer)

project(${TARGET})

# WEBServer links against nscp_mongoose, which is only built when the selected
# web backend's dependencies are satisfied (see NSCP_MONGOOSE_AVAILABLE in
# build/cmake/dependencies.cmake). Fail with a clear message here instead of a
# cryptic "target nscp_mongoose not found" later. Disable this module with
# -DBUILD_MODULE_WEBServer=OFF if you cannot provide the backend.
if(NOT TARGET nscp_mongoose)
message(
FATAL_ERROR
"WEBServer requires the nscp_mongoose library, which was not built "
"because the NSCP_WEB_BACKEND='${NSCP_WEB_BACKEND}' web backend's "
"dependencies are not satisfied. Provide the backend dependencies "
"(mongoose source, or OpenSSL for beast), switch NSCP_WEB_BACKEND, "
"or disable this module with -DBUILD_MODULE_WEBServer=OFF."
)
endif()

CREATE_MODULE(SRCS ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

set(SRCS
Expand Down
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ NSCP_CREATE_TEST(
${CMAKE_SOURCE_DIR}/modules/IcingaClient
)

# The mongoose wrapper tests link against nscp_mongoose, which is only built
# when the selected web backend's dependencies are satisfied (see
# NSCP_MONGOOSE_AVAILABLE in build/cmake/dependencies.cmake). Skip the test
# when the library is not built rather than failing on a missing target.
if(TARGET nscp_mongoose)
set(MONGOOSE_CPP_DIR ${CMAKE_SOURCE_DIR}/libs/mongoose-cpp)

# Shared (backend-independent) test sources.
Expand Down Expand Up @@ -565,6 +570,7 @@ if(WIN32)
COMMAND_EXPAND_LISTS
)
endif()
endif() # TARGET nscp_mongoose

set(SETTINGS_INI_TEST_SOURCES
${NSCP_INCLUDEDIR}/settings/impl/settings_ini_test.cpp
Expand Down
Loading