CMakeLists.txt 8.76 KB
Newer Older
1
##
2
## Copyright 2011-2012 Merethis
3
##
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## This file is part of Centreon Connector Perl.
##
## Centreon Connector Perl is free software: you can redistribute it
## and/or modify it under the terms of the GNU Affero General Public
## License as published by the Free Software Foundation, either version
## 3 of the License, or (at your option) any later version.
##
## Centreon Connector Perl is distributed in the hope that it will be
## useful, but WITHOUT ANY WARRANTY; without even the implied warranty
## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Affero General Public License for more details.
##
## You should have received a copy of the GNU Affero General Public
## License along with Centreon Connector Perl. If not, see
## <http://www.gnu.org/licenses/>.
##

# Global options.
cmake_minimum_required(VERSION 2.8)
project("Centreon Connector Perl" C CXX)
set(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
25
set(INC_DIR "${PROJECT_SOURCE_DIR}/inc/com/centreon/connector/perl")
26
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
27
set(TEST_DIR "${PROJECT_SOURCE_DIR}/test")
28
include_directories("${PROJECT_SOURCE_DIR}/inc")
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Project version.
set(CONNECTOR_PERL_MAJOR 0)
set(CONNECTOR_PERL_MINOR 1)
set(CONNECTOR_PERL_PATCH 0)
set(CONNECTOR_PERL_VERSION "${CONNECTOR_PERL_MAJOR}.${CONNECTOR_PERL_MINOR}.${CONNECTOR_PERL_PATCH}")
add_definitions(-DCENTREON_CONNECTOR_PERL_VERSION=\"${CONNECTOR_PERL_VERSION}\")

# We will use pkg-config if available.
include(FindPkgConfig)
if (PKG_CONFIG_FOUND)
  pkg_check_modules(CLIB QUIET "centreon-clib") # Will be used below.
endif ()

# Find Centreon Clib's headers.
if (WITH_CENTREON_CLIB_INCLUDE_DIR)
  find_file(
    CLIB_HEADER_FOUND
    "com/centreon/clib/version.hh"
    PATHS "${WITH_CENTREON_CLIB_INCLUDE_DIR}"
    NO_DEFAULT_PATH)
  if (NOT CLIB_HEADER_FOUND)
    message(FATAL_ERROR "Could not find Centreon Clib's headers in ${WITH_CENTREON_CLIB_INCLUDE_DIR}.")
  endif ()
  include_directories("${WITH_CENTREON_CLIB_INCLUDE_DIR}")
elseif (CLIB_FOUND) # Was Centreon Clib detected with pkg-config ?
  if (CMAKE_CXX_FLAGS)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLIB_CFLAGS}")
  else ()
    set(CMAKE_CXX_FLAGS "${CLIB_CFLAGS}")
  endif ()
else ()
  find_path(CLIB_INCLUDE_DIR "com/centreon/clib/version.hh")
  if (NOT CLIB_INCLUDE_DIR)
    message(FATAL_ERROR "Could not find Centreon Clib's headers (try WITH_CENTREON_CLIB_INCLUDE_DIR).")
  endif ()
  include_directories("${CLIB_INCLUDE_DIR}")
endif ()

# Find Centreon Clib's library.
if (WITH_CENTREON_CLIB_LIBRARIES)
  set(CLIB_LIBRARIES "${WITH_CENTREON_CLIB_LIBRARIES}")
elseif (WITH_CENTREON_CLIB_LIBRARY_DIR)
  find_library(
    CLIB_LIBRARIES
    "centreon_clib"
    PATHS "${WITH_CENTREON_CLIB_LIBRARY_DIR}"
    NO_DEFAULT_PATH)
  if (NOT CLIB_LIBRARIES)
    message(FATAL_ERROR "Could not find Centreon Clib's library in ${WITH_CENTREON_CLIB_LIBRARY_DIR}.")
  endif ()
elseif (CLIB_FOUND) # Was Centreon Clib detected with pkg-config ?
  set(CLIB_LIBRARIES "${CLIB_LDFLAGS}")
else ()
  find_library(CLIB_LIBRARIES "centreon_clib")
  if (NOT CLIB_LIBRARIES)
    message(FATAL_ERROR "Could not find Centreon Clib's library (try WITH_CENTREON_CLIB_LIBRARY_DIR or WITH_CENTREON_CLIB_LIBRARIES).")
  endif ()
endif ()

89
90
91
92
93
94
95
# Find Perl.
include(FindPerlLibs)
if (NOT PERLLIBS_FOUND)
  message(FATAL_ERROR "Could not find Perl libraries.")
endif ()
include_directories("${PERL_INCLUDE_PATH}")

96
97
98
99
100
101
102
103
104
105
106
# Disable some warnings generated by Embedded Perl.
get_property(EMBEDDED_PERL_CXXFLAGS
  SOURCE "${SRC_DIR}/embedded_perl.cc"
  PROPERTY COMPILE_FLAGS)
if (EMBEDDED_PERL_CXXFLAGS)
  string(REGEX REPLACE "-pedantic *"
    EMBEDDED_PERL_CXXFLAGS "${EMBEDDED_PERL_CXXFLAGS}")
  set_property(SOURCE "${SRC_DIR}/embedded_perl.cc"
    PROPERTY COMPILE_FLAGS "${EMBEDDED_PERL_CXXFLAGS}")
endif ()

107
108
# Perl connector library.
set(CONNECTORLIB "centreonconnectorperl")
109
add_library("${CONNECTORLIB}" STATIC
110
  # Sources.
111
  "${SRC_DIR}/checks/check.cc"
112
  "${SRC_DIR}/checks/listener.cc"
113
  "${SRC_DIR}/checks/result.cc"
114
  "${SRC_DIR}/checks/timeout.cc"
115
  "${SRC_DIR}/embedded_perl.cc"
116
  "${SRC_DIR}/multiplexer.cc"
117
  "${SRC_DIR}/options.cc"
118
119
  "${SRC_DIR}/orders/listener.cc"
  "${SRC_DIR}/orders/parser.cc"
120
  "${SRC_DIR}/pipe_handle.cc"
121
  "${SRC_DIR}/policy.cc"
122
  "${SRC_DIR}/reporter.cc"
123
  "${SRC_DIR}/script.cc"
124
  # Headers.
125
  "${INC_DIR}/checks/check.hh"
126
  "${INC_DIR}/checks/listener.hh"
127
  "${INC_DIR}/checks/result.hh"
128
  "${INC_DIR}/checks/timeout.hh"
129
  "${INC_DIR}/embedded_perl.hh"
130
  "${INC_DIR}/multiplexer.hh"
131
  "${INC_DIR}/namespace.hh"
132
  "${INC_DIR}/options.hh"
133
134
  "${INC_DIR}/orders/listener.hh"
  "${INC_DIR}/orders/parser.hh"
135
  "${INC_DIR}/pipe_handle.hh"
136
  "${INC_DIR}/policy.hh"
137
  "${INC_DIR}/reporter.hh"
138
139
140
141
142
)
target_link_libraries(
  "${CONNECTORLIB}"
  ${PERL_LIBRARY}
  ${CLIB_LIBRARIES})
143
144
145
146
147

# Perl connector.
set(CONNECTOR "centreon_connector_perl")
add_executable("${CONNECTOR}"
  # Sources.
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
  "${SRC_DIR}/main.cc")
target_link_libraries("${CONNECTOR}" ${CONNECTORLIB})

# Installation path.
if (WITH_PREFIX)
  set(CMAKE_INSTALL_PREFIX "${WITH_PREFIX}")
endif ()
if (WITH_PREFIX_BINARY)
  set(PREFIX_BINARY "${WITH_PREFIX_BINARY}")
else ()
  set(PREFIX_BINARY "bin")
endif ()

# Install rules.
install(TARGETS "${CONNECTOR}"
  RUNTIME DESTINATION "${PREFIX_BINARY}")

# Packaging.
include("package.cmake")
167
168
169
170
171
172

# Testing.
option(WITH_TESTING "Build unit tests." OFF)
if (WITH_TESTING)
  # Enable testing.
  enable_testing()
173
  set(BUILD_UNIT_TEST "Yes")
174
  include_directories("${PROJECT_SOURCE_DIR}")
175
  set(CONNECTOR_TEST_DIR "${PROJECT_SOURCE_DIR}/test/connector")
176
177
178
179
  get_property(CONNECTOR_PERL_BINARY
    TARGET "${CONNECTOR}"
    PROPERTY LOCATION)
  configure_file(
180
181
    "${TEST_DIR}/connector/paths.hh.in"
    "${TEST_DIR}/connector/paths.hh")
182

183

184
  # Embedded Perl tests.
185
186
  #   Simple script execution #1.
  set(TEST_NAME "embedded_perl_run_simple_1")
187
  add_executable("${TEST_NAME}"
188
189
190
191
192
193
194
    "${TEST_DIR}/embedded_perl/run_simple_1.cc")
  target_link_libraries("${TEST_NAME}" ${CONNECTORLIB})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Simple script execution #2.
  set(TEST_NAME "embedded_perl_run_simple_2")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/embedded_perl/run_simple_2.cc")
195
196
197
  target_link_libraries("${TEST_NAME}" ${CONNECTORLIB})
  add_test("${TEST_NAME}" "${TEST_NAME}")

198
199
200
201
202
203
204
205
206
207
208
209

  #
  # Process tests.
  #
  # Help.
  add_test("connector_help" "${CONNECTOR}" "--help")
  # Version.
  add_test("connector_version" "${CONNECTOR}" "--version")
  # Invalid flag.
  add_test("connector_invalid_flag" "${CONNECTOR}" "--merethis")
  set_tests_properties("connector_invalid_flag"
    PROPERTIES WILL_FAIL TRUE)
210
211
212
213
214
215
216
217
218
219
220
221
  # EOF on stdin.
  set(TEST_NAME "connector_eof_on_stdin")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/eof_on_stdin.cc")
  target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  # Non-existent script.
  set(TEST_NAME "connector_non_existent_script")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/non_existent_script.cc")
  target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
222
223
224
225
226
227
228
229
230
231
232
233
  # Graceful timeout.
  set(TEST_NAME "connector_timeout_term")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/timeout_term.cc")
  target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  # Forced timeout.
  set(TEST_NAME "connector_timeout_kill")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/timeout_kill.cc")
  target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250

else()
  set(BUILD_UNIT_TEST "No")
endif ()

# Summary.
message(STATUS "")
message(STATUS "Configuration Summary")
message(STATUS "---------------------")
message(STATUS "")
message(STATUS "  Project")
message(STATUS "    - Name                       Centreon Connector Perl")
message(STATUS "    - Version                    ${CONNECTOR_PERL_VERSION}")
if (WITH_KNOWN_HOSTS_CHECK)
  message(STATUS "    - Known hosts check          enabled")
else ()
  message(STATUS "    - Known hosts check          disabled")
251
endif ()
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
message(STATUS "")
message(STATUS "  System")
message(STATUS "    - Name                       ${CMAKE_SYSTEM_NAME}")
message(STATUS "    - Version                    ${CMAKE_SYSTEM_VERSION}")
message(STATUS "    - Processor                  ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "")
message(STATUS "  Build")
message(STATUS "    - Compiler                   ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID})")
message(STATUS "    - Extra compilation flags    ${CMAKE_CXX_FLAGS}")
message(STATUS "    - Build unit tests           ${BUILD_UNIT_TEST}")
message(STATUS "")
message(STATUS "  Install")
message(STATUS "    - Prefix                     ${CMAKE_INSTALL_PREFIX}")
message(STATUS "    - Binary prefix              ${PREFIX_BINARY}")
message(STATUS "    - Package                    ${PACKAGE_LIST}")
message(STATUS "")