]> granicus.if.org Git - icinga2/blob - CMakeLists.txt
Fix null ptr exception in Zone::GetLocalZone()
[icinga2] / CMakeLists.txt
1 # Icinga 2
2 # Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation
16 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 cmake_minimum_required(VERSION 2.6)
19 set(BOOST_MIN_VERSION "1.41.0")
20
21 project(icinga2)
22 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
23
24 if(NOT CMAKE_BUILD_TYPE)
25   set(CMAKE_BUILD_TYPE Release CACHE STRING
26       "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
27       FORCE)
28 endif()
29
30 file(STRINGS icinga2.spec VERSION_LINE REGEX "^Version: ")
31 string(REPLACE "Version: " "" ICINGA2_VERSION ${VERSION_LINE})
32
33 set(ICINGA2_USER "icinga" CACHE STRING "Icinga 2 user")
34 set(ICINGA2_GROUP "icinga" CACHE STRING "Icinga 2 group")
35 set(ICINGA2_COMMAND_USER "icinga" CACHE STRING "Icinga 2 command user")
36 set(ICINGA2_COMMAND_GROUP "icingacmd" CACHE STRING "Icinga 2 command group")
37 set(ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe")
38
39 file(READ "${CMAKE_CURRENT_SOURCE_DIR}/COPYING" ICINGA2_LICENSE_GPL)
40 file(READ "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.Exceptions" ICINGA2_LICENSE_ADDITIONS)
41 set(ICINGA2_LICENSE "${ICINGA2_LICENSE_GPL}\n\n---\n\n${ICINGA2_LICENSE_ADDITIONS}")
42 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" ${ICINGA2_LICENSE})
43
44 include(GetGitRevisionDescription)
45 git_describe(GIT_VERSION --tags)
46 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/icinga-version.h.force)
47   configure_file(icinga-version.h.force ${CMAKE_CURRENT_BINARY_DIR}/icinga-version.h COPYONLY)
48 else()
49   if(NOT ICINGA2_GIT_VERSION_INFO OR GIT_VERSION MATCHES "-NOTFOUND$")
50     file(STRINGS icinga2.spec SPEC_VERSION REGEX "^Version:")
51     string(LENGTH "${SPEC_VERSION}" SPEC_VERSION_LENGTH)
52     math(EXPR SPEC_VERSION_LENGTH "${SPEC_VERSION_LENGTH} - 9")
53     string(SUBSTRING ${SPEC_VERSION} 9 ${SPEC_VERSION_LENGTH} SPEC_VERSION)
54
55     file(STRINGS icinga2.spec SPEC_REVISION REGEX "^%define revision ")
56     string(LENGTH "${SPEC_REVISION}" SPEC_REVISION_LENGTH)
57     math(EXPR SPEC_REVISION_LENGTH "${SPEC_REVISION_LENGTH} - 17")
58     string(SUBSTRING ${SPEC_REVISION} 17 ${SPEC_REVISION_LENGTH} SPEC_REVISION)
59
60     set(GIT_VERSION "r${SPEC_VERSION}-${SPEC_REVISION}")
61   endif()
62   configure_file(icinga-version.h.cmake icinga-version.h)
63 endif()
64
65 if(WIN32)
66   set(Boost_USE_STATIC_LIBS ON)
67   add_definitions(-DBOOST_ALL_NO_LIB)
68 endif()
69
70 find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS thread system program_options regex REQUIRED)
71
72 link_directories(${Boost_LIBRARY_DIRS})
73 include_directories(${Boost_INCLUDE_DIRS})
74
75 find_package(OpenSSL REQUIRED)
76 include_directories(${OPENSSL_INCLUDE_DIR})
77
78 include_directories(
79   ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR}/components
80   ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/lib ${CMAKE_CURRENT_BINARY_DIR}/components
81 )
82
83 #set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
84
85 if(APPLE)
86   set(CMAKE_INSTALL_NAME_DIR "@executable_path/../lib/icinga2")
87 endif(APPLE)
88
89 if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
90   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -g")
91   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -g")
92 endif()
93
94 if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
95   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
96   if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
97     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -lpthread")
98   else()
99     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
100   endif()
101 endif()
102
103 if(MSVC)
104   add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
105 endif()
106
107 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Library output path")
108 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Executable output path")
109
110 include(CheckFunctionExists)
111 include(CheckLibraryExists)
112 check_function_exists(vfork HAVE_VFORK)
113 check_function_exists(backtrace_symbols HAVE_BACKTRACE_SYMBOLS)
114 check_function_exists(pipe2 HAVE_PIPE2)
115 check_library_exists(dl dladdr "dlfcn.h" HAVE_DLADDR)
116 check_library_exists(execinfo backtrace_symbols "" HAVE_LIBEXECINFO)
117
118 if(HAVE_LIBEXECINFO)
119   set(HAVE_BACKTRACE_SYMBOLS TRUE)
120 endif()
121
122 include(GNUInstallDirs)
123 configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES)
124
125 install(
126   FILES README COPYING COPYING.Exceptions AUTHORS ChangeLog INSTALL NEWS
127   DESTINATION ${CMAKE_INSTALL_DOCDIR}
128 )
129
130 include(CTest)
131 enable_testing()
132
133 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
134
135 add_subdirectory(third-party)
136 add_subdirectory(tools)
137 add_subdirectory(lib)
138 add_subdirectory(components)
139 add_subdirectory(icinga-app)
140 add_subdirectory(etc)
141 add_subdirectory(itl)
142 add_subdirectory(doc)
143 add_subdirectory(test)
144 add_subdirectory(pki)
145
146 set(CPACK_PACKAGE_NAME "Icinga2")
147 set(CPACK_PACKAGE_VENDOR "Icinga Development Team")
148 set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION})
149 set(CPACK_NSIS_DISPLAY_NAME "Icinga 2")
150 set(CPACK_PACKAGE_INSTALL_DIRECTORY "ICINGA2")
151 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
152 set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
153 set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
154 set(CPACK_NSIS_INSTALLED_ICON_NAME "sbin\\\\icinga2.exe")
155 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
156
157 set(CPACK_NSIS_EXECUTABLES_DIRECTORY "sbin")
158 set(CPACK_PACKAGE_EXECUTABLES "Icinga2SetupAgent;Icinga 2 Agent Wizard")
159 set(CPACK_NSIS_MUI_FINISHPAGE_RUN "Icinga2SetupAgent")
160 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "nsExec::Exec '\\\"$INSTDIR\\\\sbin\\\\icinga2\\\" --scm-uninstall'")
161
162 set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
163 include(InstallRequiredSystemLibraries)
164
165 if(WIN32)
166   install(
167     PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
168       C:\\\\openssl\\\\bin\\\\libeay32.dll C:\\\\openssl\\\\bin\\\\ssleay32.dll
169     DESTINATION ${CMAKE_INSTALL_SBINDIR}
170   )
171 endif()
172
173 include(CPack)