]> granicus.if.org Git - icinga2/blob - CMakeLists.txt
DB IDO: Add documentation for HA functionality
[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_USER "icinga" CACHE STRING "Icinga 2 command user")
39 set(ICINGA2_COMMAND_GROUP "icingacmd" CACHE STRING "Icinga 2 command group")
40 set(ICINGA2_RUNDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run" CACHE STRING "/run directory")
41 set(ICINGA2_PLUGINDIR "/usr/lib/nagios/plugins" CACHE STRING "Path for the check plugins")
42 set(ICINGA2_GIT_VERSION_INFO ON CACHE BOOL "Whether to use git describe")
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 include_directories(
84   ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR}/components
85   ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/lib ${CMAKE_CURRENT_BINARY_DIR}/components
86 )
87
88 #set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
89
90 if(APPLE)
91   set(CMAKE_INSTALL_NAME_DIR "@executable_path/../lib/icinga2")
92 endif(APPLE)
93
94 if("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
95   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments -g")
96   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -g")
97 endif()
98
99 if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
100   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
101   if(${CMAKE_SYSTEM_NAME} MATCHES AIX)
102     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -lpthread")
103   else()
104     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
105   endif()
106 endif()
107
108 if(MSVC)
109   add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS)
110 endif()
111
112 set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Library output path")
113 set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Bin/${CMAKE_BUILD_TYPE} CACHE PATH "Executable output path")
114
115 include(CheckFunctionExists)
116 include(CheckLibraryExists)
117 check_function_exists(vfork HAVE_VFORK)
118 check_function_exists(backtrace_symbols HAVE_BACKTRACE_SYMBOLS)
119 check_function_exists(pipe2 HAVE_PIPE2)
120 check_library_exists(dl dladdr "dlfcn.h" HAVE_DLADDR)
121 check_library_exists(execinfo backtrace_symbols "" HAVE_LIBEXECINFO)
122
123 if(HAVE_LIBEXECINFO)
124   set(HAVE_BACKTRACE_SYMBOLS TRUE)
125 endif()
126
127 configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h ESCAPE_QUOTES)
128
129 install(
130   FILES README.md COPYING COPYING.Exceptions AUTHORS ChangeLog NEWS
131   DESTINATION ${CMAKE_INSTALL_DOCDIR}
132 )
133
134 include(CTest)
135 enable_testing()
136
137 set_property(GLOBAL PROPERTY USE_FOLDERS ON)
138
139 add_subdirectory(third-party)
140 add_subdirectory(tools)
141 add_subdirectory(lib)
142 add_subdirectory(components)
143 add_subdirectory(icinga-app)
144 add_subdirectory(etc)
145 add_subdirectory(itl)
146 add_subdirectory(doc)
147 add_subdirectory(test)
148 add_subdirectory(pki)
149 add_subdirectory(contrib)
150
151 set(CPACK_PACKAGE_NAME "Icinga2")
152 set(CPACK_PACKAGE_VENDOR "Icinga Development Team")
153 set(CPACK_PACKAGE_VERSION ${ICINGA2_VERSION})
154 set(CPACK_NSIS_DISPLAY_NAME "Icinga 2")
155 set(CPACK_PACKAGE_INSTALL_DIRECTORY "ICINGA2")
156 set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
157 set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
158 set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/icinga-app\\\\icinga.ico")
159 set(CPACK_NSIS_INSTALLED_ICON_NAME "sbin\\\\icinga2.exe")
160 set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_BINARY_DIR}/LICENSE.txt")
161
162 set(CPACK_NSIS_EXECUTABLES_DIRECTORY "sbin")
163 set(CPACK_PACKAGE_EXECUTABLES "Icinga2SetupAgent;Icinga 2 Agent Wizard")
164 set(CPACK_NSIS_MUI_FINISHPAGE_RUN "Icinga2SetupAgent")
165 set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "nsExec::Exec '\\\"$INSTDIR\\\\sbin\\\\icinga2\\\" --scm-uninstall'")
166
167 set(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE)
168 include(InstallRequiredSystemLibraries)
169
170 if(WIN32)
171   install(
172     PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS}
173       C:\\\\openssl\\\\bin\\\\libeay32.dll C:\\\\openssl\\\\bin\\\\ssleay32.dll
174     DESTINATION ${CMAKE_INSTALL_SBINDIR}
175   )
176 endif()
177
178 include(CPack)