From d03236d5f8de50e9d9edcd055cf439e8e61fbe18 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Thu, 9 Jul 2026 08:50:23 +0200 Subject: [PATCH 01/15] Install Boost.Atomic on *suse* GHAs The Boost::thread CMake target depends on it. Actually it's needed only on *suse*:15.*, but can't harm having it on the other GHAs too. --- .github/workflows/linux.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linux.bash b/.github/workflows/linux.bash index a41fce8cb5a..eb342042973 100755 --- a/.github/workflows/linux.bash +++ b/.github/workflows/linux.bash @@ -54,7 +54,7 @@ case "$DISTRO" in *suse*) zypper in -y --allow-downgrade bison ccache cmake flex gcc-c++ ninja rpm-config-SUSE \ {lib{edit,mariadb,openssl},ncurses,postgresql,systemd,protobuf}-devel \ - libboost_{context,coroutine,filesystem,iostreams,program_options,regex,system,test,thread}-devel + libboost_{atomic,context,coroutine,filesystem,iostreams,program_options,regex,system,test,thread}-devel ;; *rockylinux:*) From 89e7e57fca179866189a6dfafa1bf9e78fa07a54 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Fri, 10 Jul 2026 10:18:15 +0200 Subject: [PATCH 02/15] Move `NOMINMAX` and `WIN32_LEAN_AND_MEAN` from `win32.hpp` to CMake This is required for the new unity builds because it is not guaranteed that a source file that includes `i2-base.hpp`, which includes `win32.hpp` is at the very start of each unity build file. This would otherwise cause syntax errors like `C2589` when C++ constructs like `std::min()` or `std::numeric_limits::max()` are used because `windows.h` without `NOMINMAX` defined will define `min()` and `max()` macros. --- lib/base/CMakeLists.txt | 2 ++ lib/base/win32.hpp | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index b31ede44ddd..6f80914e45d 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -109,6 +109,8 @@ if(WIN32) list(APPEND base_SOURCES windowseventloglogger-provider.h) + add_compile_definitions(WIN32_LEAN_AND_MEAN NOMINMAX) + add_custom_command( OUTPUT windowseventloglogger-provider.res COMMAND rc ARGS windowseventloglogger-provider.rc diff --git a/lib/base/win32.hpp b/lib/base/win32.hpp index 3b08181d837..853c920632b 100644 --- a/lib/base/win32.hpp +++ b/lib/base/win32.hpp @@ -4,11 +4,9 @@ #ifndef WIN32_H #define WIN32_H -#define WIN32_LEAN_AND_MEAN #ifndef _WIN32_WINNT #define _WIN32_WINNT _WIN32_WINNT_WIN7 #endif /* _WIN32_WINNT */ -#define NOMINMAX #include #include #include From a64fb633a9469e4a8e45a8c4c4188581a849a4dd Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Thu, 9 Jul 2026 09:13:25 +0200 Subject: [PATCH 03/15] Add find module for systemd --- CMakeLists.txt | 9 +++++---- cmake/FindSystemd.cmake | 35 +++++++++++++++++++++++++++++++++++ config.h.cmake | 1 - etc/CMakeLists.txt | 2 +- lib/base/CMakeLists.txt | 6 +----- 5 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 cmake/FindSystemd.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 82be4a0917e..b0ec2ae86bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,8 +42,6 @@ option(ICINGA2_WITH_OPENTELEMETRY "Build the OpenTelemetry integration module" $ option (USE_SYSTEMD "Configure icinga as native systemd service instead of a SysV initscript" OFF) -set(HAVE_SYSTEMD ${USE_SYSTEMD}) - include(GNUInstallDirs) include(InstallConfig) include(SetFullDir) @@ -234,8 +232,11 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/lib ) -if(HAVE_SYSTEMD) - list(APPEND base_DEPS systemd) +if(USE_SYSTEMD) + find_package(Systemd REQUIRED) + list(APPEND base_DEPS Systemd) + include_directories(SYSTEM ${Systemd_INCLUDE_DIRS}) + add_compile_definitions(HAVE_SYSTEMD) endif() if(EDITLINE_FOUND) diff --git a/cmake/FindSystemd.cmake b/cmake/FindSystemd.cmake new file mode 100644 index 00000000000..0aa60eef465 --- /dev/null +++ b/cmake/FindSystemd.cmake @@ -0,0 +1,35 @@ +# SPDX-FileCopyrightText: 2026 Icinga GmbH +# SPDX-License-Identifier: GPL-2.0-or-later + +find_path(Systemd_INCLUDE_DIRS + NAMES + systemd/sd-daemon.h + HINTS ${SYSTEMD_ROOT_DIR} +) + +find_library(Systemd_LIBRARIES + NAMES systemd + HINTS ${SYSTEMD_LIBRARY_DIR} +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Systemd + REQUIRED_VARS Systemd_LIBRARIES Systemd_INCLUDE_DIRS +) + +if(Systemd_FOUND) + message(STATUS "Systemd_LIBRARIES: ${Systemd_LIBRARIES}") + message(STATUS "Systemd_INCLUDE_DIRS: ${Systemd_INCLUDE_DIRS}") + add_library(Systemd UNKNOWN IMPORTED) + set_target_properties(Systemd PROPERTIES + IMPORTED_LOCATION "${Systemd_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${Systemd_INCLUDE_DIRS}" + INTERFACE_COMPILE_DEFINITIONS "HAVE_SYSTEMD" + INTERFACE_LINK_LIBRARIES "${Systemd_LIBRARIES}" + ) +else() + set(SYSTEMD_LIBRARIES) + set(SYSTEMD_INCLUDE_DIRS) +endif() + +mark_as_advanced(Systemd_LIBRARIES Systemd_INCLUDE_DIRS) diff --git a/config.h.cmake b/config.h.cmake index b3b36207ac6..8daab077d74 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -13,7 +13,6 @@ #cmakedefine HAVE_PTHREAD_SET_NAME_NP #cmakedefine HAVE_PTHREAD_SETNAME_NP #cmakedefine HAVE_EDITLINE -#cmakedefine HAVE_SYSTEMD #cmakedefine ICINGA2_UNITY_BUILD #cmakedefine ICINGA2_STACKTRACE_USE_BACKTRACE_SYMBOLS diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index bee39464bf9..b72c0cd553e 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -40,7 +40,7 @@ install_if_not_exists(icinga2/features-available/debuglog.conf ${ICINGA2_CONFIGD install_if_not_exists(icinga2/features-available/mainlog.conf ${ICINGA2_CONFIGDIR}/features-available) if(NOT WIN32) install_if_not_exists(icinga2/features-available/syslog.conf ${ICINGA2_CONFIGDIR}/features-available) - if(HAVE_SYSTEMD) + if(USE_SYSTEMD) install_if_not_exists(icinga2/features-available/journald.conf ${ICINGA2_CONFIGDIR}/features-available) endif() else() diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index 6f80914e45d..3f41b8bfb9b 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -133,11 +133,7 @@ if(ICINGA2_UNITY_BUILD) mkunity_target(base base base_SOURCES) endif() -if(HAVE_SYSTEMD) - find_path(SYSTEMD_INCLUDE_DIR - NAMES systemd/sd-daemon.h - HINTS ${SYSTEMD_ROOT_DIR}) - include_directories(SYSTEM ${SYSTEMD_INCLUDE_DIR}) +if(USE_SYSTEMD) set_property( SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/journaldlogger.cpp APPEND PROPERTY COMPILE_DEFINITIONS From 1077b07ed85ac1d66b872d0100ed4b552c334b73 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Thu, 9 Jul 2026 11:03:41 +0200 Subject: [PATCH 04/15] Add find module for Editline --- CMakeLists.txt | 4 +--- third-party/cmake/FindEditline.cmake | 11 +++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b0ec2ae86bb..73c7ad48158 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -204,9 +204,6 @@ include_directories(SYSTEM ${JSON_INCLUDE}) find_package(UTF8CPP) include_directories(SYSTEM ${UTF8CPP_INCLUDE}) -find_package(Editline) -set(HAVE_EDITLINE "${EDITLINE_FOUND}") - find_package(Termcap) set(HAVE_TERMCAP "${TERMCAP_FOUND}") @@ -239,6 +236,7 @@ if(USE_SYSTEMD) add_compile_definitions(HAVE_SYSTEMD) endif() +find_package(Editline) if(EDITLINE_FOUND) list(APPEND base_DEPS ${EDITLINE_LIBRARIES}) include_directories(SYSTEM ${EDITLINE_INCLUDE_DIR}) diff --git a/third-party/cmake/FindEditline.cmake b/third-party/cmake/FindEditline.cmake index eb84e4bb393..4ecadb61f34 100644 --- a/third-party/cmake/FindEditline.cmake +++ b/third-party/cmake/FindEditline.cmake @@ -76,6 +76,17 @@ find_package_handle_standard_args( EDITLINE_LIBRARIES EDITLINE_INCLUDE_DIR) +if(Editline_FOUND) + add_library(Editline UNKNOWN IMPORTED) + set_target_properties(Editline PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${EDITLINE_INCLUDE_DIR}" + INTERFACE_COMPILE_DEFINITIONS "HAVE_EDITLINE" + INTERFACE_LINK_LIBRARIES "${EDITLINE_LIBRARIES}") + set_property(TARGET Editline APPEND PROPERTY + IMPORTED_LOCATION "${EDITLINE_LIBRARIES}" + ) +endif() + mark_as_advanced( EDITLINE_ROOT_DIR EDITLINE_LIBRARIES From 79586fca39430fcc24b771a779611d8ecfa33bf8 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Thu, 9 Jul 2026 11:05:07 +0200 Subject: [PATCH 05/15] Use modern CMake commands and patterns to define targets --- CMakeLists.txt | 89 ++++--------- cmake/FindJSON.cmake | 9 -- cmake/FindUTF8CPP.cmake | 7 -- config.h.cmake | 1 - icinga-app/CMakeLists.txt | 63 ++++------ lib/base/CMakeLists.txt | 78 ++++++++---- lib/checker/CMakeLists.txt | 15 ++- lib/cli/CMakeLists.txt | 17 +-- lib/compat/CMakeLists.txt | 14 +-- lib/config/CMakeLists.txt | 26 ++-- lib/db_ido/CMakeLists.txt | 15 ++- lib/db_ido_mysql/CMakeLists.txt | 18 ++- lib/db_ido_pgsql/CMakeLists.txt | 16 +-- lib/icinga/CMakeLists.txt | 14 +-- lib/icingadb/CMakeLists.txt | 17 ++- lib/livestatus/CMakeLists.txt | 15 ++- lib/methods/CMakeLists.txt | 14 +-- lib/mysql_shim/CMakeLists.txt | 17 ++- lib/mysql_shim/mysqlinterface.cpp | 2 +- lib/notification/CMakeLists.txt | 14 +-- lib/otel/CMakeLists.txt | 31 ++--- lib/perfdata/CMakeLists.txt | 32 ++--- lib/pgsql_shim/CMakeLists.txt | 18 ++- lib/remote/CMakeLists.txt | 14 +-- plugins/CMakeLists.txt | 30 +++-- test/CMakeLists.txt | 152 ++++++++++------------- third-party/CMakeLists.txt | 10 ++ third-party/cmake/FindMySQL.cmake | 15 ++- third-party/cmake/FindPostgreSQL.cmake | 8 ++ third-party/mmatch/CMakeLists.txt | 9 +- third-party/nlohmann_json/CMakeLists.txt | 7 ++ third-party/socketpair/CMakeLists.txt | 9 +- tools/CMakeLists.txt | 1 - tools/mkclass/CMakeLists.txt | 2 + tools/mkembedconfig/CMakeLists.txt | 2 +- tools/mkunity/CMakeLists.txt | 48 ------- tools/mkunity/mkunity.c | 21 ---- 37 files changed, 382 insertions(+), 488 deletions(-) delete mode 100644 cmake/FindJSON.cmake delete mode 100644 cmake/FindUTF8CPP.cmake create mode 100644 third-party/nlohmann_json/CMakeLists.txt delete mode 100644 tools/mkunity/CMakeLists.txt delete mode 100644 tools/mkunity/mkunity.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 73c7ad48158..e269b010481 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,22 @@ option(ICINGA2_WITH_PERFDATA "Build the perfdata module" ${ICINGA2_MASTER}) option(ICINGA2_WITH_ICINGADB "Build the IcingaDB module" ${ICINGA2_MASTER}) option(ICINGA2_WITH_OPENTELEMETRY "Build the OpenTelemetry integration module" ${ICINGA2_MASTER}) +if(ICINGA2_WITH_OPENTELEMETRY) + # Newer Protobuf versions provide a CMake config package that we should prefer, since it implicitly + # links against all its dependencies (like absl, etc.) that would otherwise need to be linked manually. + # Thus, first try to find Protobuf in config mode and only fall back to module mode if that fails. + find_package(Protobuf CONFIG) + if(NOT Protobuf_FOUND) + # FindProtobuf.cmake in CMake versions < 3.31.0 is just broken and mixes up the Protobuf output directories + # and it doesn't even support to pass any PLUGIN_OPTIONS like "lite" to the protobuf_generate() function in + # order to generate code for the lite runtime without having to modify the proto files directly. + if(CMAKE_VERSION VERSION_LESS 3.31.0) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/cmake/protobuf") + endif() + find_package(Protobuf REQUIRED) + endif() +endif() + option (USE_SYSTEMD "Configure icinga as native systemd service instead of a SysV initscript" OFF) @@ -65,6 +81,11 @@ set(ICINGA2_INITRUNDIR "${ICINGA2_RUNDIR}/icinga2" CACHE FILEPATH "Runtime data set(ICINGA2_PKGDATADIR "${CMAKE_INSTALL_DATADIR}/icinga2" CACHE FILEPATH "Installed data, e.g. /usr/share/icinga2") set(ICINGA2_INCLUDEDIR "${ICINGA2_PKGDATADIR}/include" CACHE FILEPATH "Include directory for the ITL, e.g. /usr/share/icinga2/include") +# TODO: Remove when presets are done and applied in CI etc. +if(ICINGA2_UNITY_BUILD) + set(CMAKE_UNITY_BUILD ON) +endif() + # ensure absolute paths set_full_dir(ICINGA2_FULL_CONFIGDIR "${ICINGA2_CONFIGDIR}") set_full_dir(ICINGA2_FULL_CACHEDIR "${ICINGA2_CACHEDIR}") @@ -187,69 +208,13 @@ add_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED) # Required for Boost v1.74+ add_definitions(-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) -link_directories(${Boost_LIBRARY_DIRS}) -include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) - find_package(OpenSSL REQUIRED) -include_directories(SYSTEM ${OPENSSL_INCLUDE_DIR}) - -set(base_DEPS ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES}) -set(base_OBJS $ $ $) - -# JSON -find_package(JSON) -include_directories(SYSTEM ${JSON_INCLUDE}) - -# UTF8CPP -find_package(UTF8CPP) -include_directories(SYSTEM ${UTF8CPP_INCLUDE}) - -find_package(Termcap) -set(HAVE_TERMCAP "${TERMCAP_FOUND}") - -if(ICINGA2_WITH_OPENTELEMETRY) - # Newer Protobuf versions provide a CMake config package that we should prefer, since it implicitly - # links against all its dependencies (like absl, etc.) that would otherwise need to be linked manually. - # Thus, first try to find Protobuf in config mode and only fall back to module mode if that fails. - find_package(Protobuf CONFIG) - if(NOT Protobuf_FOUND) - # FindProtobuf.cmake in CMake versions < 3.31.0 is just broken and mixes up the Protobuf output directories - # and it doesn't even support to pass any PLUGIN_OPTIONS like "lite" to the protobuf_generate() function in - # order to generate code for the lite runtime without having to modify the proto files directly. - if(CMAKE_VERSION VERSION_LESS 3.31.0) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/cmake/protobuf") - endif() - find_package(Protobuf REQUIRED) - endif() - list(APPEND base_DEPS protobuf::libprotobuf-lite) -endif() - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib - ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/lib -) if(USE_SYSTEMD) find_package(Systemd REQUIRED) - list(APPEND base_DEPS Systemd) - include_directories(SYSTEM ${Systemd_INCLUDE_DIRS}) - add_compile_definitions(HAVE_SYSTEMD) endif() find_package(Editline) -if(EDITLINE_FOUND) - list(APPEND base_DEPS ${EDITLINE_LIBRARIES}) - include_directories(SYSTEM ${EDITLINE_INCLUDE_DIR}) -endif() - -if(TERMCAP_FOUND) - list(APPEND base_DEPS ${TERMCAP_LIBRARIES}) - include_directories(SYSTEM ${TERMCAP_INCLUDE_DIR}) -endif() - -if(WIN32) - list(APPEND base_DEPS ws2_32 dbghelp shlwapi msi) -endif() set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/icinga2") @@ -381,8 +346,7 @@ if(NOT HAVE_COUNTER_MACRO) message(FATAL_ERROR "Your C/C++ compiler does not support the __COUNTER__ macro.") endif() -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DI2_DEBUG") -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DI2_DEBUG") +add_compile_definitions($<$:I2_DEBUG>) check_function_exists(vfork HAVE_VFORK) check_function_exists(backtrace_symbols HAVE_BACKTRACE_SYMBOLS) @@ -396,10 +360,11 @@ check_library_exists(dl dladdr "dlfcn.h" HAVE_DLADDR) check_library_exists(execinfo backtrace_symbols "" HAVE_LIBEXECINFO) check_include_file_cxx(cxxabi.h HAVE_CXXABI_H) -if(HAVE_LIBEXECINFO) - set(HAVE_BACKTRACE_SYMBOLS TRUE) - list(APPEND base_DEPS execinfo) -endif() +# TODO: +# if(HAVE_LIBEXECINFO) +# set(HAVE_BACKTRACE_SYMBOLS TRUE) +# list(APPEND base_DEPS execinfo) +# endif() if(NOT WIN32) # boost::stacktrace uses _Unwind_Backtrace which is only exposed if _GNU_SOURCE is defined on most systems diff --git a/cmake/FindJSON.cmake b/cmake/FindJSON.cmake deleted file mode 100644 index b7d5d79d203..00000000000 --- a/cmake/FindJSON.cmake +++ /dev/null @@ -1,9 +0,0 @@ -FIND_PATH (JSON_INCLUDE json.hpp HINTS "${PROJECT_SOURCE_DIR}/third-party/nlohmann_json") - -if (JSON_INCLUDE) - set(JSON_BuildTests OFF CACHE INTERNAL "") - - message(STATUS "Found JSON: ${JSON_INCLUDE}" ) -else () - message(FATAL_ERROR "Unable to include json.hpp") -endif () diff --git a/cmake/FindUTF8CPP.cmake b/cmake/FindUTF8CPP.cmake deleted file mode 100644 index b00035357a3..00000000000 --- a/cmake/FindUTF8CPP.cmake +++ /dev/null @@ -1,7 +0,0 @@ -FIND_PATH (UTF8CPP_INCLUDE utf8.h HINTS "${PROJECT_SOURCE_DIR}/third-party/utf8cpp/source") - -if (UTF8CPP_INCLUDE) - message(STATUS "Found UTF8CPP: ${UTF8CPP_INCLUDE}" ) -else () - message(FATAL_ERROR "Unable to include utf8.h") -endif () diff --git a/config.h.cmake b/config.h.cmake index 8daab077d74..b58c378c5a7 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -12,7 +12,6 @@ #cmakedefine HAVE_PTHREAD_CREATE #cmakedefine HAVE_PTHREAD_SET_NAME_NP #cmakedefine HAVE_PTHREAD_SETNAME_NP -#cmakedefine HAVE_EDITLINE #cmakedefine ICINGA2_UNITY_BUILD #cmakedefine ICINGA2_STACKTRACE_USE_BACKTRACE_SYMBOLS diff --git a/icinga-app/CMakeLists.txt b/icinga-app/CMakeLists.txt index 88ad8bfdc2e..8b278c81040 100644 --- a/icinga-app/CMakeLists.txt +++ b/icinga-app/CMakeLists.txt @@ -1,80 +1,67 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -if(MSVC) - set(WindowsSources icinga.rc) -else() - set(WindowsSources "") -endif() - -set(icingaloader_SOURCES +add_executable(icinga-app icinga.cpp - ${WindowsSources} ) -add_library(icingaloader OBJECT ${icingaloader_SOURCES}) -add_dependencies(icingaloader base config cli) - -set_target_properties ( - icingaloader PROPERTIES - FOLDER Lib +target_link_libraries(icinga-app PUBLIC + base + config + cli + icinga + methods + remote + Boost::program_options ) -include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) +# TODO: MSVC same as WIN32 or is mingwc a reasonable possibility? +if(MSVC) + target_sources(icinga-app PRIVATE + icinga.rc + ) +endif() if(ICINGA2_WITH_CHECKER) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC checker) endif() if(ICINGA2_WITH_COMPAT) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC compat) endif() if(ICINGA2_WITH_MYSQL OR ICINGA2_WITH_PGSQL) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC db_ido) endif() if(ICINGA2_WITH_MYSQL) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC db_ido_mysql) endif() if(ICINGA2_WITH_PGSQL) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC db_ido_pgsql) endif() if(ICINGA2_WITH_LIVESTATUS) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC livestatus) endif() if(ICINGA2_WITH_NOTIFICATION) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC notification) endif() if(ICINGA2_WITH_OPENTELEMETRY) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC otel) endif() if(ICINGA2_WITH_PERFDATA) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC perfdata) endif() if(ICINGA2_WITH_ICINGADB) - list(APPEND icinga_app_SOURCES $) + target_link_libraries(icinga-app PUBLIC icingadb) endif() -add_executable(icinga-app - $ - ${base_OBJS} - $ - $ - $ - $ - $ - ${icinga_app_SOURCES} -) - -target_link_libraries(icinga-app ${base_DEPS}) - set_target_properties ( icinga-app PROPERTIES FOLDER Bin diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index 3f41b8bfb9b..c8948ac4e6c 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -1,6 +1,7 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later +# TODO: Make mkclass_target add targets to link against mkclass_target(application.ti application-ti.cpp application-ti.hpp) mkclass_target(configobject.ti configobject-ti.cpp configobject-ti.hpp) mkclass_target(configuration.ti configuration-ti.cpp configuration-ti.hpp) @@ -13,7 +14,7 @@ mkclass_target(perfdatavalue.ti perfdatavalue-ti.cpp perfdatavalue-ti.hpp) mkclass_target(streamlogger.ti streamlogger-ti.cpp streamlogger-ti.hpp) mkclass_target(sysloglogger.ti sysloglogger-ti.cpp sysloglogger-ti.hpp) -set(base_SOURCES +add_library(base OBJECT i2-base.hpp application.cpp application.hpp application-ti.hpp application-version.cpp application-environment.cpp array.cpp array.hpp array-script.cpp @@ -95,9 +96,38 @@ set(base_SOURCES workqueue.cpp workqueue.hpp ) +target_include_directories(base + PUBLIC + ${CMAKE_SOURCE_DIR}/lib + ${CMAKE_BINARY_DIR}/lib + # TODO: Make this its own library we can link against here + ${CMAKE_BINARY_DIR} +) + +set_source_files_properties(application-version.cpp + PROPERTIES + SKIP_UNITY_BUILD_INCLUSION TRUE +) + if(WIN32) mkclass_target(windowseventloglogger.ti windowseventloglogger-ti.cpp windowseventloglogger-ti.hpp) - list(APPEND base_SOURCES windowseventloglogger.cpp windowseventloglogger.hpp windowseventloglogger-ti.hpp) + target_sources(base PRIVATE + windowseventloglogger.cpp + windowseventloglogger.hpp + windowseventloglogger-ti.hpp + ) + + target_compile_definitions(base PUBLIC + NOMINMAX + WIN32_LEAN_AND_MEAN + ) + + target_link_libraries(base PUBLIC + ws2_32 + dbghelp + shlwapi + msi + ) # Generate a DLL containing message definitions for the Windows Event Viewer. # See also: https://docs.microsoft.com/en-us/windows/win32/eventlog/reporting-an-event @@ -107,9 +137,9 @@ if(WIN32) DEPENDS windowseventloglogger-provider.mc ) - list(APPEND base_SOURCES windowseventloglogger-provider.h) - - add_compile_definitions(WIN32_LEAN_AND_MEAN NOMINMAX) + target_sources(base PRIVATE + windowseventloglogger-provider.h + ) add_custom_command( OUTPUT windowseventloglogger-provider.res @@ -124,31 +154,33 @@ if(WIN32) install(TARGETS eventprovider LIBRARY DESTINATION ${CMAKE_INSTALL_SBINDIR}) endif() -set_property( - SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/application-version.cpp ${CMAKE_CURRENT_SOURCE_DIR}/journaldlogger.cpp - PROPERTY EXCLUDE_UNITY_BUILD TRUE +target_link_libraries(base PUBLIC + ${CMAKE_DL_LIBS} + mmatch + socketpair + nlohmann_json + utf8cpp + Boost::context + Boost::coroutine + Boost::filesystem + Boost::regex + Boost::thread + Boost::iostreams + OpenSSL::SSL ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(base base base_SOURCES) -endif() - if(USE_SYSTEMD) - set_property( - SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/journaldlogger.cpp - APPEND PROPERTY COMPILE_DEFINITIONS + target_link_libraries(base PUBLIC + Systemd + ) + + # TODO: Decide if this is any better than setting it in the source file directly. + set_source_files_properties(journaldlogger.cpp PROPERTIES + COMPILE_DEFINITIONS SD_JOURNAL_SUPPRESS_LOCATION ) endif() -add_library(base OBJECT ${base_SOURCES}) - -include_directories(SYSTEM ${icinga2_SOURCE_DIR}/third-party/mmatch) -link_directories(${icinga2_BINARY_DIR}/third-party/mmatch) - -include_directories(SYSTEM ${icinga2_SOURCE_DIR}/third-party/socketpair) -link_directories(${icinga2_BINARY_DIR}/third-party/socketpair) - set_target_properties ( base PROPERTIES FOLDER Lib diff --git a/lib/checker/CMakeLists.txt b/lib/checker/CMakeLists.txt index 5fc90efb0a9..7bc9c3d4b0b 100644 --- a/lib/checker/CMakeLists.txt +++ b/lib/checker/CMakeLists.txt @@ -3,17 +3,16 @@ mkclass_target(checkercomponent.ti checkercomponent-ti.cpp checkercomponent-ti.hpp) -set(checker_SOURCES +add_library(checker OBJECT checkercomponent.cpp checkercomponent.hpp checkercomponent-ti.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(checker checker checker_SOURCES) -endif() - -add_library(checker OBJECT ${checker_SOURCES}) - -add_dependencies(checker base config icinga remote) +target_link_libraries(checker + base + config + icinga + remote +) set_target_properties ( checker PROPERTIES diff --git a/lib/cli/CMakeLists.txt b/lib/cli/CMakeLists.txt index e53ac571aca..f08f577506b 100644 --- a/lib/cli/CMakeLists.txt +++ b/lib/cli/CMakeLists.txt @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -set(cli_SOURCES +add_library(cli OBJECT i2-cli.hpp apisetupcommand.cpp apisetupcommand.hpp apisetuputility.cpp apisetuputility.hpp @@ -36,13 +36,16 @@ set(cli_SOURCES variableutility.cpp variableutility.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(cli cli cli_SOURCES) -endif() - -add_library(cli OBJECT ${cli_SOURCES}) +target_link_libraries(cli PUBLIC + base + config + icinga + remote +) -add_dependencies(cli base config icinga remote) +if(Editline_FOUND) + target_link_libraries(cli PUBLIC Editline) +endif() set_target_properties ( cli PROPERTIES diff --git a/lib/compat/CMakeLists.txt b/lib/compat/CMakeLists.txt index a80231b1c19..3ca22e63bd4 100644 --- a/lib/compat/CMakeLists.txt +++ b/lib/compat/CMakeLists.txt @@ -4,18 +4,16 @@ mkclass_target(compatlogger.ti compatlogger-ti.cpp compatlogger-ti.hpp) mkclass_target(externalcommandlistener.ti externalcommandlistener-ti.cpp externalcommandlistener-ti.hpp) -set(compat_SOURCES +add_library(compat OBJECT compatlogger.cpp compatlogger.hpp compatlogger-ti.hpp externalcommandlistener.cpp externalcommandlistener.hpp externalcommandlistener-ti.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(compat compat compat_SOURCES) -endif() - -add_library(compat OBJECT ${compat_SOURCES}) - -add_dependencies(compat base config icinga) +target_link_libraries(compat PUBLIC + base + config + icinga +) set_target_properties ( compat PROPERTIES diff --git a/lib/config/CMakeLists.txt b/lib/config/CMakeLists.txt index e75e203be13..651215d2327 100644 --- a/lib/config/CMakeLists.txt +++ b/lib/config/CMakeLists.txt @@ -5,10 +5,10 @@ find_package(BISON 2.3.0 REQUIRED) find_package(FLEX 2.5.31 REQUIRED) bison_target(config_parser config_parser.yy ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc) -set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc PROPERTY EXCLUDE_UNITY_BUILD TRUE) +set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc PROPERTY SKIP_UNITY_BUILD_INCLUSION True) flex_target(config_lexer config_lexer.ll ${CMAKE_CURRENT_BINARY_DIR}/config_lexer.cc) -set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_lexer.cc PROPERTY EXCLUDE_UNITY_BUILD TRUE) +set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_lexer.cc PROPERTY SKIP_UNITY_BUILD_INCLUSION True) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc PROPERTY COMPILE_FLAGS "-Wno-deprecated-register -Wno-parentheses-equality -Wno-unused-function") @@ -17,30 +17,32 @@ endif() add_flex_bison_dependency(config_lexer config_parser) -include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) - -set(config_SOURCES +add_library(config OBJECT i2-config.hpp activationcontext.cpp activationcontext.hpp applyrule.cpp applyrule-targeted.cpp applyrule.hpp configcompiler.cpp configcompiler.hpp configcompilercontext.cpp configcompilercontext.hpp + activationcontext.hpp + applyrule.hpp + configcompiler.hpp + configcompilercontext.hpp configfragment.hpp configitem.cpp configitem.hpp configitembuilder.cpp configitembuilder.hpp expression.cpp expression.hpp objectrule.cpp objectrule.hpp + configitem.hpp + configitembuilder.hpp + expression.hpp + objectrule.hpp vmops.hpp ${FLEX_config_lexer_OUTPUTS} ${BISON_config_parser_OUTPUTS} ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(config config config_SOURCES) -endif() - -add_library(config OBJECT ${config_SOURCES}) - -add_dependencies(config base) +target_link_libraries(config PUBLIC + base +) set_target_properties ( config PROPERTIES diff --git a/lib/db_ido/CMakeLists.txt b/lib/db_ido/CMakeLists.txt index 6e7d0c452d1..8e88e3a3eaf 100644 --- a/lib/db_ido/CMakeLists.txt +++ b/lib/db_ido/CMakeLists.txt @@ -5,7 +5,7 @@ mkclass_target(dbconnection.ti dbconnection-ti.cpp dbconnection-ti.hpp) mkembedconfig_target(db_ido-itl.conf db_ido-itl.cpp) -set(db_ido_SOURCES +add_library(db_ido OBJECT i2-db_ido.hpp db_ido-itl.cpp commanddbobject.cpp commanddbobject.hpp dbconnection.cpp dbconnection.hpp dbconnection-ti.hpp @@ -27,13 +27,12 @@ set(db_ido_SOURCES zonedbobject.cpp zonedbobject.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(db_ido db_ido db_ido_SOURCES) -endif() - -add_library(db_ido OBJECT ${db_ido_SOURCES}) - -add_dependencies(db_ido base config icinga remote) +target_link_libraries(db_ido PUBLIC + base + config + icinga + remote +) set_target_properties ( db_ido PROPERTIES diff --git a/lib/db_ido_mysql/CMakeLists.txt b/lib/db_ido_mysql/CMakeLists.txt index dde48d8284a..41c8ea00bbc 100644 --- a/lib/db_ido_mysql/CMakeLists.txt +++ b/lib/db_ido_mysql/CMakeLists.txt @@ -3,19 +3,17 @@ mkclass_target(idomysqlconnection.ti idomysqlconnection-ti.cpp idomysqlconnection-ti.hpp) -set(db_ido_mysql_SOURCES +add_library(db_ido_mysql OBJECT idomysqlconnection.cpp idomysqlconnection.hpp idomysqlconnection-ti.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(db_ido_mysql db_ido_mysql db_ido_mysql_SOURCES) -endif() - -add_library(db_ido_mysql OBJECT ${db_ido_mysql_SOURCES}) - -include_directories(SYSTEM ${MYSQL_INCLUDE_DIR}) - -add_dependencies(db_ido_mysql base config icinga db_ido) +target_link_libraries(db_ido_mysql PUBLIC + base + config + icinga + db_ido + MySQL +) set_target_properties ( db_ido_mysql PROPERTIES diff --git a/lib/db_ido_pgsql/CMakeLists.txt b/lib/db_ido_pgsql/CMakeLists.txt index 3fcdf17d479..7cb4ce69be2 100644 --- a/lib/db_ido_pgsql/CMakeLists.txt +++ b/lib/db_ido_pgsql/CMakeLists.txt @@ -3,19 +3,15 @@ mkclass_target(idopgsqlconnection.ti idopgsqlconnection-ti.cpp idopgsqlconnection-ti.hpp) -set(db_ido_pgsql_SOURCES +add_library(db_ido_pgsql OBJECT idopgsqlconnection.cpp idopgsqlconnection.hpp idopgsqlconnection-ti.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(db_ido_pgsql db_ido_pgsql db_ido_pgsql_SOURCES) -endif() - -add_library(db_ido_pgsql OBJECT ${db_ido_pgsql_SOURCES}) - -include_directories(SYSTEM ${PostgreSQL_INCLUDE_DIRS}) - -add_dependencies(db_ido_pgsql base config icinga db_ido) +target_link_libraries(db_ido_pgsql PUBLIC + base + db_ido + PostgreSQL +) set_target_properties ( db_ido_pgsql PROPERTIES diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index 53aa214b2c9..8369a52ba33 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -24,7 +24,7 @@ mkclass_target(user.ti user-ti.cpp user-ti.hpp) mkembedconfig_target(icinga-itl.conf icinga-itl.cpp) -set(icinga_SOURCES +add_library(icinga OBJECT i2-icinga.hpp icinga-itl.cpp apiactions.cpp apiactions.hpp apievents.cpp apievents.hpp @@ -63,13 +63,11 @@ set(icinga_SOURCES usergroup.cpp usergroup.hpp usergroup-ti.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(icinga icinga icinga_SOURCES) -endif() - -add_library(icinga OBJECT ${icinga_SOURCES}) - -add_dependencies(icinga base config remote) +target_link_libraries(icinga PUBLIC + base + config + remote +) set_target_properties ( icinga PROPERTIES diff --git a/lib/icingadb/CMakeLists.txt b/lib/icingadb/CMakeLists.txt index 49ac16b89a4..72827649736 100644 --- a/lib/icingadb/CMakeLists.txt +++ b/lib/icingadb/CMakeLists.txt @@ -5,20 +5,17 @@ mkclass_target(icingadb.ti icingadb-ti.cpp icingadb-ti.hpp) mkembedconfig_target(icingadb-itl.conf icingadb-itl.cpp) -set(icingadb_SOURCES +add_library(icingadb OBJECT icingadb.cpp icingadb-objects.cpp icingadb-stats.cpp icingadb-utility.cpp icingadb-worker.cpp redisconnection.cpp icingadb-ti.hpp icingadbchecktask.cpp icingadb-itl.cpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(icingadb icingadb icingadb_SOURCES) -endif() - -add_library(icingadb OBJECT ${icingadb_SOURCES}) - -include_directories(SYSTEM ${icinga2_SOURCE_DIR}/third-party) - -add_dependencies(icingadb base config icinga remote) +target_link_libraries(icingadb PUBLIC + base + config + icinga + remote +) set_target_properties ( icingadb PROPERTIES diff --git a/lib/livestatus/CMakeLists.txt b/lib/livestatus/CMakeLists.txt index 3d8e3b27816..ab4ca02dbc2 100644 --- a/lib/livestatus/CMakeLists.txt +++ b/lib/livestatus/CMakeLists.txt @@ -3,7 +3,7 @@ mkclass_target(livestatuslistener.ti livestatuslistener-ti.cpp livestatuslistener-ti.hpp) -set(livestatus_SOURCES +add_library(livestatus OBJECT i2-livestatus.hpp aggregator.cpp aggregator.hpp andfilter.cpp andfilter.hpp @@ -43,13 +43,12 @@ set(livestatus_SOURCES zonestable.cpp zonestable.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(livestatus livestatus livestatus_SOURCES) -endif() - -add_library(livestatus OBJECT ${livestatus_SOURCES}) - -add_dependencies(livestatus base config icinga remote) +target_link_libraries(livestatus PUBLIC + base + config + icinga + remote +) set_target_properties ( livestatus PROPERTIES diff --git a/lib/methods/CMakeLists.txt b/lib/methods/CMakeLists.txt index 28908ad1b78..0301ac1e631 100644 --- a/lib/methods/CMakeLists.txt +++ b/lib/methods/CMakeLists.txt @@ -3,7 +3,7 @@ mkembedconfig_target(methods-itl.conf methods-itl.cpp) -set(methods_SOURCES +add_library(methods OBJECT i2-methods.hpp methods-itl.cpp clusterchecktask.cpp clusterchecktask.hpp clusterzonechecktask.cpp clusterzonechecktask.hpp @@ -21,13 +21,11 @@ set(methods_SOURCES sleepchecktask.cpp sleepchecktask.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(methods methods methods_SOURCES) -endif() - -add_library(methods OBJECT ${methods_SOURCES}) - -add_dependencies(methods base config icinga) +target_link_libraries(methods PUBLIC + base + config + icinga +) set_target_properties ( methods PROPERTIES diff --git a/lib/mysql_shim/CMakeLists.txt b/lib/mysql_shim/CMakeLists.txt index d27fa1f6f58..de034f29fcd 100644 --- a/lib/mysql_shim/CMakeLists.txt +++ b/lib/mysql_shim/CMakeLists.txt @@ -1,23 +1,22 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -include_directories(SYSTEM ${MYSQL_INCLUDE_DIR}) - -set(mysql_shim_SOURCES +add_library(mysql_shim SHARED mysql_shim.def mysqlinterface.cpp mysqlinterface.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(mysql_shim mysql_shim mysql_shim_SOURCES) -endif() - -add_library(mysql_shim SHARED ${mysql_shim_SOURCES}) +target_link_libraries(mysql_shim PUBLIC + MySQL +) include(GenerateExportHeader) generate_export_header(mysql_shim) -target_link_libraries(mysql_shim ${MYSQL_LIB}) +target_include_directories(mysql_shim PRIVATE + ${CMAKE_SOURCE_DIR}/lib + ${CMAKE_BINARY_DIR}/lib +) set_target_properties ( mysql_shim PROPERTIES diff --git a/lib/mysql_shim/mysqlinterface.cpp b/lib/mysql_shim/mysqlinterface.cpp index c03c590189e..ddf4d76f8e0 100644 --- a/lib/mysql_shim/mysqlinterface.cpp +++ b/lib/mysql_shim/mysqlinterface.cpp @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2012 Icinga GmbH // SPDX-License-Identifier: GPL-2.0-or-later -#include "mysql_shim/mysqlinterface.hpp" +#include "mysqlinterface.hpp" using namespace icinga; diff --git a/lib/notification/CMakeLists.txt b/lib/notification/CMakeLists.txt index d3f69337c52..03610171f47 100644 --- a/lib/notification/CMakeLists.txt +++ b/lib/notification/CMakeLists.txt @@ -3,17 +3,15 @@ mkclass_target(notificationcomponent.ti notificationcomponent-ti.cpp notificationcomponent-ti.hpp) -set(notification_SOURCES +add_library(notification OBJECT notificationcomponent.cpp notificationcomponent.hpp notificationcomponent-ti.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(notification notification notification_SOURCES) -endif() - -add_library(notification OBJECT ${notification_SOURCES}) - -add_dependencies(notification base config icinga) +target_link_libraries(notification PUBLIC + base + config + icinga +) set_target_properties ( notification PROPERTIES diff --git a/lib/otel/CMakeLists.txt b/lib/otel/CMakeLists.txt index a73cd57a64e..762b3952771 100644 --- a/lib/otel/CMakeLists.txt +++ b/lib/otel/CMakeLists.txt @@ -2,7 +2,17 @@ # SPDX-License-Identifier: GPL-3.0-or-later set(ICINGA2_OPENTELEMETRY_PROTOS_DIR "${icinga2_SOURCE_DIR}/third-party/opentelemetry-proto") + +add_library(otel OBJECT + otel.cpp otel.hpp + "${ICINGA2_OPENTELEMETRY_PROTOS_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.proto" + "${ICINGA2_OPENTELEMETRY_PROTOS_DIR}/opentelemetry/proto/common/v1/common.proto" + "${ICINGA2_OPENTELEMETRY_PROTOS_DIR}/opentelemetry/proto/metrics/v1/metrics.proto" + "${ICINGA2_OPENTELEMETRY_PROTOS_DIR}/opentelemetry/proto/resource/v1/resource.proto" +) + protobuf_generate( + TARGET otel LANGUAGE cpp # According to the Protobuf docs[^1], the Protobuf compiler generates with the "LITE_RUNTIME" option much # smaller code than the default optimze_for=SPEED option, which includes code for reflection, descriptors, @@ -15,26 +25,17 @@ protobuf_generate( # # [^1]: https://protobuf.dev/programming-guides/proto3/#options PLUGIN_OPTIONS lite - OUT_VAR otel_PROTO_SRCS IMPORT_DIRS "${ICINGA2_OPENTELEMETRY_PROTOS_DIR}" - PROTOS - "${ICINGA2_OPENTELEMETRY_PROTOS_DIR}/opentelemetry/proto/collector/metrics/v1/metrics_service.proto" - "${ICINGA2_OPENTELEMETRY_PROTOS_DIR}/opentelemetry/proto/common/v1/common.proto" - "${ICINGA2_OPENTELEMETRY_PROTOS_DIR}/opentelemetry/proto/metrics/v1/metrics.proto" - "${ICINGA2_OPENTELEMETRY_PROTOS_DIR}/opentelemetry/proto/resource/v1/resource.proto" ) -set(otel_SOURCES - otel.cpp otel.hpp - ${otel_PROTO_SRCS} +target_link_libraries(otel PUBLIC + base + config + protobuf::libprotobuf-lite ) -add_library(otel OBJECT ${otel_SOURCES}) -add_dependencies(otel base remote) -target_include_directories(otel - SYSTEM PUBLIC - $ - ${CMAKE_CURRENT_BINARY_DIR} +target_include_directories(otel PUBLIC + ${CMAKE_CURRENT_BINARY_DIR} ) set_target_properties( diff --git a/lib/perfdata/CMakeLists.txt b/lib/perfdata/CMakeLists.txt index c867911be4a..dc4969dad6a 100644 --- a/lib/perfdata/CMakeLists.txt +++ b/lib/perfdata/CMakeLists.txt @@ -10,7 +10,7 @@ mkclass_target(elasticsearchwriter.ti elasticsearchwriter-ti.cpp elasticsearchwr mkclass_target(opentsdbwriter.ti opentsdbwriter-ti.cpp opentsdbwriter-ti.hpp) mkclass_target(perfdatawriter.ti perfdatawriter-ti.cpp perfdatawriter-ti.hpp) -set(perfdata_SOURCES +add_library(perfdata OBJECT elasticsearchwriter.cpp elasticsearchwriter.hpp elasticsearchwriter-ti.hpp gelfwriter.cpp gelfwriter.hpp gelfwriter-ti.hpp graphitewriter.cpp graphitewriter.hpp graphitewriter-ti.hpp @@ -22,33 +22,17 @@ set(perfdata_SOURCES perfdatawriterconnection.cpp perfdatawriterconnection.hpp ) +target_link_libraries(perfdata PUBLIC + base + icinga +) + if(ICINGA2_WITH_OPENTELEMETRY) mkclass_target(otlpmetricswriter.ti otlpmetricswriter-ti.cpp otlpmetricswriter-ti.hpp) - list(APPEND perfdata_SOURCES + target_sources(perfdata PRIVATE otlpmetricswriter.cpp otlpmetricswriter.hpp otlpmetricswriter-ti.hpp ) -endif() - -if(ICINGA2_UNITY_BUILD) - mkunity_target(perfdata perfdata perfdata_SOURCES) -endif() - -add_library(perfdata OBJECT ${perfdata_SOURCES}) - -add_dependencies(perfdata base config icinga) -if(ICINGA2_WITH_OPENTELEMETRY) - add_dependencies(perfdata otel) - # All the Protobuf generated files within the otel target use relative include paths that won't be - # resolved unless we also add the include directories of the otel target. Meaning, we include some - # of the header files (not the generated ones) from otel within the otlpwriter and these headers - # again include the generated headers and the generated headers in return include other generated - # headers using relative paths like this: - # #include "opentelemetry/proto/metrics/v1/metrics.pb.h" - # - # This path can only be resolved if the parent directory of "opentelemetry" is added to the compiler's - # include search paths, which is done by the CMakefile of the otel target and we only need to propagate - # its include directories to the perfdata target. - target_include_directories(perfdata PUBLIC $) + target_link_libraries(perfdata PUBLIC otel) endif() set_target_properties ( diff --git a/lib/pgsql_shim/CMakeLists.txt b/lib/pgsql_shim/CMakeLists.txt index 8e3eae87a0c..f1b851cf564 100644 --- a/lib/pgsql_shim/CMakeLists.txt +++ b/lib/pgsql_shim/CMakeLists.txt @@ -1,24 +1,22 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -link_directories(${PostgreSQL_LIBRARY_DIRS}) -include_directories(SYSTEM ${PostgreSQL_INCLUDE_DIRS}) - -set(pgsql_shim_SOURCES +add_library(pgsql_shim SHARED pgsql_shim.def pgsqlinterface.cpp pgsqlinterface.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(pgsql_shim pgsql_shim pgsql_shim_SOURCES) -endif() - -add_library(pgsql_shim SHARED ${pgsql_shim_SOURCES}) +target_link_libraries(pgsql_shim PUBLIC + PostgreSQL +) include(GenerateExportHeader) generate_export_header(pgsql_shim) -target_link_libraries(pgsql_shim ${PostgreSQL_LIBRARIES}) +target_include_directories(pgsql_shim PRIVATE + ${CMAKE_SOURCE_DIR}/lib + ${CMAKE_BINARY_DIR}/lib +) set_target_properties ( pgsql_shim PROPERTIES diff --git a/lib/remote/CMakeLists.txt b/lib/remote/CMakeLists.txt index b7d0fc052a3..d97c744ca22 100644 --- a/lib/remote/CMakeLists.txt +++ b/lib/remote/CMakeLists.txt @@ -6,7 +6,7 @@ mkclass_target(apiuser.ti apiuser-ti.cpp apiuser-ti.hpp) mkclass_target(endpoint.ti endpoint-ti.cpp endpoint-ti.hpp) mkclass_target(zone.ti zone-ti.cpp zone-ti.hpp) -set(remote_SOURCES +add_library(remote OBJECT i2-remote.hpp actionshandler.cpp actionshandler.hpp apiaction.cpp apiaction.hpp @@ -47,13 +47,11 @@ set(remote_SOURCES zone.cpp zone.hpp zone-ti.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(remote remote remote_SOURCES) -endif() - -add_library(remote OBJECT ${remote_SOURCES}) - -add_dependencies(remote base config) +target_link_libraries(remote PUBLIC + base + config + Boost::coroutine +) set_target_properties ( remote PROPERTIES diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 26420e48701..eb1429cf2e3 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -3,15 +3,20 @@ add_executable(check_nscp_api check_nscp_api.cpp - ${base_OBJS} - $ - $ ) -target_link_libraries(check_nscp_api ${base_DEPS}) + +target_link_libraries(check_nscp_api PRIVATE + base + config + remote + Boost::program_options +) + set_target_properties ( check_nscp_api PROPERTIES DEFINE_SYMBOL I2_PLUGINS_BUILD - FOLDER Plugins) + FOLDER Plugins +) # Prefer the PluginDir constant which is set to /sbin on Windows @@ -22,13 +27,20 @@ else() endif() if (WIN32) + # TODO: What is this for? add_definitions(-DUNICODE -D_UNICODE) - set(thresholds_SOURCES + add_library(thresholds OBJECT thresholds.cpp thresholds.hpp ) - add_library(thresholds ${thresholds_SOURCES}) + target_link_libraries(thresholds PUBLIC + Boost::boost + ) + + target_include_directories(thresholds PUBLIC + ${CMAKE_SOURCE_DIR} + ) set_target_properties( thresholds PROPERTIES @@ -45,7 +57,7 @@ if (WIN32) string(REGEX REPLACE ".cpp\$" "" check_OUT "${source}") add_executable(${check_OUT} ${source}) - target_link_libraries(${check_OUT} thresholds shlwapi.lib ${Boost_PROGRAM_OPTIONS_LIBRARY}) + target_link_libraries(${check_OUT} thresholds shlwapi.lib Boost::program_options) set_target_properties( ${check_OUT} PROPERTIES @@ -59,7 +71,7 @@ if (WIN32) target_link_libraries(check_perfmon pdh.lib) target_link_libraries(check_ping ntdll.lib iphlpapi.lib ws2_32.lib) target_link_libraries(check_procs pdh.lib) - target_link_libraries(check_uptime ${Boost_SYSTEM_LIBRARY}) + target_link_libraries(check_uptime Boost::chrono) target_link_libraries(check_users wtsapi32.lib) install( diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 94296c38bd6..09576eb1cd0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,17 +3,20 @@ include(DiscoverBoostTests) -add_library(testdeps INTERFACE) +add_library(testdeps OBJECT + test-runner.cpp + test-ctest.cpp +) if(NOT Boost_UNIT_TEST_FRAMEWORK_LIBRARY) find_package(Boost QUIET COMPONENTS unit_test_framework) endif() if(Boost_UNIT_TEST_FRAMEWORK_LIBRARY) - target_link_libraries(testdeps - INTERFACE - ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} + target_link_libraries(testdeps PUBLIC + Boost::unit_test_framework ) + if(NOT Boost_USE_STATIC_LIBS) set(BOOST_TEST_DYN_LINK ON) endif() @@ -21,76 +24,67 @@ else() set(BOOST_TEST_USE_INCLUDED ON) endif() -target_link_libraries(testdeps - INTERFACE - ${base_DEPS} -) - configure_file(BoostTestConfig.h.in BoostTestTargetConfig.h @ONLY) target_include_directories(testdeps - INTERFACE + PUBLIC "${CMAKE_CURRENT_BINARY_DIR}" + # TODO: This is ugly, but needed for "test/*.hpp" includes + "${CMAKE_SOURCE_DIR}" ) -target_sources(testdeps INTERFACE - test-runner.cpp - test-ctest.cpp +set_target_properties(testdeps PROPERTIES + UNITY_BUILD False ) -Set(types_test_SOURCES +# In order to test the order of all Icinga 2 config type load dependencies, we need to link against all the libraries, +# but this results in boost signals e.g. in dbevents.cpp being triggered by icinga-checkresult.cpp test cases that +# only pass partially initialised objects. Therefore, the types test cases are decoupled from base and moved to a +# separate executable to not crash the base test cases. +add_executable(testtypes icingaapplication-fixture.cpp base-type.cpp - ${base_OBJS} - $ - $ - $ - $ +) + +target_link_libraries(testtypes PUBLIC + testdeps + base + config + icinga + remote ) if(ICINGA2_WITH_CHECKER) - list(APPEND types_test_SOURCES $) + target_link_libraries(testtypes PUBLIC checker) endif() if(ICINGA2_WITH_MYSQL) - list(APPEND types_test_SOURCES $ $) + target_link_libraries(testtypes PUBLIC db_ido db_ido_mysql) endif() if(ICINGA2_WITH_PGSQL) - list(APPEND types_test_SOURCES $ $) + target_link_libraries(testtypes PUBLIC db_ido db_ido_pgsql) endif() if(ICINGA2_WITH_ICINGADB) - list(APPEND types_test_SOURCES $) + target_link_libraries(testtypes PUBLIC icingadb) endif() if(ICINGA2_WITH_NOTIFICATION) - list(APPEND types_test_SOURCES $) + target_link_libraries(testtypes PUBLIC notification) endif() if(ICINGA2_WITH_OPENTELEMETRY) - list(APPEND types_test_SOURCES $) + target_link_libraries(testtypes PUBLIC otel) endif() if(ICINGA2_WITH_PERFDATA) - list(APPEND types_test_SOURCES $) + target_link_libraries(testtypes PUBLIC perfdata) endif() -if(ICINGA2_UNITY_BUILD) - mkunity_target(types test types_test_SOURCES) -endif() - -# In order to test the order of all Icinga 2 config type load dependencies, we need to link against all the libraries, -# but this results in boost signals e.g. in dbevents.cpp being triggered by icinga-checkresult.cpp test cases that -# only pass partially initialised objects. Therefore, the types test cases are decoupled from base and moved to a -# separate executable to not crash the base test cases. -add_executable(testtypes - ${types_test_SOURCES} -) -target_link_libraries(testtypes testdeps) target_discover_boost_tests(testtypes) -set(base_test_SOURCES +add_executable(testbase icingaapplication-fixture.cpp utils.cpp base-array.cpp @@ -130,88 +124,74 @@ set(base_test_SOURCES remote-httpmessage.cpp remote-httputility.cpp remote-url.cpp - ${base_OBJS} - $ - $ - $ - $ +) + +target_link_libraries(testbase PUBLIC + testdeps + base + config + icinga + methods + remote ) if(ICINGA2_WITH_NOTIFICATION) - list(APPEND base_test_SOURCES - notification-notificationcomponent.cpp - $ - ) + target_sources(testbase PRIVATE notification-notificationcomponent.cpp) + target_link_libraries(testbase PUBLIC notification) endif() if(ICINGA2_WITH_OPENTELEMETRY) - list(APPEND base_test_SOURCES $) + target_link_libraries(testbase PUBLIC otel) endif() if(ICINGA2_WITH_PERFDATA) - list(APPEND base_test_SOURCES + target_sources(testbase PRIVATE perfdata-elasticsearchwriter.cpp perfdata-gelfwriter.cpp perfdata-graphitewriter.cpp perfdata-influxdbwriter.cpp perfdata-opentsdbwriter.cpp perfdata-perfdatawriterconnection.cpp - $ ) + target_link_libraries(testbase PUBLIC perfdata) endif() -if(ICINGA2_UNITY_BUILD) - mkunity_target(base test base_test_SOURCES) -endif() - -add_executable(testbase - ${base_test_SOURCES} -) -target_link_libraries(testbase testdeps) target_discover_boost_tests(testbase) if(ICINGA2_WITH_LIVESTATUS) - set(livestatus_test_SOURCES + add_executable(testlivestatus icingaapplication-fixture.cpp livestatus-fixture.cpp livestatus.cpp - ${base_OBJS} - $ - $ - $ - $ - $ ) - if(ICINGA2_UNITY_BUILD) - mkunity_target(livestatus test livestatus_test_SOURCES) - endif() - - add_executable(testlivestatus - ${livestatus_test_SOURCES} + target_link_libraries(testlivestatus PUBLIC + testdeps + base + config + remote + icinga + livestatus + methods ) - target_link_libraries(testlivestatus testdeps) target_discover_boost_tests(testlivestatus) endif() -set(icinga_checkable_test_SOURCES +add_executable(icinga_checkable icingaapplication-fixture.cpp icinga-checkable-fixture.cpp icinga-checkable-flapping.cpp - ${base_OBJS} - $ - $ - $ - $ ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(icinga_checkable test icinga_checkable_test_SOURCES) -endif() - -add_executable(icinga_checkable - ${icinga_checkable_test_SOURCES} +target_link_libraries(icinga_checkable PUBLIC + testdeps + base + config + remote + icinga + cli + Boost::program_options ) -target_link_libraries(icinga_checkable testdeps) + target_discover_boost_tests(icinga_checkable) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index c45433c1b7a..46729fe31fa 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -4,3 +4,13 @@ add_subdirectory(mmatch) add_subdirectory(socketpair) + +add_subdirectory(nlohmann_json) + +# TODO: Update vendored version because this one's CMakeLists.txt doesn't support old +# CMake versions anymore +# add_subdirectory(utf8cpp) +add_library(utf8cpp INTERFACE) +target_include_directories(utf8cpp INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/utf8cpp/source +) diff --git a/third-party/cmake/FindMySQL.cmake b/third-party/cmake/FindMySQL.cmake index d3a6e7f2a19..0b7b66061b0 100644 --- a/third-party/cmake/FindMySQL.cmake +++ b/third-party/cmake/FindMySQL.cmake @@ -113,25 +113,28 @@ ENDIF(MYSQL_LIB) IF (MYSQL_INCLUDE_DIR AND MYSQL_LIB_DIR) SET(MYSQL_FOUND TRUE) - INCLUDE_DIRECTORIES(${MYSQL_INCLUDE_DIR}) - LINK_DIRECTORIES(${MYSQL_LIB_DIR}) + add_library(MySQL UNKNOWN IMPORTED) + set_target_properties(MySQL PROPERTIES + IMPORTED_LOCATION ${MYSQL_LIB} + INTERFACE_INCLUDE_DIRECTORIES ${MYSQL_INCLUDE_DIR} + ) FIND_LIBRARY(MYSQL_ZLIB zlib PATHS ${MYSQL_LIB_DIR}) FIND_LIBRARY(MYSQL_YASSL yassl PATHS ${MYSQL_LIB_DIR}) FIND_LIBRARY(MYSQL_TAOCRYPT taocrypt PATHS ${MYSQL_LIB_DIR}) IF (MYSQL_ZLIB) - SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} zlib) + target_link_library(MySQL INTERFACE zlib) ENDIF (MYSQL_ZLIB) IF (MYSQL_YASSL) - SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} yassl) + target_link_library(MySQL INTERFACE yassl) ENDIF (MYSQL_YASSL) IF (MYSQL_TAOCRYPT) - SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} taocrypt) + target_link_library(MySQL INTERFACE taocrypt) ENDIF (MYSQL_TAOCRYPT) # Added needed mysqlclient dependencies on Windows IF (WIN32) - SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} ws2_32) + target_link_library(MySQL INTERFACE ws2_32) ENDIF (WIN32) MESSAGE(STATUS "MySQL Include dir: ${MYSQL_INCLUDE_DIR} library dir: ${MYSQL_LIB_DIR}") diff --git a/third-party/cmake/FindPostgreSQL.cmake b/third-party/cmake/FindPostgreSQL.cmake index 4d213d26a47..57128c3d1db 100644 --- a/third-party/cmake/FindPostgreSQL.cmake +++ b/third-party/cmake/FindPostgreSQL.cmake @@ -177,6 +177,14 @@ if(PostgreSQL_FOUND) set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} ) set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY_TO_FIND}) + add_library(PostgreSQL UNKNOWN IMPORTED) + set_target_properties(PostgreSQL PROPERTIES + IMPORTED_LOCATION "${PostgreSQL_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${PostgreSQL_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${PostgreSQL_LIBRARIES}" + INTERFACE_LINK_DIRECTORIES "${PostgreSQL_LIBRARY_DIRS}" + ) + #message("Final PostgreSQL include dir: ${PostgreSQL_INCLUDE_DIRS}") #message("Final PostgreSQL library dir: ${PostgreSQL_LIBRARY_DIRS}") #message("Final PostgreSQL libraries: ${PostgreSQL_LIBRARIES}") diff --git a/third-party/mmatch/CMakeLists.txt b/third-party/mmatch/CMakeLists.txt index f8bc4acc375..476ab24fc6b 100644 --- a/third-party/mmatch/CMakeLists.txt +++ b/third-party/mmatch/CMakeLists.txt @@ -1,11 +1,16 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -set(mmatch_SOURCES +add_library(mmatch OBJECT mmatch.c mmatch.h ) -add_library(mmatch OBJECT ${mmatch_SOURCES}) +target_include_directories(mmatch + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources(mmatch INTERFACE $) if(NOT MSVC) target_compile_options(mmatch diff --git a/third-party/nlohmann_json/CMakeLists.txt b/third-party/nlohmann_json/CMakeLists.txt new file mode 100644 index 00000000000..bea32887aea --- /dev/null +++ b/third-party/nlohmann_json/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: 2026 Icinga GmbH +# SPDX-License-Identifier: GPL-2.0-or-later + +add_library(nlohmann_json INTERFACE) +target_include_directories(nlohmann_json SYSTEM INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/third-party/socketpair/CMakeLists.txt b/third-party/socketpair/CMakeLists.txt index bd7a093d661..044f8d3b03f 100644 --- a/third-party/socketpair/CMakeLists.txt +++ b/third-party/socketpair/CMakeLists.txt @@ -1,11 +1,16 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -set(socketpair_SOURCES +add_library(socketpair OBJECT socketpair.c socketpair.h ) -add_library(socketpair OBJECT ${socketpair_SOURCES}) +target_include_directories(socketpair + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_sources(socketpair INTERFACE $) set_target_properties ( socketpair PROPERTIES diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index c5b445183ff..8eee0dc8e1e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -3,5 +3,4 @@ add_subdirectory(mkclass) add_subdirectory(mkembedconfig) -add_subdirectory(mkunity) diff --git a/tools/mkclass/CMakeLists.txt b/tools/mkclass/CMakeLists.txt index e210a247b91..2ceaa400487 100644 --- a/tools/mkclass/CMakeLists.txt +++ b/tools/mkclass/CMakeLists.txt @@ -5,7 +5,9 @@ find_package(BISON 2.3.0 REQUIRED) find_package(FLEX 2.5.31 REQUIRED) bison_target(class_parser class_parser.yy ${CMAKE_CURRENT_BINARY_DIR}/class_parser.cc) +set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/class_parser.cc PROPERTY SKIP_UNITY_BUILD_INCLUSION True) flex_target(class_lexer class_lexer.ll ${CMAKE_CURRENT_BINARY_DIR}/class_lexer.cc) +set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/class_lexer.cc PROPERTY SKIP_UNITY_BUILD_INCLUSION True) add_flex_bison_dependency(class_lexer class_parser) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") diff --git a/tools/mkembedconfig/CMakeLists.txt b/tools/mkembedconfig/CMakeLists.txt index 85d9205d4c4..125975ad503 100644 --- a/tools/mkembedconfig/CMakeLists.txt +++ b/tools/mkembedconfig/CMakeLists.txt @@ -20,6 +20,6 @@ macro(MKEMBEDCONFIG_TARGET EmbedInput EmbedOutput) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS mkembedconfig ${EmbedInput} ) - set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${EmbedOutput} PROPERTY EXCLUDE_UNITY_BUILD TRUE) + set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${EmbedOutput} PROPERTY SKIP_UNITY_BUILD_INCLUSION TRUE) endmacro() diff --git a/tools/mkunity/CMakeLists.txt b/tools/mkunity/CMakeLists.txt deleted file mode 100644 index 372cd8a2eda..00000000000 --- a/tools/mkunity/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# SPDX-FileCopyrightText: 2012 Icinga GmbH -# SPDX-License-Identifier: GPL-2.0-or-later - -define_property( - SOURCE - PROPERTY EXCLUDE_UNITY_BUILD - BRIEF_DOCS "Whether to exclude the source file from unity builds" - FULL_DOCS "Specified whether a source file should be excluded from unity builds and should be built separately" -) - -if(ICINGA2_UNITY_BUILD) - set(mkunity_SOURCES - mkunity.c - ) - - add_executable(mkunity ${mkunity_SOURCES}) - - set_target_properties ( - mkunity PROPERTIES - FOLDER Bin - ) - - function(MKUNITY_TARGET Target Prefix UnityInputRef) - set(UnityInput ${${UnityInputRef}}) - set(UnityOutput ${CMAKE_CURRENT_BINARY_DIR}/${Target}_unity.cpp) - set(RealSources "") - set(UnitySources "") - foreach(UnitySource ${UnityInput}) - get_property(SourceExcluded SOURCE ${UnitySource} PROPERTY EXCLUDE_UNITY_BUILD) - if(SourceExcluded MATCHES TRUE OR NOT ${UnitySource} MATCHES "\\.(cpp|cxx|cc)\$") - list(APPEND RealSources ${UnitySource}) - else() - list(APPEND UnitySources ${UnitySource}) - endif() - endforeach() - add_custom_command( - OUTPUT ${UnityOutput} - COMMAND mkunity - ARGS ${Prefix} ${UnitySources} > ${UnityOutput}.tmp - COMMAND ${CMAKE_COMMAND} - ARGS -E copy ${UnityOutput}.tmp ${UnityOutput} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS mkunity ${UnitySources} - ) - list(APPEND RealSources ${UnityOutput}) - set(${UnityInputRef} ${RealSources} PARENT_SCOPE) - endfunction() -endif() diff --git a/tools/mkunity/mkunity.c b/tools/mkunity/mkunity.c deleted file mode 100644 index 2bf6aae245d..00000000000 --- a/tools/mkunity/mkunity.c +++ /dev/null @@ -1,21 +0,0 @@ -// SPDX-FileCopyrightText: 2012 Icinga GmbH -// SPDX-License-Identifier: GPL-2.0-or-later - -#include -#include - -int main(int argc, char **argv) -{ - int i; - - if (argc < 3) { - fprintf(stderr, "Syntax: %s [ ...]\n", argv[0]); - return EXIT_FAILURE; - } - - for (i = 2; i < argc; i++) { - printf("#include \"%s/%s\"\n", argv[1], argv[i]); - } - - return EXIT_SUCCESS; -} From 5d5431bb08dce25aeee6437b9ee22acbadb85d90 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Wed, 8 Jul 2026 15:53:23 +0200 Subject: [PATCH 06/15] Use the proper way of linking thread support --- CMakeLists.txt | 28 ++-------------------------- lib/base/CMakeLists.txt | 1 + 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e269b010481..b4c2b5dc82e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,6 +208,8 @@ add_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED) # Required for Boost v1.74+ add_definitions(-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +find_package(Threads REQUIRED) + find_package(OpenSSL REQUIRED) if(USE_SYSTEMD) @@ -223,18 +225,6 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics -fno-limit-debug-info") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics -fno-limit-debug-info") - - # Clang on Fedora requires -pthread, Apple Clang does not - # AppleClang is available since CMake 3.0.0 - if (NOT CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") - endif() -endif() - -if(CMAKE_C_COMPILER_ID STREQUAL "SunPro") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mt") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mt -library=stlport4") endif() if(CMAKE_C_COMPILER_ID STREQUAL "GNU") @@ -243,20 +233,6 @@ if(CMAKE_C_COMPILER_ID STREQUAL "GNU") if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER_EQUAL "11.0.0") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wrange-loop-construct") endif() - - if(CMAKE_SYSTEM_NAME MATCHES AIX) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -lpthread") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -lpthread") - elseif(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -pthread") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pthread") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lpthread") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lpthread") - set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -lpthread") - else() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -pthread") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pthread") - endif() endif() include(CheckCXXCompilerFlag) diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index c8948ac4e6c..a1a774a0461 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -156,6 +156,7 @@ endif() target_link_libraries(base PUBLIC ${CMAKE_DL_LIBS} + Threads::Threads mmatch socketpair nlohmann_json From 729d7e9b85bbc90bcb08a242a5407a92c18863d9 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Fri, 10 Jul 2026 11:29:23 +0200 Subject: [PATCH 07/15] Use `add_compile_definition()` instead of `deprecated add_definitions()` --- CMakeLists.txt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4c2b5dc82e..b4a6ad956ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -201,12 +201,12 @@ add_compile_definitions(OPENSSL_SUPPRESS_DEPRECATED) # Boost.Coroutine2 (the successor of Boost.Coroutine) # (1) doesn't even exist in old Boost versions and # (2) isn't supported by ASIO, yet. -add_definitions(-DBOOST_COROUTINES_NO_DEPRECATION_WARNING) +add_compile_definitions(BOOST_COROUTINES_NO_DEPRECATION_WARNING) -add_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED) +add_compile_definitions(BOOST_FILESYSTEM_NO_DEPRECATED) # Required for Boost v1.74+ -add_definitions(-DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) +add_compile_definitions(BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT) find_package(Threads REQUIRED) @@ -305,7 +305,11 @@ if(ICINGA2_LTO_BUILD) endif() if(MSVC) - add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS) + add_compile_definitions( + _CRT_SECURE_NO_DEPRECATE + _CRT_NONSTDC_NO_DEPRECATE + _SCL_SECURE_NO_WARNINGS + ) endif() set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Library output path") @@ -344,7 +348,7 @@ check_include_file_cxx(cxxabi.h HAVE_CXXABI_H) if(NOT WIN32) # boost::stacktrace uses _Unwind_Backtrace which is only exposed if _GNU_SOURCE is defined on most systems - add_definitions(-D_GNU_SOURCE) + add_compile_definitions(_GNU_SOURCE) endif() if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") From bfd96dffff173672f86d0adc3f8244a8fc37cc3a Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Fri, 10 Jul 2026 11:29:46 +0200 Subject: [PATCH 08/15] Remove check if override keyword exists (we have C++17 now) --- CMakeLists.txt | 8 -------- 1 file changed, 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4a6ad956ca..2a5bc7dc3e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -376,14 +376,6 @@ if(MSVC) endif() endif() -if(NOT MSVC) - check_cxx_source_compiles("class Base { public: virtual void test(void) { } }; class Derived : public Base { virtual void test(void) override { } }; int main(){}" CXX_FEATURE_OVERRIDE) - - if(NOT CXX_FEATURE_OVERRIDE) - add_definitions("-Doverride=") - endif() -endif() - # Architecture specifics # - Log the target architecture # - ARM needs to link against atomic From dd2f454e6e844290416d2ceaeffa6277d3a57765 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Thu, 9 Jul 2026 09:56:11 +0200 Subject: [PATCH 09/15] (WIP) Add CMake Presets and move compiler flags out of main CMakeLists.txt --- CMakeLists.txt | 46 ++----------- CMakePresets.json | 170 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 41 deletions(-) create mode 100644 CMakePresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a5bc7dc3e1..6ccb72b0412 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,8 +67,6 @@ set(ICINGA2_GROUP "icinga" CACHE STRING "Icinga 2 group") set(ICINGA2_COMMAND_GROUP "icingacmd" CACHE STRING "Icinga 2 command group") set(ICINGA2_PLUGINDIR "/usr/lib/nagios/plugins" CACHE STRING "Path for the check plugins") set(ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe") -set(ICINGA2_UNITY_BUILD ON CACHE BOOL "Whether to perform a unity build") -set(ICINGA2_LTO_BUILD OFF CACHE BOOL "Whether to use LTO") set(ICINGA2_CONFIGDIR "${CMAKE_INSTALL_SYSCONFDIR}/icinga2" CACHE FILEPATH "Main config directory, e.g. /etc/icinga2") set(ICINGA2_CACHEDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/cache/icinga2" CACHE FILEPATH "Directory for cache files, e.g. /var/cache/icinga2") @@ -160,8 +158,8 @@ if(WIN32) # Disable optimization for Boost::context # https://www.boost.org/doc/libs/1_69_0/libs/context/doc/html/context/overview.html # https://docs.microsoft.com/en-us/cpp/build/reference/gl-whole-program-optimization?view=vs-2017 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /GL- /EHs") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /GL- /EHs") + # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /GL- /EHs") + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /GL- /EHs") # detect if 32-bit target if(CMAKE_VS_PLATFORM_NAME STREQUAL "Win32") @@ -220,19 +218,10 @@ find_package(Editline) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/icinga2") +# TODO: Move all of this into CMake Presets if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winconsistent-missing-override -Wrange-loop-construct") - - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics -fno-limit-debug-info") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics -fno-limit-debug-info") -endif() - -if(CMAKE_C_COMPILER_ID STREQUAL "GNU") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsuggest-override") - - if("${CMAKE_CXX_COMPILER_VERSION}" VERSION_GREATER_EQUAL "11.0.0") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wrange-loop-construct") - endif() + # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics ") + # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments") endif() include(CheckCXXCompilerFlag) @@ -279,31 +268,6 @@ if(LD_DYNAMIC_LIST_DATA) set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--dynamic-list-data") endif() -check_cxx_compiler_flag("-Winvalid-pch" CXX_INVALID_PCH) - -if(CXX_INVALID_PCH) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Winvalid-pch") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Winvalid-pch") -endif() - -if(ICINGA2_LTO_BUILD) - check_cxx_compiler_flag("-flto" CXX_FLAG_LTO) - - if(NOT CXX_FLAG_LTO) - message(WARNING "Compiler does not support LTO, falling back to non-LTO build") - else() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto") - - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0) AND NOT OPENBSD) - set(CMAKE_AR "gcc-ar") - set(CMAKE_RANLIB "gcc-ranlib") - endif() - endif() -endif() - if(MSVC) add_compile_definitions( _CRT_SECURE_NO_DEPRECATE diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 00000000000..ad264841037 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,170 @@ +{ + "version": 2, + "cmakeMinimumRequired": { + "major": 3, + "minor": 20, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default", + "hidden": true, + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", + + "CMAKE_PCH_WARN_INVALID": "TRUE", + + "CMAKE_UNITY_BUILD": "TRUE", + "CMAKE_UNITY_BUILD_BATCH_SIZE": "0", + + "CMAKE_C_FLAGS_INIT": "$env{C_FLAGS_COMMON} $env{C_FLAGS_COMPILER} $env{LTO_FLAGS} $env{CFLAGS}", + "CMAKE_CXX_FLAGS_INIT": "$env{CXX_FLAGS_COMMON} $env{CXX_FLAGS_COMPILER} $env{LTO_FLAGS} $env{CXXFLAGS}", + "CMAKE_EXE_LINKER_FLAGS_INIT": "$env{LTO_FLAGS}", + "CMAKE_C_FLAGS_DEBUG_INIT": "$env{FLAGS_DEBUG_COMMON} $env{FLAGS_DEBUG_COMPILER}", + "CMAKE_CXX_FLAGS_DEBUG_INIT": "$env{FLAGS_DEBUG_COMMON} $env{FLAGS_DEBUG_COMPILER}" + } + }, + { + "name": "unix", + "hidden": true, + "binaryDir": "${sourceDir}/build", + "inherits": [ "default" ], + "environment": { + "C_FLAGS_COMMON" : "-Wall -Wextra -Wno-deprecated-declarations", + "CXX_FLAGS_COMMON" : "$env{C_FLAGS_COMMON} -Wsuggest-override -Wrange-loop-construct", + "FLAGS_DEBUG_COMMON" : "-Og", + + "CFLAGS": "$penv{CFLAGS}", + "CXXFLAGS": "$penv{CXXFLAGS}" + } + }, + { + "name": "gcc", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + }, + "environment": { + "C_FLAGS_COMPILER": "-Wno-stringop-overflow", + "CXX_FLAGS_COMPILER": "$env{C_FLAGS_COMPILER} -Wno-template-id-cdtor" + } + }, + { + "name": "clang", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + }, + "environment": { + "C_FLAGS_COMPILER": "-Winconsistent-missing-override -Wno-unknown-attributes -fcolor-diagnostics", + "CXX_FLAGS_COMPILER": "$env{C_FLAGS_COMPILER}", + "FLAGS_DEBUG_COMPILER": "-fno-limit-debug-info" + } + }, + { + "name": "lto", + "hidden": true, + "environment": { + "LTO_FLAGS": "-flto" + } + }, + { + "name": "ninja", + "hidden": true, + "generator": "Ninja" + }, + { + "name": "make", + "hidden": true, + "generator": "Unix Makefiles" + }, + { + "name": "vs", + "hidden": true, + "generator": "Visual Studio 17 2022" + }, + { + "name": "release", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "debug", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "release-gcc", + "inherits": [ "default", "gcc", "make", "release" ] + }, + { + "name": "release-gcc-lto", + "inherits": [ "default", "gcc", "make", "release", "lto" ] + }, + { + "name": "debug-gcc", + "inherits": [ "unix", "gcc", "make", "debug" ] + }, + { + "name": "release-clang", + "inherits": [ "unix", "clang", "make", "release" ] + }, + { + "name": "release-clang-lto", + "inherits": [ "unix", "clang", "make", "release", "lto" ] + }, + { + "name": "debug-clang", + "inherits": [ "unix", "clang", "make", "debug" ] + }, + { + "name": "release-gcc-ninja", + "inherits": [ "unix", "gcc", "ninja", "release" ] + }, + { + "name": "release-gcc-ninja-lto", + "inherits": [ "unix", "gcc", "ninja", "release", "lto" ] + }, + { + "name": "debug-gcc-ninja", + "inherits": [ "unix", "gcc", "ninja", "debug" ] + }, + { + "name": "release-clang-ninja", + "inherits": [ "unix", "clang", "ninja", "release" ] + }, + { + "name": "release-clang-ninja-lto", + "inherits": [ "unix", "clang", "ninja", "release", "lto" ] + }, + { + "name": "debug-clang-ninja", + "inherits": [ "unix", "clang", "ninja", "debug" ] + }, + { + "name": "release-windows", + "inherits": [ "default", "vs", "release" ] + }, + { + "name": "debug-windows", + "inherits": [ "default", "vs", "debug" ] + } + ], + "buildPresets": [ + { + "name": "release", + "configurePreset": "release" + }, + { + "name": "debug", + "configurePreset": "debug" + } + ] +} From d60eaade36497180e8a4e91ff10ab3cbb1e37ee3 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Tue, 14 Jul 2026 09:08:51 +0200 Subject: [PATCH 10/15] Clean up remaining linker and compiler options Some options don't fit into presets, because they're required to build the project. There's also a few linker flags we just set without explanation. --- CMakeLists.txt | 26 +++++++------------------- lib/config/CMakeLists.txt | 11 ++++++----- tools/mkclass/CMakeLists.txt | 10 ++++++---- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ccb72b0412..2d009ea2170 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,8 +158,7 @@ if(WIN32) # Disable optimization for Boost::context # https://www.boost.org/doc/libs/1_69_0/libs/context/doc/html/context/overview.html # https://docs.microsoft.com/en-us/cpp/build/reference/gl-whole-program-optimization?view=vs-2017 - # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj /GL- /EHs") - # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /GL- /EHs") + add_compile_options(/bigobj /GL- /EHs) # detect if 32-bit target if(CMAKE_VS_PLATFORM_NAME STREQUAL "Win32") @@ -167,7 +166,7 @@ if(WIN32) # maybe it is when Boost is compiled with it... # https://lists.boost.org/Archives/boost/2013/10/206720.php # https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers?view=vs-2017 - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") + add_link_options(/SAFESEH:NO) endif() endif() @@ -218,12 +217,6 @@ find_package(Editline) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/icinga2") -# TODO: Move all of this into CMake Presets -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics ") - # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments") -endif() - include(CheckCXXCompilerFlag) function(check_cxx_linker_flag flag var) @@ -236,36 +229,31 @@ endfunction() check_cxx_linker_flag("-Wl,--gc-sections" LD_GC_SECTIONS) if(LD_GC_SECTIONS) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections") + add_link_option(-Wl,--gc-sections) endif() check_cxx_linker_flag("-Wl,--no-export-dynamic" LD_NO_EXPORT_DYNAMIC) if(LD_NO_EXPORT_DYNAMIC) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-export-dynamic") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-export-dynamic") + add_link_option(-Wl,--no-export-dynamic) endif() check_cxx_linker_flag("-Bsymbolic-functions" LD_SYMBOLIC_FUNCTIONS) if(LD_SYMBOLIC_FUNCTIONS) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Bsymbolic-functions") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Bsymbolic-functions") + add_link_option(-Bsymbolic-functions) endif() check_cxx_linker_flag("-Wl,--dynamic-list-cpp-typeinfo" LD_DYNAMIC_LIST_CPP_TYPEINFO) if(LD_DYNAMIC_LIST_CPP_TYPEINFO) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--dynamic-list-cpp-typeinfo") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--dynamic-list-cpp-typeinfo") + add_link_option(-Wl,--dynamic-list-cpp-typeinfo) endif() check_cxx_linker_flag("-Wl,--dynamic-list-data" LD_DYNAMIC_LIST_DATA) if(LD_DYNAMIC_LIST_DATA) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--dynamic-list-data") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--dynamic-list-data") + add_link_option(-Wl,--dynamic-list-data) endif() if(MSVC) diff --git a/lib/config/CMakeLists.txt b/lib/config/CMakeLists.txt index 651215d2327..e2737f3978e 100644 --- a/lib/config/CMakeLists.txt +++ b/lib/config/CMakeLists.txt @@ -5,14 +5,15 @@ find_package(BISON 2.3.0 REQUIRED) find_package(FLEX 2.5.31 REQUIRED) bison_target(config_parser config_parser.yy ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc) -set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc PROPERTY SKIP_UNITY_BUILD_INCLUSION True) - flex_target(config_lexer config_lexer.ll ${CMAKE_CURRENT_BINARY_DIR}/config_lexer.cc) -set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_lexer.cc PROPERTY SKIP_UNITY_BUILD_INCLUSION True) + +set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc ${CMAKE_CURRENT_BINARY_DIR}/config_lexer.cc + PROPERTIES + SKIP_UNITY_BUILD_INCLUSION TRUE +) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc PROPERTY COMPILE_FLAGS "-Wno-deprecated-register -Wno-parentheses-equality -Wno-unused-function") - set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_lexer.cc PROPERTY COMPILE_FLAGS "-Wno-deprecated-register -Wno-null-conversion") + set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/config_parser.cc PROPERTY COMPILE_FLAGS "-Wno-unused-but-set-variable") endif() add_flex_bison_dependency(config_lexer config_parser) diff --git a/tools/mkclass/CMakeLists.txt b/tools/mkclass/CMakeLists.txt index 2ceaa400487..ec0589912cb 100644 --- a/tools/mkclass/CMakeLists.txt +++ b/tools/mkclass/CMakeLists.txt @@ -5,14 +5,16 @@ find_package(BISON 2.3.0 REQUIRED) find_package(FLEX 2.5.31 REQUIRED) bison_target(class_parser class_parser.yy ${CMAKE_CURRENT_BINARY_DIR}/class_parser.cc) -set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/class_parser.cc PROPERTY SKIP_UNITY_BUILD_INCLUSION True) flex_target(class_lexer class_lexer.ll ${CMAKE_CURRENT_BINARY_DIR}/class_lexer.cc) -set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/class_lexer.cc PROPERTY SKIP_UNITY_BUILD_INCLUSION True) add_flex_bison_dependency(class_lexer class_parser) +set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/class_parser.cc ${CMAKE_CURRENT_BINARY_DIR}/class_lexer.cc + PROPERTIES + SKIP_UNITY_BUILD_INCLUSION TRUE +) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/class_parser.cc PROPERTY COMPILE_FLAGS "-Wno-deprecated-register") - set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/class_lexer.cc PROPERTY COMPILE_FLAGS "-Wno-deprecated-register -Wno-null-conversion") + set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/class_parser.cc PROPERTY COMPILE_FLAGS "-Wno-unused-but-set-variable") endif() include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) From f7d1de43886ae058954170fd1b3c2eb108bbfcd4 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Tue, 14 Jul 2026 09:17:32 +0200 Subject: [PATCH 11/15] Move `check_cxx_linker_flag` into a CMake include --- CMakeLists.txt | 8 +------- cmake/CheckCXXLinkerFlag.cmake | 11 +++++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 cmake/CheckCXXLinkerFlag.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d009ea2170..058e9fe4c99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,13 +218,7 @@ find_package(Editline) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/icinga2") include(CheckCXXCompilerFlag) - -function(check_cxx_linker_flag flag var) - set(CMAKE_REQUIRED_FLAGS ${flag}) - set(result 0) - check_cxx_compiler_flag(${flag} result) - set(${var} ${result} PARENT_SCOPE) -endfunction() +include(CheckCXXLinkerFlag) check_cxx_linker_flag("-Wl,--gc-sections" LD_GC_SECTIONS) diff --git a/cmake/CheckCXXLinkerFlag.cmake b/cmake/CheckCXXLinkerFlag.cmake new file mode 100644 index 00000000000..ab0d9194b54 --- /dev/null +++ b/cmake/CheckCXXLinkerFlag.cmake @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2026 Icinga GmbH +# SPDX-License-Identifier: GPL-2.0-or-later + +include(CheckCXXCompilerFlag) + +function(check_cxx_linker_flag flag var) + set(CMAKE_REQUIRED_FLAGS ${flag}) + set(result 0) + check_cxx_compiler_flag(${flag} result) + set(${var} ${result} PARENT_SCOPE) +endfunction() From a710cc62eaf61c61726df891fc300e93b768da73 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Tue, 14 Jul 2026 15:00:24 +0200 Subject: [PATCH 12/15] move include dirs etc. into lib target --- lib/CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ lib/base/CMakeLists.txt | 27 +-------------------------- lib/checker/CMakeLists.txt | 1 + lib/cli/CMakeLists.txt | 1 + lib/compat/CMakeLists.txt | 1 + lib/config/CMakeLists.txt | 1 + lib/db_ido/CMakeLists.txt | 1 + lib/db_ido_mysql/CMakeLists.txt | 1 + lib/db_ido_pgsql/CMakeLists.txt | 1 + lib/icinga/CMakeLists.txt | 1 + lib/icingadb/CMakeLists.txt | 1 + lib/livestatus/CMakeLists.txt | 1 + lib/notification/CMakeLists.txt | 1 + lib/perfdata/CMakeLists.txt | 1 + lib/remote/CMakeLists.txt | 1 + 15 files changed, 45 insertions(+), 26 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index ebb0ce404a5..68b717210c6 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,6 +1,37 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later +add_library(lib OBJECT) + +target_include_directories(lib PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR} +) + +target_link_libraries(lib PUBLIC + ${CMAKE_DL_LIBS} + Threads::Threads + mmatch + socketpair + nlohmann_json + utf8cpp + Boost::context + Boost::coroutine + Boost::filesystem + Boost::regex + Boost::thread + Boost::iostreams + OpenSSL::SSL +) + +if(WIN32) + target_compile_definitions(lib PUBLIC + NOMINMAX + WIN32_LEAN_AND_MEAN + ) +endif() + add_subdirectory(base) add_subdirectory(cli) add_subdirectory(config) diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index a1a774a0461..b8bee43a748 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -96,14 +96,6 @@ add_library(base OBJECT workqueue.cpp workqueue.hpp ) -target_include_directories(base - PUBLIC - ${CMAKE_SOURCE_DIR}/lib - ${CMAKE_BINARY_DIR}/lib - # TODO: Make this its own library we can link against here - ${CMAKE_BINARY_DIR} -) - set_source_files_properties(application-version.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE @@ -117,11 +109,6 @@ if(WIN32) windowseventloglogger-ti.hpp ) - target_compile_definitions(base PUBLIC - NOMINMAX - WIN32_LEAN_AND_MEAN - ) - target_link_libraries(base PUBLIC ws2_32 dbghelp @@ -155,19 +142,7 @@ if(WIN32) endif() target_link_libraries(base PUBLIC - ${CMAKE_DL_LIBS} - Threads::Threads - mmatch - socketpair - nlohmann_json - utf8cpp - Boost::context - Boost::coroutine - Boost::filesystem - Boost::regex - Boost::thread - Boost::iostreams - OpenSSL::SSL + lib ) if(USE_SYSTEMD) diff --git a/lib/checker/CMakeLists.txt b/lib/checker/CMakeLists.txt index 7bc9c3d4b0b..5fd75ca8c9f 100644 --- a/lib/checker/CMakeLists.txt +++ b/lib/checker/CMakeLists.txt @@ -12,6 +12,7 @@ target_link_libraries(checker config icinga remote + lib ) set_target_properties ( diff --git a/lib/cli/CMakeLists.txt b/lib/cli/CMakeLists.txt index f08f577506b..e1f50fc4939 100644 --- a/lib/cli/CMakeLists.txt +++ b/lib/cli/CMakeLists.txt @@ -41,6 +41,7 @@ target_link_libraries(cli PUBLIC config icinga remote + lib ) if(Editline_FOUND) diff --git a/lib/compat/CMakeLists.txt b/lib/compat/CMakeLists.txt index 3ca22e63bd4..9e9b2045746 100644 --- a/lib/compat/CMakeLists.txt +++ b/lib/compat/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(compat PUBLIC base config icinga + lib ) set_target_properties ( diff --git a/lib/config/CMakeLists.txt b/lib/config/CMakeLists.txt index e2737f3978e..3e1b51c372a 100644 --- a/lib/config/CMakeLists.txt +++ b/lib/config/CMakeLists.txt @@ -43,6 +43,7 @@ add_library(config OBJECT target_link_libraries(config PUBLIC base + lib ) set_target_properties ( diff --git a/lib/db_ido/CMakeLists.txt b/lib/db_ido/CMakeLists.txt index 8e88e3a3eaf..d8c50f037eb 100644 --- a/lib/db_ido/CMakeLists.txt +++ b/lib/db_ido/CMakeLists.txt @@ -32,6 +32,7 @@ target_link_libraries(db_ido PUBLIC config icinga remote + lib ) set_target_properties ( diff --git a/lib/db_ido_mysql/CMakeLists.txt b/lib/db_ido_mysql/CMakeLists.txt index 41c8ea00bbc..defdd1ce8aa 100644 --- a/lib/db_ido_mysql/CMakeLists.txt +++ b/lib/db_ido_mysql/CMakeLists.txt @@ -12,6 +12,7 @@ target_link_libraries(db_ido_mysql PUBLIC config icinga db_ido + lib MySQL ) diff --git a/lib/db_ido_pgsql/CMakeLists.txt b/lib/db_ido_pgsql/CMakeLists.txt index 7cb4ce69be2..3eb948e5c33 100644 --- a/lib/db_ido_pgsql/CMakeLists.txt +++ b/lib/db_ido_pgsql/CMakeLists.txt @@ -10,6 +10,7 @@ add_library(db_ido_pgsql OBJECT target_link_libraries(db_ido_pgsql PUBLIC base db_ido + lib PostgreSQL ) diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index 8369a52ba33..6daf4dfbc7d 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -67,6 +67,7 @@ target_link_libraries(icinga PUBLIC base config remote + lib ) set_target_properties ( diff --git a/lib/icingadb/CMakeLists.txt b/lib/icingadb/CMakeLists.txt index 72827649736..09f23f82e9c 100644 --- a/lib/icingadb/CMakeLists.txt +++ b/lib/icingadb/CMakeLists.txt @@ -15,6 +15,7 @@ target_link_libraries(icingadb PUBLIC config icinga remote + lib ) set_target_properties ( diff --git a/lib/livestatus/CMakeLists.txt b/lib/livestatus/CMakeLists.txt index ab4ca02dbc2..f5f7066d9ac 100644 --- a/lib/livestatus/CMakeLists.txt +++ b/lib/livestatus/CMakeLists.txt @@ -48,6 +48,7 @@ target_link_libraries(livestatus PUBLIC config icinga remote + lib ) set_target_properties ( diff --git a/lib/notification/CMakeLists.txt b/lib/notification/CMakeLists.txt index 03610171f47..10b49d3352d 100644 --- a/lib/notification/CMakeLists.txt +++ b/lib/notification/CMakeLists.txt @@ -11,6 +11,7 @@ target_link_libraries(notification PUBLIC base config icinga + lib ) set_target_properties ( diff --git a/lib/perfdata/CMakeLists.txt b/lib/perfdata/CMakeLists.txt index dc4969dad6a..bba196a6784 100644 --- a/lib/perfdata/CMakeLists.txt +++ b/lib/perfdata/CMakeLists.txt @@ -23,6 +23,7 @@ add_library(perfdata OBJECT ) target_link_libraries(perfdata PUBLIC + lib base icinga ) diff --git a/lib/remote/CMakeLists.txt b/lib/remote/CMakeLists.txt index d97c744ca22..19fa4a2de8d 100644 --- a/lib/remote/CMakeLists.txt +++ b/lib/remote/CMakeLists.txt @@ -50,6 +50,7 @@ add_library(remote OBJECT target_link_libraries(remote PUBLIC base config + lib Boost::coroutine ) From c2896db908632b94c42e664892471a5d9fb57e61 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Thu, 9 Jul 2026 09:49:07 +0200 Subject: [PATCH 13/15] Make mkclass add targets for more parallelization --- lib/base/CMakeLists.txt | 46 +++++++++------------- lib/checker/CMakeLists.txt | 12 +++--- lib/cli/CMakeLists.txt | 6 +-- lib/compat/CMakeLists.txt | 14 +++---- lib/config/CMakeLists.txt | 3 +- lib/db_ido/CMakeLists.txt | 12 +++--- lib/db_ido_mysql/CMakeLists.txt | 12 +++--- lib/db_ido_pgsql/CMakeLists.txt | 10 ++--- lib/icinga/CMakeLists.txt | 68 ++++++++++++--------------------- lib/icingadb/CMakeLists.txt | 12 +++--- lib/livestatus/CMakeLists.txt | 12 +++--- lib/notification/CMakeLists.txt | 11 +++--- lib/perfdata/CMakeLists.txt | 34 +++++++---------- lib/pgsql_shim/CMakeLists.txt | 6 +-- lib/remote/CMakeLists.txt | 20 +++++----- tools/mkclass/CMakeLists.txt | 35 ++++++++++++----- 16 files changed, 137 insertions(+), 176 deletions(-) diff --git a/lib/base/CMakeLists.txt b/lib/base/CMakeLists.txt index b8bee43a748..b510ef7b19e 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -1,54 +1,45 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -# TODO: Make mkclass_target add targets to link against -mkclass_target(application.ti application-ti.cpp application-ti.hpp) -mkclass_target(configobject.ti configobject-ti.cpp configobject-ti.hpp) -mkclass_target(configuration.ti configuration-ti.cpp configuration-ti.hpp) -mkclass_target(datetime.ti datetime-ti.cpp datetime-ti.hpp) -mkclass_target(filelogger.ti filelogger-ti.cpp filelogger-ti.hpp) -mkclass_target(function.ti function-ti.cpp function-ti.hpp) -mkclass_target(journaldlogger.ti journaldlogger-ti.cpp journaldlogger-ti.hpp) -mkclass_target(logger.ti logger-ti.cpp logger-ti.hpp) -mkclass_target(perfdatavalue.ti perfdatavalue-ti.cpp perfdatavalue-ti.hpp) -mkclass_target(streamlogger.ti streamlogger-ti.cpp streamlogger-ti.hpp) -mkclass_target(sysloglogger.ti sysloglogger-ti.cpp sysloglogger-ti.hpp) - add_library(base OBJECT i2-base.hpp - application.cpp application.hpp application-ti.hpp application-version.cpp application-environment.cpp + application.cpp application.hpp application.ti + application-version.cpp application-environment.cpp array.cpp array.hpp array-script.cpp atomic.hpp atomic-file.cpp atomic-file.hpp base64.cpp base64.hpp boolean.cpp boolean.hpp boolean-script.cpp bulker.hpp - configobject.cpp configobject.hpp configobject-ti.hpp configobject-script.cpp + configobject.cpp configobject.hpp configobject.ti + configobject-script.cpp configtype.cpp configtype.hpp - configuration.cpp configuration.hpp configuration-ti.hpp + configuration.cpp configuration.hpp configuration.ti configwriter.cpp configwriter.hpp console.cpp console.hpp context.cpp context.hpp convert.cpp convert.hpp - datetime.cpp datetime.hpp datetime-ti.hpp datetime-script.cpp + datetime.cpp datetime.hpp datetime.ti + datetime-script.cpp debug.hpp debuginfo.cpp debuginfo.hpp dependencygraph.cpp dependencygraph.hpp dictionary.cpp dictionary.hpp dictionary-script.cpp exception.cpp exception.hpp fifo.cpp fifo.hpp - filelogger.cpp filelogger.hpp filelogger-ti.hpp - function.cpp function.hpp function-ti.hpp function-script.cpp functionwrapper.hpp + filelogger.cpp filelogger.hpp filelogger.ti + function.cpp function.hpp function.ti + function-script.cpp functionwrapper.hpp generator.hpp initialize.cpp initialize.hpp intrusive-ptr.hpp io-engine.cpp io-engine.hpp - journaldlogger.cpp journaldlogger.hpp journaldlogger-ti.hpp + journaldlogger.cpp journaldlogger.hpp journaldlogger.ti json.cpp json.hpp json-script.cpp lazy-init.hpp library.cpp library.hpp loader.cpp loader.hpp - logger.cpp logger.hpp logger-ti.hpp + logger.cpp logger.hpp logger.ti math-script.cpp netstring.cpp netstring.hpp networkstream.cpp networkstream.hpp @@ -58,7 +49,7 @@ add_library(base OBJECT objectlock.cpp objectlock.hpp object-packer.cpp object-packer.hpp objecttype.cpp objecttype.hpp - perfdatavalue.cpp perfdatavalue.hpp perfdatavalue-ti.hpp + perfdatavalue.cpp perfdatavalue.hpp perfdatavalue.ti primitivetype.cpp primitivetype.hpp process.cpp process.hpp reference.cpp reference.hpp reference-script.cpp @@ -78,9 +69,9 @@ add_library(base OBJECT statsfunction.hpp stdiostream.cpp stdiostream.hpp stream.cpp stream.hpp - streamlogger.cpp streamlogger.hpp streamlogger-ti.hpp + streamlogger.cpp streamlogger.hpp streamlogger.ti string.cpp string.hpp string-script.cpp - sysloglogger.cpp sysloglogger.hpp sysloglogger-ti.hpp + sysloglogger.cpp sysloglogger.hpp sysloglogger.ti tcpsocket.cpp tcpsocket.hpp threadpool.cpp threadpool.hpp timer.cpp timer.hpp @@ -102,11 +93,10 @@ set_source_files_properties(application-version.cpp ) if(WIN32) - mkclass_target(windowseventloglogger.ti windowseventloglogger-ti.cpp windowseventloglogger-ti.hpp) target_sources(base PRIVATE windowseventloglogger.cpp windowseventloglogger.hpp - windowseventloglogger-ti.hpp + windowseventloglogger.ti ) target_link_libraries(base PUBLIC @@ -141,12 +131,14 @@ if(WIN32) install(TARGETS eventprovider LIBRARY DESTINATION ${CMAKE_INSTALL_SBINDIR}) endif() +target_mkclass(base base_generated config_generated) + target_link_libraries(base PUBLIC lib ) if(USE_SYSTEMD) - target_link_libraries(base PUBLIC + target_link_libraries(lib PUBLIC Systemd ) diff --git a/lib/checker/CMakeLists.txt b/lib/checker/CMakeLists.txt index 5fd75ca8c9f..dcc09a8a3ea 100644 --- a/lib/checker/CMakeLists.txt +++ b/lib/checker/CMakeLists.txt @@ -1,20 +1,18 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(checkercomponent.ti checkercomponent-ti.cpp checkercomponent-ti.hpp) - add_library(checker OBJECT - checkercomponent.cpp checkercomponent.hpp checkercomponent-ti.hpp + checkercomponent.cpp checkercomponent.hpp checkercomponent.ti ) +target_mkclass(checker checker_generated) + target_link_libraries(checker - base - config - icinga - remote lib ) +add_dependencies(checker base_generated icinga_generated remote_generated) + set_target_properties ( checker PROPERTIES FOLDER Components diff --git a/lib/cli/CMakeLists.txt b/lib/cli/CMakeLists.txt index e1f50fc4939..fa075559876 100644 --- a/lib/cli/CMakeLists.txt +++ b/lib/cli/CMakeLists.txt @@ -37,13 +37,11 @@ add_library(cli OBJECT ) target_link_libraries(cli PUBLIC - base - config - icinga - remote lib ) +add_dependencies(cli base_generated icinga_generated remote_generated) + if(Editline_FOUND) target_link_libraries(cli PUBLIC Editline) endif() diff --git a/lib/compat/CMakeLists.txt b/lib/compat/CMakeLists.txt index 9e9b2045746..1f7eaf42f50 100644 --- a/lib/compat/CMakeLists.txt +++ b/lib/compat/CMakeLists.txt @@ -1,21 +1,19 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(compatlogger.ti compatlogger-ti.cpp compatlogger-ti.hpp) -mkclass_target(externalcommandlistener.ti externalcommandlistener-ti.cpp externalcommandlistener-ti.hpp) - add_library(compat OBJECT - compatlogger.cpp compatlogger.hpp compatlogger-ti.hpp - externalcommandlistener.cpp externalcommandlistener.hpp externalcommandlistener-ti.hpp + compatlogger.cpp compatlogger.hpp compatlogger.ti + externalcommandlistener.cpp externalcommandlistener.hpp externalcommandlistener.ti ) +target_mkclass(compat compat_generated) + target_link_libraries(compat PUBLIC - base - config - icinga lib ) +add_dependencies(compat base_generated icinga_generated) + set_target_properties ( compat PROPERTIES FOLDER Components diff --git a/lib/config/CMakeLists.txt b/lib/config/CMakeLists.txt index 3e1b51c372a..c6f205fe19c 100644 --- a/lib/config/CMakeLists.txt +++ b/lib/config/CMakeLists.txt @@ -42,10 +42,11 @@ add_library(config OBJECT ) target_link_libraries(config PUBLIC - base lib ) +add_dependencies(config base_generated) + set_target_properties ( config PROPERTIES FOLDER Lib diff --git a/lib/db_ido/CMakeLists.txt b/lib/db_ido/CMakeLists.txt index d8c50f037eb..f93bb2f649b 100644 --- a/lib/db_ido/CMakeLists.txt +++ b/lib/db_ido/CMakeLists.txt @@ -1,14 +1,12 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(dbconnection.ti dbconnection-ti.cpp dbconnection-ti.hpp) - mkembedconfig_target(db_ido-itl.conf db_ido-itl.cpp) add_library(db_ido OBJECT i2-db_ido.hpp db_ido-itl.cpp commanddbobject.cpp commanddbobject.hpp - dbconnection.cpp dbconnection.hpp dbconnection-ti.hpp + dbconnection.cpp dbconnection.hpp dbconnection.ti dbevents.cpp dbevents.hpp dbobject.cpp dbobject.hpp dbquery.cpp dbquery.hpp @@ -27,14 +25,14 @@ add_library(db_ido OBJECT zonedbobject.cpp zonedbobject.hpp ) +target_mkclass(db_ido db_ido_generated) + target_link_libraries(db_ido PUBLIC - base - config - icinga - remote lib ) +add_dependencies(db_ido base_generated icinga_generated remote_generated) + set_target_properties ( db_ido PROPERTIES FOLDER Lib diff --git a/lib/db_ido_mysql/CMakeLists.txt b/lib/db_ido_mysql/CMakeLists.txt index defdd1ce8aa..5857e283dfa 100644 --- a/lib/db_ido_mysql/CMakeLists.txt +++ b/lib/db_ido_mysql/CMakeLists.txt @@ -1,21 +1,19 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(idomysqlconnection.ti idomysqlconnection-ti.cpp idomysqlconnection-ti.hpp) - add_library(db_ido_mysql OBJECT - idomysqlconnection.cpp idomysqlconnection.hpp idomysqlconnection-ti.hpp + idomysqlconnection.cpp idomysqlconnection.hpp idomysqlconnection.ti ) +target_mkclass(db_ido_mysql db_ido_mysql_generated) + target_link_libraries(db_ido_mysql PUBLIC - base - config - icinga - db_ido lib MySQL ) +add_dependencies(db_ido_mysql db_ido_generated) + set_target_properties ( db_ido_mysql PROPERTIES FOLDER Components diff --git a/lib/db_ido_pgsql/CMakeLists.txt b/lib/db_ido_pgsql/CMakeLists.txt index 3eb948e5c33..66ed5d03cb5 100644 --- a/lib/db_ido_pgsql/CMakeLists.txt +++ b/lib/db_ido_pgsql/CMakeLists.txt @@ -1,19 +1,19 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(idopgsqlconnection.ti idopgsqlconnection-ti.cpp idopgsqlconnection-ti.hpp) - add_library(db_ido_pgsql OBJECT - idopgsqlconnection.cpp idopgsqlconnection.hpp idopgsqlconnection-ti.hpp + idopgsqlconnection.cpp idopgsqlconnection.hpp idopgsqlconnection.ti ) +target_mkclass(db_ido_pgsql db_ido_pgsql_generated) + target_link_libraries(db_ido_pgsql PUBLIC - base - db_ido lib PostgreSQL ) +add_dependencies(db_ido_pgsql base_generated db_ido_generated) + set_target_properties ( db_ido_pgsql PROPERTIES FOLDER Components diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index 6daf4dfbc7d..15cfb384742 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -1,75 +1,55 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(checkable.ti checkable-ti.cpp checkable-ti.hpp) -mkclass_target(checkcommand.ti checkcommand-ti.cpp checkcommand-ti.hpp) -mkclass_target(checkresult.ti checkresult-ti.cpp checkresult-ti.hpp) -mkclass_target(command.ti command-ti.cpp command-ti.hpp) -mkclass_target(comment.ti comment-ti.cpp comment-ti.hpp) -mkclass_target(dependency.ti dependency-ti.cpp dependency-ti.hpp) -mkclass_target(downtime.ti downtime-ti.cpp downtime-ti.hpp) -mkclass_target(eventcommand.ti eventcommand-ti.cpp eventcommand-ti.hpp) -mkclass_target(hostgroup.ti hostgroup-ti.cpp hostgroup-ti.hpp) -mkclass_target(host.ti host-ti.cpp host-ti.hpp) -mkclass_target(icingaapplication.ti icingaapplication-ti.cpp icingaapplication-ti.hpp) -mkclass_target(customvarobject.ti customvarobject-ti.cpp customvarobject-ti.hpp) -mkclass_target(notificationcommand.ti notificationcommand-ti.cpp notificationcommand-ti.hpp) -mkclass_target(notification.ti notification-ti.cpp notification-ti.hpp) -mkclass_target(scheduleddowntime.ti scheduleddowntime-ti.cpp scheduleddowntime-ti.hpp) -mkclass_target(servicegroup.ti servicegroup-ti.cpp servicegroup-ti.hpp) -mkclass_target(service.ti service-ti.cpp service-ti.hpp) -mkclass_target(timeperiod.ti timeperiod-ti.cpp timeperiod-ti.hpp) -mkclass_target(usergroup.ti usergroup-ti.cpp usergroup-ti.hpp) -mkclass_target(user.ti user-ti.cpp user-ti.hpp) - mkembedconfig_target(icinga-itl.conf icinga-itl.cpp) add_library(icinga OBJECT i2-icinga.hpp icinga-itl.cpp apiactions.cpp apiactions.hpp apievents.cpp apievents.hpp - checkable.cpp checkable.hpp checkable-ti.hpp + checkable.cpp checkable.hpp checkable.ti checkable-check.cpp checkable-comment.cpp checkable-dependency.cpp checkable-downtime.cpp checkable-event.cpp checkable-flapping.cpp checkable-notification.cpp - checkcommand.cpp checkcommand.hpp checkcommand-ti.hpp - checkresult.cpp checkresult.hpp checkresult-ti.hpp + checkcommand.cpp checkcommand.hpp checkcommand.ti + checkresult.cpp checkresult.hpp checkresult.ti cib.cpp cib.hpp clusterevents.cpp clusterevents.hpp clusterevents-check.cpp - command.cpp command.hpp command-ti.hpp - comment.cpp comment.hpp comment-ti.hpp + command.cpp command.hpp command.ti + comment.cpp comment.hpp comment.ti compatutility.cpp compatutility.hpp - customvarobject.cpp customvarobject.hpp customvarobject-ti.hpp - dependency.cpp dependency-group.cpp dependency-state.cpp dependency.hpp dependency-ti.hpp dependency-apply.cpp - downtime.cpp downtime.hpp downtime-ti.hpp + customvarobject.cpp customvarobject.hpp customvarobject.ti + dependency.cpp dependency-group.cpp dependency-state.cpp dependency.hpp dependency.ti dependency-apply.cpp + downtime.cpp downtime.hpp downtime.ti envresolver.cpp envresolver.hpp - eventcommand.cpp eventcommand.hpp eventcommand-ti.hpp + eventcommand.cpp eventcommand.hpp eventcommand.ti externalcommandprocessor.cpp externalcommandprocessor.hpp - host.cpp host.hpp host-ti.hpp - hostgroup.cpp hostgroup.hpp hostgroup-ti.hpp - icingaapplication.cpp icingaapplication.hpp icingaapplication-ti.hpp + host.cpp host.hpp host.ti + hostgroup.cpp hostgroup.hpp hostgroup.ti + icingaapplication.cpp icingaapplication.hpp icingaapplication.ti legacytimeperiod.cpp legacytimeperiod.hpp macroprocessor.cpp macroprocessor.hpp macroresolver.hpp - notification.cpp notification.hpp notification-ti.hpp notification-apply.cpp - notificationcommand.cpp notificationcommand.hpp notificationcommand-ti.hpp + notification.cpp notification.hpp notification.ti notification-apply.cpp + notificationcommand.cpp notificationcommand.hpp notificationcommand.ti objectutils.cpp objectutils.hpp pluginutility.cpp pluginutility.hpp - scheduleddowntime.cpp scheduleddowntime.hpp scheduleddowntime-ti.hpp scheduleddowntime-apply.cpp - service.cpp service.hpp service-ti.hpp service-apply.cpp - servicegroup.cpp servicegroup.hpp servicegroup-ti.hpp - timeperiod.cpp timeperiod.hpp timeperiod-ti.hpp - user.cpp user.hpp user-ti.hpp - usergroup.cpp usergroup.hpp usergroup-ti.hpp + scheduleddowntime.cpp scheduleddowntime.hpp scheduleddowntime.ti scheduleddowntime-apply.cpp + service.cpp service.hpp service.ti service-apply.cpp + servicegroup.cpp servicegroup.hpp servicegroup.ti + timeperiod.cpp timeperiod.hpp timeperiod.ti + user.cpp user.hpp user.ti + usergroup.cpp usergroup.hpp usergroup.ti ) target_link_libraries(icinga PUBLIC - base - config - remote lib ) +target_mkclass(icinga icinga_generated) + +add_dependencies(icinga base_generated remote_generated) + set_target_properties ( icinga PROPERTIES FOLDER Lib diff --git a/lib/icingadb/CMakeLists.txt b/lib/icingadb/CMakeLists.txt index 09f23f82e9c..592a14bdc63 100644 --- a/lib/icingadb/CMakeLists.txt +++ b/lib/icingadb/CMakeLists.txt @@ -1,23 +1,21 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(icingadb.ti icingadb-ti.cpp icingadb-ti.hpp) - mkembedconfig_target(icingadb-itl.conf icingadb-itl.cpp) add_library(icingadb OBJECT - icingadb.cpp icingadb-objects.cpp icingadb-stats.cpp icingadb-utility.cpp icingadb-worker.cpp redisconnection.cpp icingadb-ti.hpp + icingadb.cpp icingadb-objects.cpp icingadb-stats.cpp icingadb-utility.cpp icingadb-worker.cpp redisconnection.cpp icingadb.ti icingadbchecktask.cpp icingadb-itl.cpp ) +target_mkclass(icingadb icingadb_generated) + target_link_libraries(icingadb PUBLIC - base - config - icinga - remote lib ) +add_dependencies(icingadb base_generated icinga_generated remote_generated) + set_target_properties ( icingadb PROPERTIES FOLDER Components diff --git a/lib/livestatus/CMakeLists.txt b/lib/livestatus/CMakeLists.txt index f5f7066d9ac..898128677a5 100644 --- a/lib/livestatus/CMakeLists.txt +++ b/lib/livestatus/CMakeLists.txt @@ -1,8 +1,6 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(livestatuslistener.ti livestatuslistener-ti.cpp livestatuslistener-ti.hpp) - add_library(livestatus OBJECT i2-livestatus.hpp aggregator.cpp aggregator.hpp @@ -24,7 +22,7 @@ add_library(livestatus OBJECT hoststable.cpp hoststable.hpp invavgaggregator.cpp invavgaggregator.hpp invsumaggregator.cpp invsumaggregator.hpp - livestatuslistener.cpp livestatuslistener.hpp livestatuslistener-ti.hpp + livestatuslistener.cpp livestatuslistener.hpp livestatuslistener.ti livestatuslogutility.cpp livestatuslogutility.hpp livestatusquery.cpp livestatusquery.hpp logtable.cpp logtable.hpp @@ -43,14 +41,14 @@ add_library(livestatus OBJECT zonestable.cpp zonestable.hpp ) +target_mkclass(livestatus livestatus_generated) + target_link_libraries(livestatus PUBLIC - base - config - icinga - remote lib ) +add_dependencies(livestatus base_generated icinga_generated remote_generated) + set_target_properties ( livestatus PROPERTIES FOLDER Components diff --git a/lib/notification/CMakeLists.txt b/lib/notification/CMakeLists.txt index 10b49d3352d..daef0bd987c 100644 --- a/lib/notification/CMakeLists.txt +++ b/lib/notification/CMakeLists.txt @@ -1,19 +1,18 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(notificationcomponent.ti notificationcomponent-ti.cpp notificationcomponent-ti.hpp) - add_library(notification OBJECT - notificationcomponent.cpp notificationcomponent.hpp notificationcomponent-ti.hpp + notificationcomponent.cpp notificationcomponent.hpp notificationcomponent.ti ) +target_mkclass(notification notification_generated) + target_link_libraries(notification PUBLIC - base - config - icinga lib ) +add_dependencies(notification base_generated icinga_generated) + set_target_properties ( notification PROPERTIES FOLDER Components diff --git a/lib/perfdata/CMakeLists.txt b/lib/perfdata/CMakeLists.txt index bba196a6784..0ea12a2e896 100644 --- a/lib/perfdata/CMakeLists.txt +++ b/lib/perfdata/CMakeLists.txt @@ -1,41 +1,33 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(gelfwriter.ti gelfwriter-ti.cpp gelfwriter-ti.hpp) -mkclass_target(graphitewriter.ti graphitewriter-ti.cpp graphitewriter-ti.hpp) -mkclass_target(influxdbcommonwriter.ti influxdbcommonwriter-ti.cpp influxdbcommonwriter-ti.hpp) -mkclass_target(influxdbwriter.ti influxdbwriter-ti.cpp influxdbwriter-ti.hpp) -mkclass_target(influxdb2writer.ti influxdb2writer-ti.cpp influxdb2writer-ti.hpp) -mkclass_target(elasticsearchwriter.ti elasticsearchwriter-ti.cpp elasticsearchwriter-ti.hpp) -mkclass_target(opentsdbwriter.ti opentsdbwriter-ti.cpp opentsdbwriter-ti.hpp) -mkclass_target(perfdatawriter.ti perfdatawriter-ti.cpp perfdatawriter-ti.hpp) - add_library(perfdata OBJECT - elasticsearchwriter.cpp elasticsearchwriter.hpp elasticsearchwriter-ti.hpp - gelfwriter.cpp gelfwriter.hpp gelfwriter-ti.hpp - graphitewriter.cpp graphitewriter.hpp graphitewriter-ti.hpp - influxdbcommonwriter.cpp influxdbcommonwriter.hpp influxdbcommonwriter-ti.hpp - influxdbwriter.cpp influxdbwriter.hpp influxdbwriter-ti.hpp - influxdb2writer.cpp influxdb2writer.hpp influxdb2writer-ti.hpp - opentsdbwriter.cpp opentsdbwriter.hpp opentsdbwriter-ti.hpp - perfdatawriter.cpp perfdatawriter.hpp perfdatawriter-ti.hpp + elasticsearchwriter.cpp elasticsearchwriter.hpp elasticsearchwriter.ti + gelfwriter.cpp gelfwriter.hpp gelfwriter.ti + graphitewriter.cpp graphitewriter.hpp graphitewriter.ti + influxdbcommonwriter.cpp influxdbcommonwriter.hpp influxdbcommonwriter.ti + influxdbwriter.cpp influxdbwriter.hpp influxdbwriter.ti + influxdb2writer.cpp influxdb2writer.hpp influxdb2writer.ti + opentsdbwriter.cpp opentsdbwriter.hpp opentsdbwriter.ti + perfdatawriter.cpp perfdatawriter.hpp perfdatawriter.ti perfdatawriterconnection.cpp perfdatawriterconnection.hpp ) target_link_libraries(perfdata PUBLIC lib - base - icinga ) +add_dependencies(perfdata base_generated icinga_generated) + if(ICINGA2_WITH_OPENTELEMETRY) - mkclass_target(otlpmetricswriter.ti otlpmetricswriter-ti.cpp otlpmetricswriter-ti.hpp) target_sources(perfdata PRIVATE - otlpmetricswriter.cpp otlpmetricswriter.hpp otlpmetricswriter-ti.hpp + otlpmetricswriter.cpp otlpmetricswriter.hpp otlpmetricswriter.ti ) target_link_libraries(perfdata PUBLIC otel) endif() +target_mkclass(perfdata perfdata_generated) + set_target_properties ( perfdata PROPERTIES FOLDER Components diff --git a/lib/pgsql_shim/CMakeLists.txt b/lib/pgsql_shim/CMakeLists.txt index f1b851cf564..75a05dfca7e 100644 --- a/lib/pgsql_shim/CMakeLists.txt +++ b/lib/pgsql_shim/CMakeLists.txt @@ -7,17 +7,13 @@ add_library(pgsql_shim SHARED ) target_link_libraries(pgsql_shim PUBLIC + lib PostgreSQL ) include(GenerateExportHeader) generate_export_header(pgsql_shim) -target_include_directories(pgsql_shim PRIVATE - ${CMAKE_SOURCE_DIR}/lib - ${CMAKE_BINARY_DIR}/lib -) - set_target_properties ( pgsql_shim PROPERTIES FOLDER Lib diff --git a/lib/remote/CMakeLists.txt b/lib/remote/CMakeLists.txt index 19fa4a2de8d..15b3b9bb98e 100644 --- a/lib/remote/CMakeLists.txt +++ b/lib/remote/CMakeLists.txt @@ -1,19 +1,15 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(apilistener.ti apilistener-ti.cpp apilistener-ti.hpp) -mkclass_target(apiuser.ti apiuser-ti.cpp apiuser-ti.hpp) -mkclass_target(endpoint.ti endpoint-ti.cpp endpoint-ti.hpp) -mkclass_target(zone.ti zone-ti.cpp zone-ti.hpp) - add_library(remote OBJECT i2-remote.hpp actionshandler.cpp actionshandler.hpp apiaction.cpp apiaction.hpp apifunction.cpp apifunction.hpp - apilistener.cpp apilistener.hpp apilistener-ti.hpp apilistener-configsync.cpp apilistener-filesync.cpp + apilistener.cpp apilistener.hpp apilistener.ti + apilistener-configsync.cpp apilistener-filesync.cpp apilistener-authority.cpp - apiuser.cpp apiuser.hpp apiuser-ti.hpp + apiuser.cpp apiuser.hpp apiuser.ti configfileshandler.cpp configfileshandler.hpp configobjectslock.cpp configobjectslock.hpp configobjectutility.cpp configobjectutility.hpp @@ -23,7 +19,7 @@ add_library(remote OBJECT consolehandler.cpp consolehandler.hpp createobjecthandler.cpp createobjecthandler.hpp deleteobjecthandler.cpp deleteobjecthandler.hpp - endpoint.cpp endpoint.hpp endpoint-ti.hpp + endpoint.cpp endpoint.hpp endpoint.ti eventqueue.cpp eventqueue.hpp eventshandler.cpp eventshandler.hpp filterutility.cpp filterutility.hpp @@ -44,16 +40,18 @@ add_library(remote OBJECT typequeryhandler.cpp typequeryhandler.hpp url.cpp url.hpp url-characters.hpp variablequeryhandler.cpp variablequeryhandler.hpp - zone.cpp zone.hpp zone-ti.hpp + zone.cpp zone.hpp zone.ti ) +target_mkclass(remote remote_generated) + target_link_libraries(remote PUBLIC - base - config lib Boost::coroutine ) +add_dependencies(remote base_generated) + set_target_properties ( remote PROPERTIES FOLDER Lib diff --git a/tools/mkclass/CMakeLists.txt b/tools/mkclass/CMakeLists.txt index ec0589912cb..a2b1bf69867 100644 --- a/tools/mkclass/CMakeLists.txt +++ b/tools/mkclass/CMakeLists.txt @@ -37,12 +37,29 @@ set_target_properties ( FOLDER Bin ) -macro(MKCLASS_TARGET ClassInput ClassImplOutput ClassHeaderOutput) - add_custom_command( - OUTPUT ${ClassImplOutput} ${ClassHeaderOutput} - COMMAND mkclass - ARGS ${ClassInput} ${CMAKE_CURRENT_BINARY_DIR}/${ClassImplOutput} ${CMAKE_CURRENT_BINARY_DIR}/${ClassHeaderOutput} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS mkclass ${ClassInput} - ) -endmacro() +function(target_mkclass target generator_target) + get_target_property(sources ${target} SOURCES) + + set(generated_headers) + set(generated_impls) + foreach(file ${sources}) + if(file MATCHES "\.ti$") + get_filename_component(basename ${file} NAME_WE) + set(generated_header ${CMAKE_CURRENT_BINARY_DIR}/${basename}-ti.hpp) + set(generated_impl ${CMAKE_CURRENT_BINARY_DIR}/${basename}-ti.cpp) + add_custom_command( + OUTPUT ${generated_impl} ${generated_header} + COMMAND mkclass + ARGS ${file} ${generated_impl} ${generated_header} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS mkclass ${file} + ) + list(APPEND generated_headers ${generated_header}) + list(APPEND generated_impls ${generated_impl}) + endif() + endforeach() + + target_sources(${target} PRIVATE ${generated_headers}) + add_custom_target(${generator_target} DEPENDS ${generated_headers} ${generated_impls}) + add_dependencies(${target} ${generator_target}) +endfunction() From b0c60556945f1390724bb3bfb4110a70e5f1c351 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Tue, 14 Jul 2026 15:41:06 +0200 Subject: [PATCH 14/15] (WIP) Enable presets in CI --- .github/workflows/linux.bash | 15 +++++++-------- Containerfile | 5 +++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/linux.bash b/.github/workflows/linux.bash index eb342042973..6728d9925c9 100755 --- a/.github/workflows/linux.bash +++ b/.github/workflows/linux.bash @@ -4,13 +4,14 @@ set -exo pipefail export PATH="/usr/lib/ccache/bin:/usr/lib/ccache:/usr/lib64/ccache:$PATH" export CCACHE_DIR=/icinga2/ccache export CTEST_OUTPUT_ON_FAILURE=1 +CMAKE_PRESET=release-gcc-ninja CMAKE_OPTS=() SCL_ENABLE_GCC=() # -Wstringop-overflow is notorious for false positives and has been a problem for years. # See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443 # -Wtemplate-id-cdtor leaks from using the generated headers. We should reenable this once # we're considering moving to C++20 and/or the -ti.hpp files are generated differently. -WARN_FLAGS="-Wall -Wextra -Wno-template-id-cdtor -Wno-stringop-overflow" +WARN_FLAGS="" # -Wattributes needs to be disabled to not get warnings in old compilers about not-yet # understood attributes, like [[gnu::no_dangling]] on many of the "stable" distros. @@ -105,11 +106,10 @@ case "$DISTRO" in -DUSE_SYSTEMD=OFF -DICINGA2_WITH_MYSQL=OFF -DICINGA2_WITH_PGSQL=OFF - -DCMAKE_{C,CXX}_FLAGS="${WARN_FLAGS}" ) ;; debian:*|ubuntu:*) - CMAKE_OPTS+=(-DICINGA2_LTO_BUILD=ON) + CMAKE_PRESET=release-gcc-ninja-lto source <(dpkg-buildflags --export=sh) export CFLAGS="${CFLAGS} ${WARN_FLAGS}" export CXXFLAGS="${CXXFLAGS} ${WARN_FLAGS}" @@ -122,8 +122,9 @@ case "$DISTRO" in esac ;; *) - CMAKE_OPTS+=(-DCMAKE_{C,CXX}_FLAGS="$(rpm -E '%{optflags} %{?march_flag}') ${WARN_FLAGS}") - export LDFLAGS="$(rpm -E '%{?build_ldflags}')" + # export CFLAGS="$(rpm -E '%{optflags} %{?march_flag}') ${WARN_FLAGS}" + # export CXXFLAGS="${CFLAGS}" + # export LDFLAGS="$(rpm -E '%{?build_ldflags}')" ;; esac @@ -131,9 +132,7 @@ mkdir /icinga2/build cd /icinga2/build "${SCL_ENABLE_GCC[@]}" cmake \ - -GNinja \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DICINGA2_UNITY_BUILD=ON \ + --preset ${CMAKE_PRESET} \ -DUSE_SYSTEMD=ON \ -DICINGA2_USER=$(id -un) \ -DICINGA2_GROUP=$(id -gn) \ diff --git a/Containerfile b/Containerfile index ad3e2302b8a..ffd523c1829 100644 --- a/Containerfile +++ b/Containerfile @@ -92,7 +92,7 @@ ARG TARGETPLATFORM # These arguments are used to configure the build of Icinga 2 and can be overridden # by the user when building the image. All of them have a default value suitable for our official image. ARG CMAKE_BUILD_TYPE=RelWithDebInfo -ARG ICINGA2_UNITY_BUILD=ON +ARG CMAKE_UNITY_BUILD=TRUE ARG ICINGA2_BUILD_TESTING=ON # The number of jobs to run in parallel when building Icinga 2. @@ -116,7 +116,8 @@ RUN --mount=type=bind,source=.,target=/icinga2,readonly \ # Podman supports forwarding notifications from containers to systemd, so build Icinga 2 with systemd support. -DUSE_SYSTEMD=ON \ -DBUILD_TESTING=${ICINGA2_BUILD_TESTING} \ - -DICINGA2_UNITY_BUILD=${ICINGA2_UNITY_BUILD} \ + -DCMAKE_UNITY_BUILD=${CMAKE_UNITY_BUILD} \ + -DCMAKE_UNITY_BUILD_BATCH_SIZE=0 \ # The command group name below is required for the prepare-dirs script to work, as it expects # the command group name, which by default is `icingacmd` to exist on the system. Since we # don't create the `icingacmd` command group in this image, we need to override it with icinga. From 0f6b36c938017f729be5db4832a537fa17850da7 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Tue, 14 Jul 2026 15:41:44 +0200 Subject: [PATCH 15/15] (Temp) Enable unity builds on Windows --- tools/win32/configure.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/win32/configure.ps1 b/tools/win32/configure.ps1 index a9a9040fb9c..1c3f7fe9ae8 100644 --- a/tools/win32/configure.ps1 +++ b/tools/win32/configure.ps1 @@ -60,6 +60,8 @@ if (Test-Path CMakeCache.txt) { } & cmake.exe "$sourcePath" ` + -DCMAKE_UNITY_BUILD=TRUE ` + -DCMAKE_UNITY_BUILD_BATCH_SIZE=16 ` -DCMAKE_BUILD_TYPE="$env:CMAKE_BUILD_TYPE" ` -G "$env:CMAKE_GENERATOR" -A "$env:CMAKE_GENERATOR_PLATFORM" -DCPACK_GENERATOR=WIX ` -DOPENSSL_ROOT_DIR="$env:OPENSSL_ROOT_DIR" `