2019-02-25 15:09:36 +01:00
# Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+
2013-11-03 13:45:26 +01:00
2023-02-23 15:49:20 +01:00
cmake_minimum_required ( VERSION 2.8.12 )
2019-02-07 16:33:59 +01:00
set ( BOOST_MIN_VERSION "1.66.0" )
2022-08-15 17:29:23 +02:00
if ( "${CMAKE_VERSION}" VERSION_LESS "3.8" ) # SLES 12.5
if ( NOT MSVC )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17" )
endif ( )
else ( )
set ( CMAKE_CXX_STANDARD 17 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
endif ( )
2013-12-18 12:54:49 +01:00
2013-11-03 13:45:26 +01:00
project ( icinga2 )
2014-06-23 10:56:12 +02:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" )
2014-06-15 02:17:01 +02:00
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/cmake" )
2013-11-03 13:45:26 +01:00
2013-11-20 16:36:11 +01:00
if ( NOT CMAKE_BUILD_TYPE )
2013-11-30 13:47:51 +01:00
set ( CMAKE_BUILD_TYPE Release CACHE STRING
2018-01-19 09:18:52 +01:00
" C h o o s e t h e t y p e o f b u i l d , o p t i o n s a r e : N o n e D e b u g R e l e a s e R e l W i t h D e b I n f o M i n S i z e R e l . "
F O R C E )
2013-11-20 16:36:11 +01:00
endif ( )
2023-02-23 14:54:57 +01:00
if ( WIN32 )
set ( ICINGA2_MASTER OFF )
else ( )
set ( ICINGA2_MASTER ON )
endif ( )
option ( ICINGA2_WITH_MYSQL "Build the MySQL IDO module" ${ ICINGA2_MASTER } )
option ( ICINGA2_WITH_PGSQL "Build the PostgreSQL IDO module" ${ ICINGA2_MASTER } )
2014-12-19 09:45:35 +01:00
option ( ICINGA2_WITH_CHECKER "Build the checker module" ON )
2023-02-23 14:54:57 +01:00
option ( ICINGA2_WITH_COMPAT "Build the compat module" ${ ICINGA2_MASTER } )
option ( ICINGA2_WITH_LIVESTATUS "Build the Livestatus module" ${ ICINGA2_MASTER } )
2014-12-19 09:45:35 +01:00
option ( ICINGA2_WITH_NOTIFICATION "Build the notification module" ON )
2023-02-22 17:51:30 +01:00
option ( ICINGA2_WITH_PERFDATA "Build the perfdata module" ${ ICINGA2_MASTER } )
2015-11-25 15:24:04 +01:00
option ( ICINGA2_WITH_TESTS "Run unit tests" ON )
2023-02-23 14:54:57 +01:00
option ( ICINGA2_WITH_ICINGADB "Build the IcingaDB module" ${ ICINGA2_MASTER } )
2019-11-02 12:02:46 +01:00
2018-01-17 13:52:23 +01:00
option ( USE_SYSTEMD
" C o n f i g u r e i c i n g a a s n a t i v e s y s t e m d s e r v i c e i n s t e a d o f a S y s V i n i t s c r i p t " O F F )
set ( HAVE_SYSTEMD ${ USE_SYSTEMD } )
2014-07-22 13:18:41 +02:00
include ( GNUInstallDirs )
2014-12-19 09:51:14 +01:00
include ( InstallConfig )
2018-07-31 11:59:09 +02:00
include ( SetFullDir )
2014-07-22 13:18:41 +02:00
2013-12-05 09:42:42 +01:00
set ( ICINGA2_USER "icinga" CACHE STRING "Icinga 2 user" )
set ( ICINGA2_GROUP "icinga" CACHE STRING "Icinga 2 group" )
set ( ICINGA2_COMMAND_GROUP "icingacmd" CACHE STRING "Icinga 2 command group" )
2014-07-22 13:22:39 +02:00
set ( ICINGA2_PLUGINDIR "/usr/lib/nagios/plugins" CACHE STRING "Path for the check plugins" )
2014-05-18 14:33:38 +02:00
set ( ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe" )
2015-03-01 01:27:42 +01:00
set ( ICINGA2_UNITY_BUILD ON CACHE BOOL "Whether to perform a unity build" )
2015-03-04 08:57:20 +01:00
set ( ICINGA2_LTO_BUILD OFF CACHE BOOL "Whether to use LTO" )
2013-11-03 13:45:26 +01:00
2018-07-31 11:59:09 +02:00
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" )
set ( ICINGA2_DATADIR "${CMAKE_INSTALL_LOCALSTATEDIR}/lib/icinga2" CACHE FILEPATH "Data directory for the daemon, e.g. /var/lib/icinga2" )
set ( ICINGA2_LOGDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/log/icinga2" CACHE FILEPATH "Logging directory, e.g. /var/log/icinga2" )
set ( ICINGA2_SPOOLDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/spool/icinga2" CACHE FILEPATH "Spooling directory, e.g. /var/spool/icinga2" )
set ( ICINGA2_RUNDIR "${CMAKE_INSTALL_LOCALSTATEDIR}/run" CACHE STRING "/run directory (deprecated, please use ICINGA2_INITRUNDIR)" )
set ( ICINGA2_INITRUNDIR "${ICINGA2_RUNDIR}/icinga2" CACHE FILEPATH "Runtime data for the init system, e.g. /run/icinga2" )
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" )
# ensure absolute paths
set_full_dir ( ICINGA2_FULL_CONFIGDIR "${ICINGA2_CONFIGDIR}" )
set_full_dir ( ICINGA2_FULL_CACHEDIR "${ICINGA2_CACHEDIR}" )
set_full_dir ( ICINGA2_FULL_DATADIR "${ICINGA2_DATADIR}" )
set_full_dir ( ICINGA2_FULL_LOGDIR "${ICINGA2_LOGDIR}" )
set_full_dir ( ICINGA2_FULL_SPOOLDIR "${ICINGA2_SPOOLDIR}" )
set_full_dir ( ICINGA2_FULL_RUNDIR "${ICINGA2_RUNDIR}" )
set_full_dir ( ICINGA2_FULL_INITRUNDIR "${ICINGA2_INITRUNDIR}" )
set_full_dir ( ICINGA2_FULL_PKGDATADIR "${ICINGA2_PKGDATADIR}" )
set_full_dir ( ICINGA2_FULL_INCLUDEDIR "${ICINGA2_INCLUDEDIR}" )
2018-04-19 08:49:47 +02:00
2018-07-31 11:59:09 +02:00
set ( LOGROTATE_DIR "${CMAKE_INSTALL_SYSCONFDIR}/logrotate.d" CACHE STRING "Location of logrotate configs, e.g. /etc/logrotate.d" )
set ( BASHCOMPLETION_DIR "${CMAKE_INSTALL_SYSCONFDIR}/bash_completion.d" CACHE STRING "Location of bash_completion files, e.g. /etc/bash_completion.d" )
if ( NOT WIN32 )
set ( ICINGA2_SYSCONFIGFILE "${CMAKE_INSTALL_SYSCONFDIR}/sysconfig/icinga2" CACHE PATH "where to store configuation for the init system, defaults to /etc/sysconfig/icinga2" )
2018-04-19 08:49:47 +02:00
endif ( )
2016-08-10 08:03:54 +02:00
site_name ( ICINGA2_BUILD_HOST_NAME )
set ( ICINGA2_BUILD_COMPILER_NAME "${CMAKE_CXX_COMPILER_ID}" )
if ( NOT CMAKE_CXX_COMPILER_VERSION )
execute_process ( COMMAND ${ CMAKE_CXX_COMPILER } -dumpversion
2016-08-10 08:22:17 +02:00
O U T P U T _ V A R I A B L E C M A K E _ C X X _ C O M P I L E R _ V E R S I O N O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
2016-08-10 08:03:54 +02:00
endif ( )
set ( ICINGA2_BUILD_COMPILER_VERSION "${CMAKE_CXX_COMPILER_VERSION}" )
2013-11-03 13:45:26 +01:00
file ( READ "${CMAKE_CURRENT_SOURCE_DIR}/COPYING" ICINGA2_LICENSE_GPL )
set ( ICINGA2_LICENSE "${ICINGA2_LICENSE_GPL}\n\n---\n\n${ICINGA2_LICENSE_ADDITIONS}" )
file ( WRITE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" ${ ICINGA2_LICENSE } )
2021-01-15 17:41:49 +01:00
file ( STRINGS ICINGA2_VERSION SPEC_VERSION REGEX "^Version:" )
2016-08-25 17:32:20 +02:00
string ( LENGTH "${SPEC_VERSION}" SPEC_VERSION_LENGTH )
math ( EXPR SPEC_VERSION_LENGTH "${SPEC_VERSION_LENGTH} - 9" )
string ( SUBSTRING ${ SPEC_VERSION } 9 ${ SPEC_VERSION_LENGTH } SPEC_VERSION )
configure_file ( icinga-spec-version.h.cmake icinga-spec-version.h )
2013-11-03 13:45:26 +01:00
include ( GetGitRevisionDescription )
git_describe ( GIT_VERSION --tags )
2014-05-18 14:19:16 +02:00
if ( EXISTS ${ CMAKE_CURRENT_SOURCE_DIR } /icinga-version.h.force )
configure_file ( icinga-version.h.force ${ CMAKE_CURRENT_BINARY_DIR } /icinga-version.h COPYONLY )
2013-11-27 10:35:48 +01:00
else ( )
2014-05-18 14:33:38 +02:00
if ( NOT ICINGA2_GIT_VERSION_INFO OR GIT_VERSION MATCHES "-NOTFOUND$" )
2021-01-15 17:41:49 +01:00
file ( STRINGS ICINGA2_VERSION SPEC_REVISION REGEX "^Revision: " )
2014-05-21 10:29:44 +02:00
string ( LENGTH "${SPEC_REVISION}" SPEC_REVISION_LENGTH )
2018-04-05 16:41:10 +02:00
math ( EXPR SPEC_REVISION_LENGTH "${SPEC_REVISION_LENGTH} - 10" )
string ( SUBSTRING ${ SPEC_REVISION } 10 ${ SPEC_REVISION_LENGTH } SPEC_REVISION )
2014-05-21 10:29:44 +02:00
set ( GIT_VERSION "r${SPEC_VERSION}-${SPEC_REVISION}" )
2019-04-04 12:55:52 +02:00
set ( ICINGA2_VERSION "${SPEC_VERSION}" )
else ( )
# use GIT version as ICINGA2_VERSION
string ( REGEX REPLACE "^[rv]" "" ICINGA2_VERSION "${GIT_VERSION}" )
2014-05-18 14:19:16 +02:00
endif ( )
2013-11-27 10:35:48 +01:00
configure_file ( icinga-version.h.cmake icinga-version.h )
endif ( )
2013-11-03 13:45:26 +01:00
2019-04-04 12:55:52 +02:00
# NuGet on Windows requires a semantic versioning, example: 2.10.4.123 (only 4 element, only numeric)
string ( REGEX REPLACE "-([0-9]+).*$" ".\\1" ICINGA2_VERSION_SAFE "${ICINGA2_VERSION}" )
2019-07-25 10:49:11 +02:00
string ( REGEX REPLACE "-[^\\.]*(.*)$" "\\1" ICINGA2_VERSION_SAFE "${ICINGA2_VERSION_SAFE}" )
2019-09-26 13:37:09 +02:00
string ( REGEX REPLACE "^([0-9]+\\.[0-9]+\\.[0-9]+)[\\.]?[0-9]*" "\\1" CHOCO_VERSION_SHORT "${ICINGA2_VERSION_SAFE}" )
message ( STATUS "ICINGA2_VERSION_SAFE=${ICINGA2_VERSION_SAFE} CHOCO_VERSION_SHORT=${CHOCO_VERSION_SHORT}" )
2019-04-04 12:55:52 +02:00
2013-11-03 13:45:26 +01:00
if ( WIN32 )
set ( Boost_USE_STATIC_LIBS ON )
2019-04-04 12:11:15 +02:00
# Disabled for linking issues for newer Boost versions, they link against Windows SDKs
#add_definitions(-DBOOST_ALL_NO_LIB)
2019-04-04 12:20:52 +02:00
# 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" )
2019-04-04 14:42:58 +02:00
# detect if 32-bit target
if ( CMAKE_VS_PLATFORM_NAME STREQUAL "Win32" )
# SAFESEH is not supported in Boost on Windows x86
# 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" )
endif ( )
2013-11-03 13:45:26 +01:00
endif ( )
2016-03-26 14:41:58 +01:00
if ( NOT DEFINED LOGROTATE_HAS_SU )
set ( LOGROTATE_HAS_SU OFF )
2016-08-23 00:59:24 +02:00
find_program ( LOGROTATE_BINARY logrotate )
execute_process ( COMMAND ${ LOGROTATE_BINARY } ERROR_VARIABLE LOGROTATE_OUTPUT )
2016-03-26 14:41:58 +01:00
if ( LOGROTATE_OUTPUT )
string ( REGEX REPLACE "^logrotate ([0-9.]*).*" "\\1" LOGROTATE_VERSION
$ { L O G R O T A T E _ O U T P U T } )
message ( STATUS "Found logrotate (found version \" ${ LOGROTATE_VERSION } \")")
if ( "${LOGROTATE_VERSION}" VERSION_GREATER "3.7.9" )
set ( LOGROTATE_HAS_SU ON )
endif ( )
endif ( )
endif ( )
if ( LOGROTATE_HAS_SU )
set ( LOGROTATE_USE_SU "\n\tsu ${ICINGA2_USER} ${ICINGA2_GROUP}" )
2019-03-31 21:22:31 +02:00
else ( )
set ( LOGROTATE_CREATE "\n\tcreate 644 ${ICINGA2_USER} ${ICINGA2_GROUP}" )
2016-03-26 14:41:58 +01:00
endif ( )
2022-07-21 17:53:08 +02:00
find_package ( Boost ${ BOOST_MIN_VERSION } COMPONENTS coroutine context date_time filesystem iostreams thread system program_options regex REQUIRED )
2013-12-18 12:54:49 +01:00
2019-02-15 13:32:55 +01:00
# 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 )
2019-04-09 17:42:02 +02:00
add_definitions ( -DBOOST_FILESYSTEM_NO_DEPRECATED )
2020-12-14 15:59:56 +01:00
# Required for Boost v1.74+
add_definitions ( -DBOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT )
2013-11-03 13:45:26 +01:00
link_directories ( ${ Boost_LIBRARY_DIRS } )
include_directories ( ${ Boost_INCLUDE_DIRS } )
find_package ( OpenSSL REQUIRED )
include_directories ( ${ OPENSSL_INCLUDE_DIR } )
2018-01-17 14:59:02 +01:00
set ( base_DEPS ${ CMAKE_DL_LIBS } ${ Boost_LIBRARIES } ${ OPENSSL_LIBRARIES } )
set ( base_OBJS $< TARGET_OBJECTS:mmatch > $< TARGET_OBJECTS:socketpair > $< TARGET_OBJECTS:base > )
2018-10-18 15:22:50 +02:00
# JSON
find_package ( JSON )
include_directories ( ${ JSON_INCLUDE } )
2014-10-27 12:42:57 +01:00
2019-03-14 09:32:09 +01:00
# UTF8CPP
find_package ( UTF8CPP )
include_directories ( ${ UTF8CPP_INCLUDE } )
2015-03-17 10:42:46 +01:00
find_package ( Editline )
set ( HAVE_EDITLINE "${EDITLINE_FOUND}" )
find_package ( Termcap )
set ( HAVE_TERMCAP "${TERMCAP_FOUND}" )
2013-11-03 13:45:26 +01:00
include_directories (
2014-10-13 09:51:49 +02:00
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / l i b
$ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / l i b
2013-11-03 13:45:26 +01:00
)
2018-01-17 04:28:21 +01:00
if ( UNIX OR CYGWIN )
2018-01-17 14:59:02 +01:00
list ( APPEND base_OBJS $< TARGET_OBJECTS:execvpe > )
2018-01-17 04:28:21 +01:00
endif ( )
2018-01-17 13:52:23 +01:00
if ( HAVE_SYSTEMD )
list ( APPEND base_DEPS systemd )
endif ( )
2018-01-17 04:28:21 +01:00
if ( EDITLINE_FOUND )
list ( APPEND base_DEPS ${ EDITLINE_LIBRARIES } )
include_directories ( ${ EDITLINE_INCLUDE_DIR } )
endif ( )
if ( TERMCAP_FOUND )
list ( APPEND base_DEPS ${ TERMCAP_LIBRARIES } )
include_directories ( ${ TERMCAP_INCLUDE_DIR } )
endif ( )
if ( WIN32 )
list ( APPEND base_DEPS ws2_32 dbghelp shlwapi msi )
endif ( )
2016-08-28 17:19:20 +02:00
set ( CMAKE_MACOSX_RPATH 1 )
2019-03-12 15:53:52 +01:00
set ( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/icinga2" )
2013-11-03 13:45:26 +01:00
2015-07-14 15:02:43 +02:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
2020-03-17 18:12:36 +01:00
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" )
2017-09-27 20:04:43 +02:00
# 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 ( )
2013-11-30 13:47:51 +01:00
endif ( )
2014-12-04 22:02:44 +01:00
if ( CMAKE_C_COMPILER_ID STREQUAL "SunPro" )
2014-09-03 08:24:14 +02:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mt" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mt -library=stlport4" )
endif ( )
2014-12-04 22:02:44 +01:00
if ( CMAKE_C_COMPILER_ID STREQUAL "GNU" )
if ( CMAKE_SYSTEM_NAME MATCHES AIX )
2019-08-20 15:46:45 +02:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -lpthread" )
2014-04-16 15:08:47 +02:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -lpthread" )
2015-02-13 11:21:20 +01:00
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" )
2015-03-01 15:29:57 +01:00
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -lpthread" )
2017-12-31 07:22:16 +01:00
set ( CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -lpthread" )
2014-04-16 15:08:47 +02:00
else ( )
2016-02-16 13:08:21 +01:00
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -pthread" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pthread" )
2014-04-16 15:08:47 +02:00
endif ( )
2013-11-05 07:32:11 +01:00
endif ( )
2016-08-27 21:42:05 +02:00
include ( CheckCXXCompilerFlag )
2017-12-24 07:27:57 +01:00
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 ( )
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" )
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" )
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" )
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" )
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 ( )
2015-03-04 08:57:20 +01:00
if ( ICINGA2_LTO_BUILD )
2016-08-27 21:42:05 +02:00
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" )
2019-08-20 20:52:51 +02:00
set ( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto" )
2018-01-17 14:26:37 +01:00
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 ( )
2016-08-27 21:42:05 +02:00
endif ( )
2015-03-04 08:57:20 +01:00
endif ( )
2013-11-03 13:45:26 +01:00
if ( MSVC )
add_definitions ( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS )
endif ( )
set ( LIBRARY_OUTPUT_PATH ${ CMAKE_BINARY_DIR } /Bin/ ${ CMAKE_BUILD_TYPE } CACHE PATH "Library output path" )
set ( EXECUTABLE_OUTPUT_PATH ${ CMAKE_BINARY_DIR } /Bin/ ${ CMAKE_BUILD_TYPE } CACHE PATH "Executable output path" )
2014-08-31 11:01:37 +02:00
include ( CheckSymbolExists )
2013-11-03 13:45:26 +01:00
include ( CheckFunctionExists )
2013-11-13 11:55:44 +01:00
include ( CheckLibraryExists )
2014-09-02 13:02:22 +02:00
include ( CheckIncludeFileCXX )
2014-08-31 11:01:37 +02:00
check_symbol_exists ( __COUNTER__ "" HAVE_COUNTER_MACRO )
2016-08-27 09:35:08 +02:00
if ( NOT HAVE_COUNTER_MACRO )
message ( FATAL_ERROR "Your C/C++ compiler does not support the __COUNTER__ macro." )
2014-08-31 11:01:37 +02:00
endif ( )
2014-12-19 12:19:28 +01:00
set ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DI2_DEBUG" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DI2_DEBUG" )
2014-11-12 11:34:59 +01:00
2013-11-03 13:45:26 +01:00
check_function_exists ( vfork HAVE_VFORK )
check_function_exists ( backtrace_symbols HAVE_BACKTRACE_SYMBOLS )
check_function_exists ( pipe2 HAVE_PIPE2 )
2014-09-06 02:20:25 +02:00
check_function_exists ( nice HAVE_NICE )
2024-08-05 13:24:35 +02:00
check_function_exists ( malloc_info HAVE_MALLOC_INFO )
2014-03-06 12:16:00 +01:00
check_library_exists ( dl dladdr "dlfcn.h" HAVE_DLADDR )
2014-04-14 03:02:33 +02:00
check_library_exists ( execinfo backtrace_symbols "" HAVE_LIBEXECINFO )
2014-09-02 13:02:22 +02:00
check_include_file_cxx ( cxxabi.h HAVE_CXXABI_H )
2014-04-14 03:02:33 +02:00
if ( HAVE_LIBEXECINFO )
set ( HAVE_BACKTRACE_SYMBOLS TRUE )
2020-10-27 15:31:39 +01:00
list ( APPEND base_DEPS execinfo )
2014-04-14 03:02:33 +02:00
endif ( )
2013-11-03 13:45:26 +01:00
2020-10-28 10:26:39 +01:00
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 )
endif ( )
2020-10-23 13:08:43 +02:00
if ( CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" )
set ( ICINGA2_STACKTRACE_USE_BACKTRACE_SYMBOLS TRUE )
endif ( )
if ( ICINGA2_STACKTRACE_USE_BACKTRACE_SYMBOLS AND NOT HAVE_BACKTRACE_SYMBOLS )
message ( FATAL_ERROR "ICINGA2_STACKTRACE_USE_BACKTRACE_SYMBOLS is set but backtrace_symbols() was not found" )
endif ( )
2016-08-25 05:14:13 +02:00
if ( CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
exec_program ( ${ CMAKE_CXX_COMPILER }
A R G S - d u m p v e r s i o n
O U T P U T _ V A R I A B L E _ I C I N G A 2 _ C O M P I L E R _ V E R S I O N
)
2015-11-30 08:16:39 +01:00
2022-07-21 10:54:46 +02:00
if ( "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "7.0.0" )
message ( FATAL_ERROR "Your version of GCC (${CMAKE_CXX_COMPILER_VERSION}) is too old for building Icinga 2 (GCC >= 7.0.0 is required)." )
2015-03-23 07:55:06 +01:00
endif ( )
endif ( )
2020-10-21 12:49:50 +02:00
if ( MSVC )
if ( "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "19.20" )
message ( FATAL_ERROR "Your version of MSVC (${CMAKE_CXX_COMPILER_VERSION}) is too old for building Icinga 2 (MSVC >= 19.20 from Visual Studio 2019 is required)." )
endif ( )
endif ( )
2016-01-11 14:28:58 +01:00
if ( NOT MSVC )
2016-08-25 05:14:13 +02:00
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 )
2015-03-23 07:55:06 +01:00
2016-01-11 14:28:58 +01:00
if ( NOT CXX_FEATURE_OVERRIDE )
add_definitions ( "-Doverride=" )
endif ( )
2015-03-23 07:55:06 +01:00
endif ( )
2019-07-08 13:48:15 +02:00
# Architecture specifics
# - Log the target architecture
# - ARM needs to link against atomic
if ( NOT MSVC )
# inspired by https://github.com/civetweb/civetweb/blob/master/cmake/DetermineTargetArchitecture.cmake
execute_process (
C O M M A N D $ { C M A K E _ C _ C O M P I L E R } - d u m p m a c h i n e
R E S U L T _ V A R I A B L E R E S U L T
O U T P U T _ V A R I A B L E A R C H
E R R O R _ Q U I E T
)
if ( RESULT )
2019-08-08 19:26:10 +02:00
message ( STATUS "Failed to detect target architecture with compiler ${CMAKE_C_COMPILER}: ${RESULT}" )
2019-07-08 13:48:15 +02:00
endif ( )
2019-08-08 19:26:10 +02:00
string ( REGEX MATCH "([^-]+).*" ARCH_MATCH "${ARCH}" )
2019-07-08 13:48:15 +02:00
if ( NOT CMAKE_MATCH_1 OR NOT ARCH_MATCH )
2019-08-08 19:26:10 +02:00
message ( STATUS "Failed to match the target architecture: ${ARCH}" )
2019-07-08 13:48:15 +02:00
endif ( )
set ( ARCH ${ CMAKE_MATCH_1 } )
message ( STATUS "Target architecture - ${ARCH}" )
# ARM settings
if ( "${ARCH}" STREQUAL "arm" )
check_cxx_source_compiles ( "include <atomic>; int main(){ std::atomic<uint_fast64_t> x; x.fetch_add(1); x.sub_add(1); }" CXX_ATOMIC )
2021-11-23 16:19:05 +01:00
link_libraries ( atomic )
2019-07-08 13:48:15 +02:00
endif ( )
else ( )
if ( "${MSVC_C_ARCHITECTURE_ID}" STREQUAL "X86" )
set ( ARCH "i686" )
elseif ( "${MSVC_C_ARCHITECTURE_ID}" STREQUAL "x64" )
set ( ARCH "x86_64" )
elseif ( "${MSVC_C_ARCHITECTURE_ID}" STREQUAL "ARM" )
set ( ARCH "arm" )
else ( )
message ( FATAL_ERROR "Failed to determine the MSVC target architecture: ${MSVC_C_ARCHITECTURE_ID}" )
endif ( )
message ( STATUS "Target architecture - ${ARCH}" )
endif ( )
2013-11-15 09:04:39 +01:00
configure_file ( config.h.cmake ${ CMAKE_CURRENT_BINARY_DIR } /config.h ESCAPE_QUOTES )
2013-11-03 13:45:26 +01:00
install (
2018-05-03 02:38:33 +02:00
F I L E S R E A D M E . m d C O P Y I N G A U T H O R S C H A N G E L O G . m d N E W S
2013-11-03 13:45:26 +01:00
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ D O C D I R }
)
include ( CTest )
enable_testing ( )
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
add_subdirectory ( third-party )
add_subdirectory ( tools )
add_subdirectory ( lib )
add_subdirectory ( icinga-app )
add_subdirectory ( etc )
add_subdirectory ( itl )
2014-09-17 11:25:34 +02:00
add_subdirectory ( agent )
2014-11-06 15:17:08 +01:00
add_subdirectory ( plugins )
2016-08-31 13:41:13 +02:00
add_subdirectory ( choco )
2014-04-20 11:22:15 +02:00
2023-02-23 12:31:28 +01:00
if ( NOT WIN32 )
add_subdirectory ( doc )
endif ( )
2016-03-30 18:59:23 +02:00
if ( MSVC )
add_subdirectory ( icinga-installer )
endif ( )
2015-11-25 15:24:04 +01:00
if ( ICINGA2_WITH_TESTS )
add_subdirectory ( test )
endif ( )
2016-03-30 11:47:39 +02:00
set ( CPACK_PACKAGE_NAME "Icinga 2" )
2019-02-25 16:30:40 +01:00
set ( CPACK_PACKAGE_VENDOR "Icinga GmbH" )
2019-04-04 12:55:52 +02:00
set ( CPACK_PACKAGE_VERSION ${ ICINGA2_VERSION_SAFE } )
2014-04-20 11:22:15 +02:00
set ( CPACK_PACKAGE_INSTALL_DIRECTORY "ICINGA2" )
set ( CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico" )
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" )
2018-02-02 07:22:50 +01:00
set ( CPACK_PACKAGE_EXECUTABLES "Icinga2SetupAgent;Icinga 2 Agent Wizard" )
2016-03-30 11:47:39 +02:00
set ( CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico" )
set ( CPACK_WIX_UPGRADE_GUID "52F2BEAA-4DF0-4C3E-ABDC-C0F61DE4DF8A" )
2016-04-14 08:38:57 +02:00
set ( CPACK_WIX_UI_BANNER "${CMAKE_CURRENT_SOURCE_DIR}/icinga-installer/bannrbmp.bmp" )
set ( CPACK_WIX_UI_DIALOG "${CMAKE_CURRENT_SOURCE_DIR}/icinga-installer/dlgbmp.bmp" )
2016-04-14 14:58:13 +02:00
set ( CPACK_WIX_PATCH_FILE "${CMAKE_CURRENT_BINARY_DIR}/icinga-installer/icinga2.wixpatch.Debug" )
set ( CPACK_WIX_PATCH_FILE "${CMAKE_CURRENT_BINARY_DIR}/icinga-installer/icinga2.wixpatch" )
2019-04-25 18:14:04 +02:00
set ( CPACK_WIX_EXTENSIONS "WixUtilExtension" "WixNetFxExtension" )
2024-04-04 17:53:42 +02:00
set ( CPACK_WIX_INSTALL_SCOPE NONE )
2014-04-20 11:22:15 +02:00
2017-12-13 22:31:56 +01:00
set ( CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION "sbin" )
set ( CMAKE_INSTALL_UCRT_LIBRARIES TRUE )
2014-04-20 11:22:15 +02:00
include ( InstallRequiredSystemLibraries )
if ( WIN32 )
2023-06-14 12:03:22 +02:00
if ( CMAKE_VS_PLATFORM_NAME STREQUAL "x64" )
set ( ICINGA2_OPENSSL_DLL_ARCH "-x64" )
2017-04-06 12:58:05 +02:00
else ( )
2023-06-14 12:03:22 +02:00
set ( ICINGA2_OPENSSL_DLL_ARCH "" )
2017-04-06 12:58:05 +02:00
endif ( )
2023-06-14 12:03:22 +02:00
foreach ( ICINGA2_OPENSSL_LIB crypto ssl )
list ( APPEND ICINGA2_OPENSSL_DLLS ${ OPENSSL_INCLUDE_DIR } /../bin/lib ${ ICINGA2_OPENSSL_LIB } -3 ${ ICINGA2_OPENSSL_DLL_ARCH } .dll )
endforeach ( )
2017-04-06 12:58:05 +02:00
install (
2017-12-13 22:31:56 +01:00
P R O G R A M S $ { I C I N G A 2 _ O P E N S S L _ D L L S }
2017-04-06 12:58:05 +02:00
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ S B I N D I R }
)
2014-04-20 11:22:15 +02:00
endif ( )
2021-01-15 17:41:49 +01:00
include ( CPack )