]> granicus.if.org Git - icinga2/blob - CMakeLists.txt
Fix incorrect operators in GelfWriter::NotificationToUserHandler
[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 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/third-party/cmake")
24
25 if(NOT CMAKE_BUILD_TYPE)
26   set(CMAKE_BUILD_TYPE Release CACHE STRING
27       "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
28       FORCE)
29 endif()
30
31 option(ICINGA2_WITH_MYSQL "MySQL support" ON)
32 option(ICINGA2_WITH_PGSQL "PostgreSQL support" ON)
33
34 file(STRINGS icinga2.spec VERSION_LINE REGEX "^Version: ")
35 string(REPLACE "Version: " "" ICINGA2_VERSION ${VERSION_LINE})
36
37 include(GNUInstallDirs)
38
39 set(ICINGA2_USER "icinga" CACHE STRING "Icinga 2 user")
40 set(ICINGA2_GROUP "icinga" CACHE STRING "Icinga 2 group")
41 set(ICINGA2_COMMAND_GROUP "icingacmd" CACHE STRING "Icinga 2 command group")
42 set(ICINGA2_RUNDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run" CACHE STRING "/run directory")
43 set(ICINGA2_PLUGINDIR "/usr/lib/nagios/plugins" CACHE STRING "Path for the check plugins")
44 set(ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe")
45 set(ICINGA2_UNITY_BUILD OFF CACHE BOOL "Whether to perform a unity build")
46
47 file(READ "${CMAKE_CURRENT_SOURCE_DIR}/COPYING" ICINGA2_LICENSE_GPL)
48 file(READ "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.Exceptions" ICINGA2_LICENSE_ADDITIONS)
49 set(ICINGA2_LICENSE "${ICINGA2_LICENSE_GPL}\n\n---\n\n${ICINGA2_LICENSE_ADDITIONS}")
50 file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt" ${ICINGA2_LICENSE})
51
52 include(GetGitRevisionDescription)
53 git_describe(GIT_VERSION --tags)
54 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/icinga-version.h.force)
55   configure_file(icinga-version.h.force ${CMAKE_CURRENT_BINARY_DIR}/icinga-version.h COPYONLY)
56 else()
57   if(NOT ICINGA2_GIT_VERSION_INFO OR GIT_VERSION MATCHES "-NOTFOUND$")
58     file(STRINGS icinga2.spec SPEC_VERSION REGEX "^Version:")
59     string(LENGTH "${SPEC_VERSION}" SPEC_VERSION_LENGTH)
60     math(EXPR SPEC_VERSION_LENGTH "${SPEC_VERSION_LENGTH} - 9")
61     string(SUBSTRING ${SPEC_VERSION} 9 ${SPEC_VERSION_LENGTH} SPEC_VERSION)
62
63     file(STRINGS icinga2.spec SPEC_REVISION REGEX "^%define revision ")
64     string(LENGTH "${SPEC_REVISION}" SPEC_REVISION_LENGTH)
65     math(EXPR SPEC_REVISION_LENGTH "${SPEC_REVISION_LENGTH} - 17")
66     string(SUBSTRING ${SPEC_REVISION} 17 ${SPEC_REVISION_LENGTH} SPEC_REVISION)
67
68     set(GIT_VERSION "r${SPEC_VERSION}-${SPEC_REVISION}")
69   endif()
70   configure_file(icinga-version.h.cmake icinga-version.h)
71 endif()
72
73 if(WIN32)
74   set(Boost_USE_STATIC_LIBS ON)
75   add_definitions(-DBOOST_ALL_NO_LIB)
76 endif()
77
78 find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS thread system program_options regex REQUIRED)
79
80 link_directories(${Boost_LIBRARY_DIRS})
81 include_directories(${Boost_INCLUDE_DIRS})
82
83 find_package(OpenSSL REQUIRED)
84 include_directories(${OPENSSL_INCLUDE_DIR})
85
86 find_package(YAJL)
87
88 if(NOT YAJL_FOUND)
89   include_directories(${icinga2_BINARY_DIR}/third-party/yajl/include)
90   link_directories(${icinga2_BINARY_DIR}/third-party/yajl)
91   set(YAJL_LIBRARIES "yajl")
92 endif()
93
94 include_directories(
95   ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib
96   ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/lib
97 )
98
99 #set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
100
101 if(APPLE)
102   set(CMAKE_INSTALL_NAME_DIR "@executable_path/../lib/icinga2")
103   set(CMAKE_MACOSX_RPATH 0)
104 endif(APPLE)
105
106 if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
107   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -g")
108   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -g")
109 endif()
110
111 if("${CMAKE_C_COMPILER_ID}" STREQUAL "SunPro")
112     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mt")
113     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mt -library=stlport4")
114 endif()
115
116 if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
117   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
118   if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
119     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -lpthread")
120   else()
121     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
122   endif()
123 endif()
124
125 if(MSVC)
126   add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
127 endif()
128
129 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Library output path")
130 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Executable output path")
131
132 include(CheckSymbolExists)
133 include(CheckFunctionExists)
134 include(CheckLibraryExists)
135 include(CheckIncludeFileCXX)
136
137 check_symbol_exists(__COUNTER__ "" HAVE_COUNTER_MACRO)
138
139 if(NOT HAVE_COUNTER_MACRO AND ICINGA2_UNITY_BUILD)
140   message(STATUS "Your C/C++ compiler does not support the __COUNTER__ macro. Disabling unity build.")
141   set(ICINGA2_UNITY_BUILD FALSE)
142 endif()
143
144 if(NOT MSVC)
145   set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
146   set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
147 endif()
148
149 check_function_exists(vfork HAVE_VFORK)
150 check_function_exists(backtrace_symbols HAVE_BACKTRACE_SYMBOLS)
151 check_function_exists(pipe2 HAVE_PIPE2)
152 check_function_exists(nice HAVE_NICE)
153 check_library_exists(dl dladdr "dlfcn.h" HAVE_DLADDR)
154 check_library_exists(execinfo backtrace_symbols "" HAVE_LIBEXECINFO)
155 check_include_file_cxx(cxxabi.h HAVE_CXXABI_H)
156
157 if(HAVE_LIBEXECINFO)
158   set(HAVE_BACKTRACE_SYMBOLS TRUE)
159 endif()
160
161 configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES)
162
163 install(
164   FILES README.md COPYING COPYING.Exceptions AUTHORS ChangeLog NEWS
165   DESTINATION ${CMAKE_INSTALL_DOCDIR}
166 )
167
168 include(CTest)
169 enable_testing()
170
171 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
172
173 add_subdirectory(third-party)
174 add_subdirectory(tools)
175 add_subdirectory(lib)
176 add_subdirectory(icinga-app)
177 add_subdirectory(etc)
178 add_subdirectory(itl)
179 add_subdirectory(doc)
180 add_subdirectory(test)
181 add_subdirectory(agent)
182 add_subdirectory(plugins)
183
184 set(CPACK_PACKAGE_NAME "Icinga2")
185 set(CPACK_PACKAGE_VENDOR "Icinga Development Team")
186 set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION})
187 set(CPACK_NSIS_DISPLAY_NAME "Icinga 2")
188 set(CPACK_PACKAGE_INSTALL_DIRECTORY "ICINGA2")
189 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
190 set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
191 set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
192 set(CPACK_NSIS_INSTALLED_ICON_NAME "sbin\\\\icinga2.exe")
193 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
194
195 set(CPACK_NSIS_EXECUTABLES_DIRECTORY "sbin")
196 set(CPACK_PACKAGE_EXECUTABLES "Icinga2SetupAgent;Icinga 2 Agent Wizard")
197 set(CPACK_NSIS_MUI_FINISHPAGE_RUN "Icinga2SetupAgent")
198 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "nsExec::Exec '\\\"$INSTDIR\\\\sbin\\\\icinga2\\\" --scm-uninstall'")
199
200 set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
201 include(InstallRequiredSystemLibraries)
202
203 if(WIN32)
204   install(
205     PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
206       C:\\\\openssl\\\\bin\\\\libeay32.dll C:\\\\openssl\\\\bin\\\\ssleay32.dll
207     DESTINATION ${CMAKE_INSTALL_SBINDIR}
208   )
209 endif()
210
211 include(CPack)