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:*) 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..2c4ac79861c --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,125 @@ +{ + "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": "16", + + "CMAKE_C_FLAGS_INIT": "$env{C_FLAGS_COMMON} $env{FLAGS_COMPILER} $env{CFLAGS}", + "CMAKE_CXX_FLAGS_INIT": "$env{CXX_FLAGS_COMMON} $env{FLAGS_COMPILER} $env{CXXFLAGS}", + "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}" + }, + "environment": { + "C_FLAGS_COMMON" : "-Wall -Wextra", + "CXX_FLAGS_COMMON" : "$env{C_FLAGS_COMMON} -Wsuggest-override -Wrange-loop-construct -Wno-template-id-cdtor", + "FLAGS_DEBUG_COMMON" : "-Og", + + "CFLAGS": "$penv{CFLAGS}", + "CXXFLAGS": "$penv{CXXFLAGS}" + } + }, + { + "name": "gcc", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "gcc", + "CMAKE_CXX_COMPILER": "g++" + }, + "environment": { + "FLAGS_COMPILER": "-Wno-stringop-overflow" + } + }, + { + "name": "clang", + "hidden": true, + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++" + }, + "environment": { + "FLAGS_COMPILER": "-Winconsistent-missing-override -Wno-unknown-attributes -fcolor-diagnostics", + "FLAGS_DEBUG_COMPILER": "-fno-limit-debug-info" + } + }, + { + "name": "ninja", + "hidden": true, + "generator": "Ninja" + }, + { + "name": "make", + "hidden": true, + "generator": "Unix Makefiles" + }, + { + "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": "debug-gcc", + "inherits": [ "default", "gcc", "make", "debug" ] + }, + { + "name": "release-clang", + "inherits": [ "default", "clang", "make", "release" ] + }, + { + "name": "debug-clang", + "inherits": [ "default", "clang", "make", "debug" ] + }, + { + "name": "release-gcc-ninja", + "inherits": [ "default", "gcc", "ninja", "release" ] + }, + { + "name": "debug-gcc-ninja", + "inherits": [ "default", "gcc", "ninja", "debug" ] + }, + { + "name": "release-clang-ninja", + "inherits": [ "default", "clang", "ninja", "release" ] + }, + { + "name": "debug-clang-ninja", + "inherits": [ "default", "clang", "ninja", "debug" ] + } + ], + "buildPresets": [ + { + "name": "release", + "configurePreset": "release" + }, + { + "name": "debug", + "configurePreset": "debug" + } + ] +} 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/base/CMakeLists.txt b/lib/base/CMakeLists.txt index b31ede44ddd..b40571f62c4 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,33 @@ 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} +) + 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,7 +132,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 +149,34 @@ 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} + Threads::Threads + 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) + target_link_libraries(base 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..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..e2737f3978e 100644 --- a/lib/config/CMakeLists.txt +++ b/lib/config/CMakeLists.txt @@ -5,42 +5,45 @@ 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}) - -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/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..bc082e34d14 100644 --- a/tools/mkclass/CMakeLists.txt +++ b/tools/mkclass/CMakeLists.txt @@ -1,6 +1,9 @@ # SPDX-FileCopyrightText: 2012 Icinga GmbH # SPDX-License-Identifier: GPL-2.0-or-later +# TODO: Make this add targets, like config_mkclass, remote_mkclass that can be used by other +# modules. This would have the benefit that for example remote wouldn't have to wait +# fore the entirety of base to compile, just for the headers to be generated. find_package(BISON 2.3.0 REQUIRED) find_package(FLEX 2.5.31 REQUIRED) @@ -8,9 +11,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}) 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; -}