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