From b0519612a698244016884022cbd47353c35c4a06 Mon Sep 17 00:00:00 2001 From: Michael Medin Date: Thu, 4 Jun 2026 07:07:02 +0200 Subject: [PATCH 1/2] Allow building with missing beast/mongoose if web server is disabled. Signed-off-by: Michael Medin --- CMakeLists.txt | 5 ---- build/cmake/dependencies.cmake | 48 +++++++++++++++++++------------- libs/mongoose-cpp/CMakeLists.txt | 17 ++++++++++- modules/WEBServer/CMakeLists.txt | 16 +++++++++++ tests/CMakeLists.txt | 6 ++++ 5 files changed, 66 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21572450e..5a5aaf2a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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} diff --git a/build/cmake/dependencies.cmake b/build/cmake/dependencies.cmake index 312adaae1..a9d003e59 100644 --- a/build/cmake/dependencies.cmake +++ b/build/cmake/dependencies.cmake @@ -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() diff --git a/libs/mongoose-cpp/CMakeLists.txt b/libs/mongoose-cpp/CMakeLists.txt index 26909ceae..6a18a200e 100644 --- a/libs/mongoose-cpp/CMakeLists.txt +++ b/libs/mongoose-cpp/CMakeLists.txt @@ -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 @@ -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) diff --git a/modules/WEBServer/CMakeLists.txt b/modules/WEBServer/CMakeLists.txt index 69c2c1f6c..73ddd99f7 100644 --- a/modules/WEBServer/CMakeLists.txt +++ b/modules/WEBServer/CMakeLists.txt @@ -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 diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 90e943449..0e36a6778 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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. @@ -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 From b57e63c3198666ea3f8f2a7bbdb78f7ad11017c3 Mon Sep 17 00:00:00 2001 From: Michael Medin Date: Fri, 5 Jun 2026 03:29:56 +0200 Subject: [PATCH 2/2] cmake: conditionally include Boost components based on Mongoose availability Signed-off-by: Michael Medin --- build/cmake/dependencies.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build/cmake/dependencies.cmake b/build/cmake/dependencies.cmake index a9d003e59..c21940b7e 100644 --- a/build/cmake/dependencies.cmake +++ b/build/cmake/dependencies.cmake @@ -140,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()