X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=CMakeLists.txt;h=735e553f7bb5802d4a501d6f17d19eae48f33e78;hb=f9812ee1aa79d9d6c413326aa1630010d8c074b9;hp=3556d3a9672c58bf2462ceecb1cca9bd707e9827;hpb=37b715baf12f397498bb50cc7cccd0ee6929bd1e;p=icinga2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3556d3a96..735e553f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ cmake_minimum_required(VERSION 2.8.8) -set(BOOST_MIN_VERSION "1.53.0") +set(BOOST_MIN_VERSION "1.66.0") project(icinga2) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") @@ -27,9 +27,6 @@ option (USE_SYSTEMD set(HAVE_SYSTEMD ${USE_SYSTEMD}) -file(STRINGS VERSION VERSION_LINE REGEX "^Version: ") -string(REPLACE "Version: " "" ICINGA2_VERSION ${VERSION_LINE}) - include(GNUInstallDirs) include(InstallConfig) include(SetFullDir) @@ -104,15 +101,38 @@ else() string(SUBSTRING ${SPEC_REVISION} 10 ${SPEC_REVISION_LENGTH} SPEC_REVISION) set(GIT_VERSION "r${SPEC_VERSION}-${SPEC_REVISION}") + set(ICINGA2_VERSION "${SPEC_VERSION}") + else() + # use GIT version as ICINGA2_VERSION + string(REGEX REPLACE "^[rv]" "" ICINGA2_VERSION "${GIT_VERSION}") endif() configure_file(icinga-version.h.cmake icinga-version.h) endif() +# 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}") +string(REGEX REPLACE "-[^\\.]*(.*)$" "\\1" ICINGA2_VERSION_SAFE "${ICINGA2_VERSION_SAFE}") +message(STATUS "ICINGA2_VERSION_SAFE=${ICINGA2_VERSION_SAFE}") + if(WIN32) set(Boost_USE_STATIC_LIBS ON) - add_definitions(-DBOOST_ALL_NO_LIB) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /bigobj") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") + # Disabled for linking issues for newer Boost versions, they link against Windows SDKs + #add_definitions(-DBOOST_ALL_NO_LIB) + + # 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") + + # 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() endif() if(NOT DEFINED LOGROTATE_HAS_SU) @@ -130,9 +150,18 @@ if(NOT DEFINED LOGROTATE_HAS_SU) endif() if(LOGROTATE_HAS_SU) set(LOGROTATE_USE_SU "\n\tsu ${ICINGA2_USER} ${ICINGA2_GROUP}") +else() + set(LOGROTATE_CREATE "\n\tcreate 644 ${ICINGA2_USER} ${ICINGA2_GROUP}") endif() -find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS thread system program_options regex REQUIRED) +find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS context coroutine date_time filesystem thread system program_options regex REQUIRED) + +# 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_definitions(-DBOOST_FILESYSTEM_NO_DEPRECATED) link_directories(${Boost_LIBRARY_DIRS}) include_directories(${Boost_INCLUDE_DIRS}) @@ -143,15 +172,13 @@ include_directories(${OPENSSL_INCLUDE_DIR}) set(base_DEPS ${CMAKE_DL_LIBS} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES}) set(base_OBJS $ $ $) -find_package(YAJL) +# JSON +find_package(JSON) +include_directories(${JSON_INCLUDE}) -if(NOT YAJL_FOUND) - include_directories(${icinga2_BINARY_DIR}/third-party/yajl/include) - link_directories(${icinga2_BINARY_DIR}/third-party/yajl) - list(APPEND base_OBJS $) -else() - list(APPEND base_DEPS ${YAJL_LIBRARIES}) -endif() +# UTF8CPP +find_package(UTF8CPP) +include_directories(${UTF8CPP_INCLUDE}) find_package(Editline) set(HAVE_EDITLINE "${EDITLINE_FOUND}") @@ -192,6 +219,7 @@ if(WIN32) endif() set(CMAKE_MACOSX_RPATH 1) +set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH};${CMAKE_INSTALL_FULL_LIBDIR}/icinga2") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -fcolor-diagnostics") @@ -349,6 +377,54 @@ if(NOT MSVC) endif() endif() +# 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( + COMMAND ${CMAKE_C_COMPILER} -dumpmachine + RESULT_VARIABLE RESULT + OUTPUT_VARIABLE ARCH + ERROR_QUIET + ) + + if (RESULT) + message(FATAL_ERROR "Failed to detect target architecture: ${RESULT}") + endif() + + string(REGEX MATCH "([^-]+).*" ARCH_MATCH ${ARCH}) + if (NOT CMAKE_MATCH_1 OR NOT ARCH_MATCH) + message(FATAL_ERROR "Failed to match the target architecture: ${ARCH}") + endif() + + set(ARCH ${CMAKE_MATCH_1}) + + message(STATUS "Target architecture - ${ARCH}") + + # ARM settings + if("${ARCH}" STREQUAL "arm") + check_cxx_source_compiles( "include ; int main(){ std::atomic x; x.fetch_add(1); x.sub_add(1); }" CXX_ATOMIC) + + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -latomic") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -latomic") + set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} -latomic") + 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() + configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES) install( @@ -382,7 +458,7 @@ endif() set(CPACK_PACKAGE_NAME "Icinga 2") set(CPACK_PACKAGE_VENDOR "Icinga GmbH") -set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION}) +set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION_SAFE}) 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") @@ -390,11 +466,11 @@ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt") set(CPACK_PACKAGE_EXECUTABLES "Icinga2SetupAgent;Icinga 2 Agent Wizard") set(CPACK_WIX_PRODUCT_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico") set(CPACK_WIX_UPGRADE_GUID "52F2BEAA-4DF0-4C3E-ABDC-C0F61DE4DF8A") -set(CPACK_WIX_EXTENSIONS "WixUtilExtension") 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") 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") +set(CPACK_WIX_EXTENSIONS "WixUtilExtension" "WixNetFxExtension") set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION "sbin") set(CMAKE_INSTALL_UCRT_LIBRARIES TRUE) @@ -402,11 +478,11 @@ include(InstallRequiredSystemLibraries) if(WIN32) if(CMAKE_VS_PLATFORM_NAME STREQUAL "x64") - set(NSCP_URL "https://github.com/mickem/nscp/releases/download/0.5.0.62/NSCP-0.5.0.62-x64.msi") - set(NSCP_SHA256 "1854de86ad4fda3391f273de0f9985b702c014bdec01b26ad28a1343177f537f") + set(NSCP_URL "https://github.com/mickem/nscp/releases/download/0.5.2.39/NSCP-0.5.2.39-x64.msi") + set(NSCP_SHA256 "dfe93c293f30586b02510d8b7884e4e177b93a5fead8b5dc6de8103532e6e159") else() - set(NSCP_URL "https://github.com/mickem/nscp/releases/download/0.5.0.62/NSCP-0.5.0.62-Win32.msi") - set(NSCP_SHA256 "2186b60d588fa0811344ce709332f9c63670019c62ae92eae49698bf76205a95") + set(NSCP_URL "https://github.com/mickem/nscp/releases/download/0.5.2.39/NSCP-0.5.2.39-Win32.msi") + set(NSCP_SHA256 "ca6a67fb01c1468f2b510fd2f9eb0750887db3fb49a0302732c1421c85c6627c") endif() set(NSCP_SHA256SUM "")