diff --git a/.github/workflows/linux.bash b/.github/workflows/linux.bash index a41fce8cb5a..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. @@ -54,7 +55,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:*) @@ -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/CMakeLists.txt b/CMakeLists.txt index 82be4a0917e..058e9fe4c99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,11 +39,25 @@ 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) -set(HAVE_SYSTEMD ${USE_SYSTEMD}) - include(GNUInstallDirs) include(InstallConfig) include(SetFullDir) @@ -53,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") @@ -67,6 +79,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}") @@ -141,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") @@ -150,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() @@ -182,190 +198,64 @@ 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) -link_directories(${Boost_LIBRARY_DIRS}) -include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) +find_package(Threads REQUIRED) 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(Editline) -set(HAVE_EDITLINE "${EDITLINE_FOUND}") - -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) +if(USE_SYSTEMD) + find_package(Systemd REQUIRED) endif() -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib - ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/lib -) - -if(HAVE_SYSTEMD) - list(APPEND base_DEPS systemd) -endif() - -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() +find_package(Editline) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/icinga2") -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") - - # 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") - 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() - - 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) - -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) 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") -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() + add_link_option(-Wl,--dynamic-list-data) 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") @@ -382,8 +272,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) @@ -397,14 +286,15 @@ 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 - add_definitions(-D_GNU_SOURCE) + add_compile_definitions(_GNU_SOURCE) endif() if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") @@ -432,14 +322,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 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" + } + ] +} 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. 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() 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/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/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 b3b36207ac6..b58c378c5a7 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -12,8 +12,6 @@ #cmakedefine HAVE_PTHREAD_CREATE #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/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/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 b31ede44ddd..b510ef7b19e 100644 --- a/lib/base/CMakeLists.txt +++ b/lib/base/CMakeLists.txt @@ -1,53 +1,45 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -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) - -set(base_SOURCES +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 @@ -57,7 +49,7 @@ set(base_SOURCES 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 @@ -77,9 +69,9 @@ set(base_SOURCES 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 @@ -95,9 +87,24 @@ set(base_SOURCES workqueue.cpp workqueue.hpp ) +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 + ) + + 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,7 +114,9 @@ if(WIN32) DEPENDS windowseventloglogger-provider.mc ) - list(APPEND base_SOURCES windowseventloglogger-provider.h) + target_sources(base PRIVATE + windowseventloglogger-provider.h + ) add_custom_command( OUTPUT windowseventloglogger-provider.res @@ -122,35 +131,24 @@ 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_mkclass(base base_generated config_generated) + +target_link_libraries(base PUBLIC + lib ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(base base base_SOURCES) -endif() +if(USE_SYSTEMD) + target_link_libraries(lib PUBLIC + Systemd + ) -if(HAVE_SYSTEMD) - find_path(SYSTEMD_INCLUDE_DIR - NAMES systemd/sd-daemon.h - HINTS ${SYSTEMD_ROOT_DIR}) - include_directories(SYSTEM ${SYSTEMD_INCLUDE_DIR}) - set_property( - SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/journaldlogger.cpp - APPEND PROPERTY COMPILE_DEFINITIONS + # 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/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 diff --git a/lib/checker/CMakeLists.txt b/lib/checker/CMakeLists.txt index 5fc90efb0a9..dcc09a8a3ea 100644 --- a/lib/checker/CMakeLists.txt +++ b/lib/checker/CMakeLists.txt @@ -1,19 +1,17 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(checkercomponent.ti checkercomponent-ti.cpp checkercomponent-ti.hpp) - -set(checker_SOURCES - checkercomponent.cpp checkercomponent.hpp checkercomponent-ti.hpp +add_library(checker OBJECT + checkercomponent.cpp checkercomponent.hpp checkercomponent.ti ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(checker checker checker_SOURCES) -endif() +target_mkclass(checker checker_generated) -add_library(checker OBJECT ${checker_SOURCES}) +target_link_libraries(checker + lib +) -add_dependencies(checker base config icinga remote) +add_dependencies(checker base_generated icinga_generated remote_generated) set_target_properties ( checker PROPERTIES diff --git a/lib/cli/CMakeLists.txt b/lib/cli/CMakeLists.txt index e53ac571aca..fa075559876 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,15 @@ set(cli_SOURCES variableutility.cpp variableutility.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(cli cli cli_SOURCES) -endif() +target_link_libraries(cli PUBLIC + lib +) -add_library(cli OBJECT ${cli_SOURCES}) +add_dependencies(cli base_generated icinga_generated remote_generated) -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..1f7eaf42f50 100644 --- a/lib/compat/CMakeLists.txt +++ b/lib/compat/CMakeLists.txt @@ -1,21 +1,18 @@ # 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) - -set(compat_SOURCES - compatlogger.cpp compatlogger.hpp compatlogger-ti.hpp - externalcommandlistener.cpp externalcommandlistener.hpp externalcommandlistener-ti.hpp +add_library(compat OBJECT + compatlogger.cpp compatlogger.hpp compatlogger.ti + externalcommandlistener.cpp externalcommandlistener.hpp externalcommandlistener.ti ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(compat compat compat_SOURCES) -endif() +target_mkclass(compat compat_generated) -add_library(compat OBJECT ${compat_SOURCES}) +target_link_libraries(compat PUBLIC + lib +) -add_dependencies(compat base config icinga) +add_dependencies(compat base_generated icinga_generated) set_target_properties ( compat PROPERTIES diff --git a/lib/config/CMakeLists.txt b/lib/config/CMakeLists.txt index e75e203be13..c6f205fe19c 100644 --- a/lib/config/CMakeLists.txt +++ b/lib/config/CMakeLists.txt @@ -5,42 +5,47 @@ 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) - 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_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) -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}) +target_link_libraries(config PUBLIC + lib +) -add_dependencies(config base) +add_dependencies(config base_generated) set_target_properties ( config PROPERTIES diff --git a/lib/db_ido/CMakeLists.txt b/lib/db_ido/CMakeLists.txt index 6e7d0c452d1..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) -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 + dbconnection.cpp dbconnection.hpp dbconnection.ti dbevents.cpp dbevents.hpp dbobject.cpp dbobject.hpp dbquery.cpp dbquery.hpp @@ -27,13 +25,13 @@ set(db_ido_SOURCES zonedbobject.cpp zonedbobject.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(db_ido db_ido db_ido_SOURCES) -endif() +target_mkclass(db_ido db_ido_generated) -add_library(db_ido OBJECT ${db_ido_SOURCES}) +target_link_libraries(db_ido PUBLIC + lib +) -add_dependencies(db_ido base config icinga remote) +add_dependencies(db_ido base_generated icinga_generated remote_generated) set_target_properties ( db_ido PROPERTIES diff --git a/lib/db_ido_mysql/CMakeLists.txt b/lib/db_ido_mysql/CMakeLists.txt index dde48d8284a..5857e283dfa 100644 --- a/lib/db_ido_mysql/CMakeLists.txt +++ b/lib/db_ido_mysql/CMakeLists.txt @@ -1,21 +1,18 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(idomysqlconnection.ti idomysqlconnection-ti.cpp idomysqlconnection-ti.hpp) - -set(db_ido_mysql_SOURCES - idomysqlconnection.cpp idomysqlconnection.hpp idomysqlconnection-ti.hpp +add_library(db_ido_mysql OBJECT + idomysqlconnection.cpp idomysqlconnection.hpp idomysqlconnection.ti ) -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}) +target_mkclass(db_ido_mysql db_ido_mysql_generated) -include_directories(SYSTEM ${MYSQL_INCLUDE_DIR}) +target_link_libraries(db_ido_mysql PUBLIC + lib + MySQL +) -add_dependencies(db_ido_mysql base config icinga db_ido) +add_dependencies(db_ido_mysql db_ido_generated) 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..66ed5d03cb5 100644 --- a/lib/db_ido_pgsql/CMakeLists.txt +++ b/lib/db_ido_pgsql/CMakeLists.txt @@ -1,21 +1,18 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(idopgsqlconnection.ti idopgsqlconnection-ti.cpp idopgsqlconnection-ti.hpp) - -set(db_ido_pgsql_SOURCES - idopgsqlconnection.cpp idopgsqlconnection.hpp idopgsqlconnection-ti.hpp +add_library(db_ido_pgsql OBJECT + idopgsqlconnection.cpp idopgsqlconnection.hpp idopgsqlconnection.ti ) -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}) +target_mkclass(db_ido_pgsql db_ido_pgsql_generated) -include_directories(SYSTEM ${PostgreSQL_INCLUDE_DIRS}) +target_link_libraries(db_ido_pgsql PUBLIC + lib + PostgreSQL +) -add_dependencies(db_ido_pgsql base config icinga db_ido) +add_dependencies(db_ido_pgsql base_generated db_ido_generated) set_target_properties ( db_ido_pgsql PROPERTIES diff --git a/lib/icinga/CMakeLists.txt b/lib/icinga/CMakeLists.txt index 53aa214b2c9..15cfb384742 100644 --- a/lib/icinga/CMakeLists.txt +++ b/lib/icinga/CMakeLists.txt @@ -1,75 +1,54 @@ # 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) -set(icinga_SOURCES +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 ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(icinga icinga icinga_SOURCES) -endif() +target_link_libraries(icinga PUBLIC + lib +) -add_library(icinga OBJECT ${icinga_SOURCES}) +target_mkclass(icinga icinga_generated) -add_dependencies(icinga base config remote) +add_dependencies(icinga base_generated remote_generated) set_target_properties ( icinga PROPERTIES diff --git a/lib/icingadb/CMakeLists.txt b/lib/icingadb/CMakeLists.txt index 49ac16b89a4..592a14bdc63 100644 --- a/lib/icingadb/CMakeLists.txt +++ b/lib/icingadb/CMakeLists.txt @@ -1,24 +1,20 @@ # 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) -set(icingadb_SOURCES - icingadb.cpp icingadb-objects.cpp icingadb-stats.cpp icingadb-utility.cpp icingadb-worker.cpp redisconnection.cpp icingadb-ti.hpp +add_library(icingadb OBJECT + icingadb.cpp icingadb-objects.cpp icingadb-stats.cpp icingadb-utility.cpp icingadb-worker.cpp redisconnection.cpp icingadb.ti icingadbchecktask.cpp icingadb-itl.cpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(icingadb icingadb icingadb_SOURCES) -endif() - -add_library(icingadb OBJECT ${icingadb_SOURCES}) +target_mkclass(icingadb icingadb_generated) -include_directories(SYSTEM ${icinga2_SOURCE_DIR}/third-party) +target_link_libraries(icingadb PUBLIC + lib +) -add_dependencies(icingadb base config icinga remote) +add_dependencies(icingadb base_generated icinga_generated remote_generated) set_target_properties ( icingadb PROPERTIES diff --git a/lib/livestatus/CMakeLists.txt b/lib/livestatus/CMakeLists.txt index 3d8e3b27816..898128677a5 100644 --- a/lib/livestatus/CMakeLists.txt +++ b/lib/livestatus/CMakeLists.txt @@ -1,9 +1,7 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -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 @@ -24,7 +22,7 @@ set(livestatus_SOURCES 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,13 +41,13 @@ set(livestatus_SOURCES zonestable.cpp zonestable.hpp ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(livestatus livestatus livestatus_SOURCES) -endif() +target_mkclass(livestatus livestatus_generated) -add_library(livestatus OBJECT ${livestatus_SOURCES}) +target_link_libraries(livestatus PUBLIC + lib +) -add_dependencies(livestatus base config icinga remote) +add_dependencies(livestatus base_generated icinga_generated remote_generated) 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..daef0bd987c 100644 --- a/lib/notification/CMakeLists.txt +++ b/lib/notification/CMakeLists.txt @@ -1,19 +1,17 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later -mkclass_target(notificationcomponent.ti notificationcomponent-ti.cpp notificationcomponent-ti.hpp) - -set(notification_SOURCES - notificationcomponent.cpp notificationcomponent.hpp notificationcomponent-ti.hpp +add_library(notification OBJECT + notificationcomponent.cpp notificationcomponent.hpp notificationcomponent.ti ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(notification notification notification_SOURCES) -endif() +target_mkclass(notification notification_generated) -add_library(notification OBJECT ${notification_SOURCES}) +target_link_libraries(notification PUBLIC + lib +) -add_dependencies(notification base config icinga) +add_dependencies(notification base_generated icinga_generated) 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..0ea12a2e896 100644 --- a/lib/perfdata/CMakeLists.txt +++ b/lib/perfdata/CMakeLists.txt @@ -1,56 +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) - -set(perfdata_SOURCES - 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 +add_library(perfdata OBJECT + 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 ) -if(ICINGA2_WITH_OPENTELEMETRY) - mkclass_target(otlpmetricswriter.ti otlpmetricswriter-ti.cpp otlpmetricswriter-ti.hpp) - list(APPEND perfdata_SOURCES - otlpmetricswriter.cpp otlpmetricswriter.hpp otlpmetricswriter-ti.hpp - ) -endif() - -if(ICINGA2_UNITY_BUILD) - mkunity_target(perfdata perfdata perfdata_SOURCES) -endif() +target_link_libraries(perfdata PUBLIC + lib +) -add_library(perfdata OBJECT ${perfdata_SOURCES}) +add_dependencies(perfdata base_generated icinga_generated) -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_sources(perfdata PRIVATE + 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 8e3eae87a0c..75a05dfca7e 100644 --- a/lib/pgsql_shim/CMakeLists.txt +++ b/lib/pgsql_shim/CMakeLists.txt @@ -1,25 +1,19 @@ # 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 + lib + PostgreSQL +) include(GenerateExportHeader) generate_export_header(pgsql_shim) -target_link_libraries(pgsql_shim ${PostgreSQL_LIBRARIES}) - set_target_properties ( pgsql_shim PROPERTIES FOLDER Lib diff --git a/lib/remote/CMakeLists.txt b/lib/remote/CMakeLists.txt index b7d0fc052a3..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) - -set(remote_SOURCES +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 @@ set(remote_SOURCES 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,17 @@ set(remote_SOURCES 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 ) -if(ICINGA2_UNITY_BUILD) - mkunity_target(remote remote remote_SOURCES) -endif() +target_mkclass(remote remote_generated) -add_library(remote OBJECT ${remote_SOURCES}) +target_link_libraries(remote PUBLIC + lib + Boost::coroutine +) -add_dependencies(remote base config) +add_dependencies(remote base_generated) 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/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 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..a2b1bf69867 100644 --- a/tools/mkclass/CMakeLists.txt +++ b/tools/mkclass/CMakeLists.txt @@ -8,9 +8,13 @@ bison_target(class_parser class_parser.yy ${CMAKE_CURRENT_BINARY_DIR}/class_pars flex_target(class_lexer class_lexer.ll ${CMAKE_CURRENT_BINARY_DIR}/class_lexer.cc) 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}) @@ -33,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() 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; -} 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" `