cmake: Save features in use to a property

This commit is contained in:
Roger A. Light
2026-03-10 09:13:29 +00:00
parent 32dcead969
commit cbfef628fe
4 changed files with 48 additions and 41 deletions

View File

@@ -32,6 +32,13 @@ if(APPLE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -undefined dynamic_lookup")
endif()
set_property(GLOBAL PROPERTY TEST_ENV_VARS "BUILD_ROOT=${CMAKE_BINARY_DIR}")
function(option_env name description value)
option(${name} "${description}" ${value})
get_property(test_vars GLOBAL PROPERTY TEST_ENV_VARS)
set_property(GLOBAL PROPERTY TEST_ENV_VARS "${test_vars};${name}=${${name}}")
endfunction()
add_library(common-options INTERFACE)
if(NOT WIN32)
target_compile_options(common-options INTERFACE -Wall -Wextra -Wconversion)
@@ -45,12 +52,12 @@ include(GNUInstallDirs)
include(CMakePushCheckState)
include(CheckSourceCompiles)
option(WITH_BUNDLED_DEPS "Build with bundled dependencies?" ON)
option(WITH_LIB_CPP "Build C++ library?" ON)
option(WITH_TLS "Include SSL/TLS support?" ON)
option(WITH_TLS_PSK "Include TLS-PSK support (requires WITH_TLS)?" ON)
option(WITH_TESTS "Enable tests" ON)
option(INC_MEMTRACK "Include memory tracking support?" ON)
option_env(WITH_BUNDLED_DEPS "Build with bundled dependencies?" ON)
option_env(WITH_LIB_CPP "Build C++ library?" ON)
option_env(WITH_TLS "Include SSL/TLS support?" ON)
option_env(WITH_TLS_PSK "Include TLS-PSK support (requires WITH_TLS)?" ON)
option_env(WITH_TESTS "Enable tests" ON)
option_env(INC_MEMTRACK "Include memory tracking support?" ON)
if (WITH_LIB_CPP OR WITH_TESTS)
ENABLE_LANGUAGE(CXX)
@@ -73,27 +80,27 @@ else()
set (OPENSSL_INCLUDE_DIR "")
endif()
option(WITH_UNIX_SOCKETS "Include Unix Domain Socket support?" ON)
option_env(WITH_UNIX_SOCKETS "Include Unix Domain Socket support?" ON)
if(WITH_UNIX_SOCKETS)
add_definitions("-DWITH_UNIX_SOCKETS")
endif()
option(WITH_SOCKS "Include SOCKS5 support?" ON)
option_env(WITH_SOCKS "Include SOCKS5 support?" ON)
if(WITH_SOCKS)
add_definitions("-DWITH_SOCKS")
endif()
option(WITH_WEBSOCKETS "Include websockets support?" ON)
option(WITH_WEBSOCKETS_BUILTIN "Websockets support uses builtin library? Set OFF to use libwebsockets" ON)
option_env(WITH_WEBSOCKETS "Include websockets support?" ON)
option_env(WITH_WEBSOCKETS_BUILTIN "Websockets support uses builtin library? Set OFF to use libwebsockets" ON)
if(WITH_WEBSOCKETS AND NOT WITH_TLS)
message(FATAL_ERROR "WITH_WEBSOCKETS support requires WITH_TLS.")
endif()
option(WITH_SRV "Include SRV lookup support?" OFF)
option(WITH_STATIC_LIBRARIES "Build static versions of the libmosquitto/pp libraries?" OFF)
option(WITH_PIC "Build the static library with PIC (Position Independent Code) enabled archives?" OFF)
option_env(WITH_SRV "Include SRV lookup support?" OFF)
option_env(WITH_STATIC_LIBRARIES "Build static versions of the libmosquitto/pp libraries?" OFF)
option_env(WITH_PIC "Build the static library with PIC (Position Independent Code) enabled archives?" OFF)
option(WITH_THREADING "Include threading support?" ON)
option_env(WITH_THREADING "Include threading support?" ON)
if(WITH_THREADING)
add_definitions("-DWITH_THREADING")
if(WIN32)
@@ -101,7 +108,7 @@ if(WITH_THREADING)
endif()
endif()
option(WITH_DLT "Include DLT support?" OFF)
option_env(WITH_DLT "Include DLT support?" OFF)
message(STATUS "WITH_DLT = ${WITH_DLT}")
if(WITH_DLT)
find_package(PkgConfig)
@@ -111,7 +118,7 @@ endif()
find_package(cJSON REQUIRED)
find_package(argon2)
option(WITH_CTRL_SHELL "Include mosquitto_ctrl interactive shell support?" ON)
option_env(WITH_CTRL_SHELL "Include mosquitto_ctrl interactive shell support?" ON)
if(WITH_CTRL_SHELL)
find_package(LineEditing)
endif()
@@ -120,7 +127,7 @@ if(ARGON2_FOUND)
#add_definitions("-DWITH_ARGON2")
endif()
option(WITH_LTO "Build with link time optimizations (IPO) / interprocedural optimization (IPO) enabled." ON)
option_env(WITH_LTO "Build with link time optimizations (IPO) / interprocedural optimization (IPO) enabled." ON)
if(WITH_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT is_ipo_supported OUTPUT output)
@@ -135,11 +142,11 @@ endif()
# Include projects
# ========================================
option(WITH_CLIENTS "Build clients?" ON)
option(WITH_BROKER "Build broker?" ON)
option(WITH_APPS "Build apps?" ON)
option(WITH_PLUGINS "Build plugins?" ON)
option(WITH_DOCS "Build documentation?" ON)
option_env(WITH_CLIENTS "Build clients?" ON)
option_env(WITH_BROKER "Build broker?" ON)
option_env(WITH_APPS "Build apps?" ON)
option_env(WITH_PLUGINS "Build plugins?" ON)
option_env(WITH_DOCS "Build documentation?" ON)
target_sources(common-options INTERFACE config.h)
target_include_directories(common-options

View File

@@ -69,12 +69,12 @@ if(INC_MEMTRACK)
target_compile_definitions(libmosquitto_common PUBLIC "WITH_MEMORY_TRACKING")
endif()
option(ALLOC_MISMATCH_INVALID_READ "Memory function mismatch detection." OFF)
option_env(ALLOC_MISMATCH_INVALID_READ "Memory function mismatch detection." OFF)
if(ALLOC_MISMATCH_INVALID_READ)
target_compile_definitions(libmosquitto_common PRIVATE "ALLOC_MISMATCH_INVALID_READ")
endif()
option(ALLOC_MISMATCH_ABORT "Memory function mismatch abort." OFF)
option_env(ALLOC_MISMATCH_ABORT "Memory function mismatch abort." OFF)
if(ALLOC_MISMATCH_ABORT)
target_compile_definitions(libmosquitto_common PRIVATE "ALLOC_MISMATCH_ABORT")
endif()

View File

@@ -34,12 +34,12 @@ function(add_mosquitto_plugin PLUGIN_NAME SRCLIST INCLIST LINKLIST)
endfunction()
option(WITH_PLUGIN_ACL_FILE "Build acl-file plugin?" ON)
option(WITH_PLUGIN_DYNAMIC_SECURITY "Build dynamic-security plugin?" ON)
option(WITH_PLUGIN_EXAMPLES "Build example plugins?" ON)
option(WITH_PLUGIN_PERSIST_SQLITE "Build persist-sqlite plugin?" ON)
option(WITH_PLUGIN_PASSWORD_FILE "Build password-file plugin?" ON)
option(WITH_PLUGIN_SPARKPLUG_AWARE "Build sparkplug-aware plugin?" ON)
option_env(WITH_PLUGIN_ACL_FILE "Build acl-file plugin?" ON)
option_env(WITH_PLUGIN_DYNAMIC_SECURITY "Build dynamic-security plugin?" ON)
option_env(WITH_PLUGIN_EXAMPLES "Build example plugins?" ON)
option_env(WITH_PLUGIN_PERSIST_SQLITE "Build persist-sqlite plugin?" ON)
option_env(WITH_PLUGIN_PASSWORD_FILE "Build password-file plugin?" ON)
option_env(WITH_PLUGIN_SPARKPLUG_AWARE "Build sparkplug-aware plugin?" ON)
if(WITH_PLUGIN_ACL_FILE)
add_subdirectory(acl-file)

View File

@@ -96,14 +96,14 @@ if(HAVE_SYS_EPOLL_H)
target_compile_definitions(mosquitto PRIVATE "WITH_EPOLL")
endif()
option(INC_BRIDGE_SUPPORT
option_env(INC_BRIDGE_SUPPORT
"Include bridge support for connecting to other brokers?" ON)
if(INC_BRIDGE_SUPPORT)
target_sources(mosquitto PRIVATE bridge.c)
target_compile_definitions(mosquitto PRIVATE "WITH_BRIDGE")
endif()
option(WITH_HTTP_API
option_env(WITH_HTTP_API
"Include http_api support for listeners?" ON)
set(HTTP_API_DIR "Default http_api directory" CACHE STRING "")
if(WITH_HTTP_API)
@@ -125,38 +125,38 @@ if(WITH_HTTP_API)
endif()
option(USE_LIBWRAP "Include tcp-wrappers support?" OFF)
option_env(USE_LIBWRAP "Include tcp-wrappers support?" OFF)
if(USE_LIBWRAP)
target_link_libraries(mosquitto PRIVATE wrap)
target_compile_definitions(mosquitto PRIVATE "WITH_WRAP")
endif()
option(INC_DB_UPGRADE "Include database upgrade support? (recommended)" ON)
option_env(INC_DB_UPGRADE "Include database upgrade support? (recommended)" ON)
if(INC_MEMTRACK)
target_compile_definitions(mosquitto PUBLIC "WITH_MEMORY_TRACKING")
endif()
option(WITH_PERSISTENCE "Include persistence support?" ON)
option_env(WITH_PERSISTENCE "Include persistence support?" ON)
if(WITH_PERSISTENCE)
target_compile_definitions(mosquitto PRIVATE "WITH_PERSISTENCE")
endif()
option(WITH_SYS_TREE "Include $SYS tree support?" ON)
option_env(WITH_SYS_TREE "Include $SYS tree support?" ON)
if(WITH_SYS_TREE)
target_compile_definitions(mosquitto PRIVATE "WITH_SYS_TREE")
endif()
option(WITH_OLD_KEEPALIVE "Use legacy keepalive check mechanism?" OFF)
option_env(WITH_OLD_KEEPALIVE "Use legacy keepalive check mechanism?" OFF)
if (WITH_OLD_KEEPALIVE)
add_definitions("-DWITH_OLD_KEEPALIVE")
endif (WITH_OLD_KEEPALIVE)
option(WITH_ADNS "Include ADNS support?" OFF)
option_env(WITH_ADNS "Include ADNS support?" OFF)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
option(WITH_SYSTEMD "Include systemd support?" OFF)
option_env(WITH_SYSTEMD "Include systemd support?" OFF)
if(WITH_SYSTEMD)
target_compile_definitions(mosquitto PRIVATE "WITH_SYSTEMD")
find_library(SYSTEMD_LIBRARY systemd)
@@ -164,9 +164,9 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
endif()
endif()
option(STATIC_WEBSOCKETS "Use the static libwebsockets library?" OFF)
option_env(STATIC_WEBSOCKETS "Use the static libwebsockets library?" OFF)
option(WITH_CONTROL "Include $CONTROL topic support?" ON)
option_env(WITH_CONTROL "Include $CONTROL topic support?" ON)
if(WITH_CONTROL)
target_compile_definitions(mosquitto PRIVATE "WITH_CONTROL")
endif()