CMakeLists.txt 10.4 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
# 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}")
54
  set(CLIB_INCLUDE_DIR "${WITH_CENTREON_CLIB_INCLUDE_DIR}")
55
56
57
58
59
60
61
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 ()
Dorian Guillois's avatar
Dorian Guillois committed
62
  find_path(CLIB_INCLUDE_DIR "com/centreon/clib/version.hh" PATH_SUFFIXES "centreon-clib")
63
  if (NOT CLIB_INCLUDE_DIR)
Dorian Guillois's avatar
Dorian Guillois committed
64
    message(FATAL_ERROR "Could not find Centreon Clib's headers (try WITH_CENTREON_CLIB_INCLUDE_DIR).")
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  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 ()

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
execute_process(COMMAND "${PERL_EXECUTABLE}" "-MExtUtils::Embed" "-e" "ldopts"
  RESULT_VARIABLE PERL_LDFLAGS_ERROR
98
99
  OUTPUT_VARIABLE PERL_LIBRARIES)
string(STRIP "${PERL_LIBRARIES}" PERL_LIBRARIES)
100
101
102
if (PERL_LDFLAGS_ERROR)
  set(PERL_LIBRARIES ${PERL_LIBRARY})
endif ()
103

104
105
106
107
# Generate code to dynamically load modules.
add_custom_command(OUTPUT "${SRC_DIR}/xs_init.cc"
  COMMAND "${PERL_EXECUTABLE}" "-MExtUtils::Embed" "-e" "xsinit" "--" "-o" "${SRC_DIR}/xs_init.cc")

108
109
110
111
112
113
114
115
116
117
118
# 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 ()

119
120
# Perl connector library.
set(CONNECTORLIB "centreonconnectorperl")
121
add_library("${CONNECTORLIB}" STATIC
122
  # Sources.
123
  "${SRC_DIR}/checks/check.cc"
124
  "${SRC_DIR}/checks/listener.cc"
125
  "${SRC_DIR}/checks/result.cc"
126
  "${SRC_DIR}/checks/timeout.cc"
127
  "${SRC_DIR}/embedded_perl.cc"
128
  "${SRC_DIR}/multiplexer.cc"
129
  "${SRC_DIR}/options.cc"
130
131
  "${SRC_DIR}/orders/listener.cc"
  "${SRC_DIR}/orders/parser.cc"
132
  "${SRC_DIR}/pipe_handle.cc"
133
  "${SRC_DIR}/policy.cc"
134
  "${SRC_DIR}/reporter.cc"
135
  "${SRC_DIR}/script.cc"
136
  "${SRC_DIR}/xs_init.cc"
137
  # Headers.
138
  "${INC_DIR}/checks/check.hh"
139
  "${INC_DIR}/checks/listener.hh"
140
  "${INC_DIR}/checks/result.hh"
141
  "${INC_DIR}/checks/timeout.hh"
142
  "${INC_DIR}/embedded_perl.hh"
143
  "${INC_DIR}/multiplexer.hh"
144
  "${INC_DIR}/namespace.hh"
145
  "${INC_DIR}/options.hh"
146
147
  "${INC_DIR}/orders/listener.hh"
  "${INC_DIR}/orders/parser.hh"
148
  "${INC_DIR}/pipe_handle.hh"
149
  "${INC_DIR}/policy.hh"
150
  "${INC_DIR}/reporter.hh"
151
152
153
)
target_link_libraries(
  "${CONNECTORLIB}"
154
  ${PERL_LIBRARIES}
155
  ${CLIB_LIBRARIES})
156
157
158
159
160

# Perl connector.
set(CONNECTOR "centreon_connector_perl")
add_executable("${CONNECTOR}"
  # Sources.
161
162
163
164
165
166
167
168
169
170
  "${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 ()
171
  set(PREFIX_BINARY "${CMAKE_INSTALL_PREFIX}/bin")
172
173
174
175
176
177
178
179
endif ()

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

# Packaging.
include("package.cmake")
180
181
182
183
184
185

# Testing.
option(WITH_TESTING "Build unit tests." OFF)
if (WITH_TESTING)
  # Enable testing.
  enable_testing()
186
  include_directories("${PROJECT_SOURCE_DIR}")
187
  set(CONNECTOR_TEST_DIR "${PROJECT_SOURCE_DIR}/test/connector")
188
189
190
191
  get_property(CONNECTOR_PERL_BINARY
    TARGET "${CONNECTOR}"
    PROPERTY LOCATION)
  configure_file(
192
193
    "${TEST_DIR}/connector/paths.hh.in"
    "${TEST_DIR}/connector/paths.hh")
194

195
  # Embedded Perl tests.
196
197
  #   Simple script execution #1.
  set(TEST_NAME "embedded_perl_run_simple_1")
198
  add_executable("${TEST_NAME}"
199
200
201
202
203
204
205
    "${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")
206
207
208
  target_link_libraries("${TEST_NAME}" ${CONNECTORLIB})
  add_test("${TEST_NAME}" "${TEST_NAME}")

209
210
211
212
213
214
215
216
217
218
219
220

  #
  # 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)
221
222
223
224
225
226
227
228
229
230
231
232
  # 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}")
233
234
235
236
237
238
239
240
241
242
243
244
  # 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}")
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
  # Execution library.
  add_library("test_execute" STATIC
    "${TEST_DIR}/connector/misc.cc"
    "${TEST_DIR}/connector/misc.hh")
  set(TEST_LIBRARIES ${CLIB_LIBRARIES} "test_execute")
  # Single script execution.
  set(TEST_NAME "connector_execute_single_script")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/execute_single_script.cc")
  target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  # Multiple script execution.
  set(TEST_NAME "connector_execute_multiple_scripts")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/execute_multiple_scripts.cc")
  target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
262
263
264
265
266
267
  # Module loading from script.
  set(TEST_NAME "connector_execute_module_loading")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/execute_module_loading.cc")
  target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287

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}")
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}")
288
289
290
291
292
if (WITH_TESTING)
  message(STATUS "    - Unit tests                 enabled")
else()
  message(STATUS "    - Unit tests                 disabled")
endif ()
293
294
295
296
297
298
message(STATUS "")
message(STATUS "  Install")
message(STATUS "    - Prefix                     ${CMAKE_INSTALL_PREFIX}")
message(STATUS "    - Binary prefix              ${PREFIX_BINARY}")
message(STATUS "    - Package                    ${PACKAGE_LIST}")
message(STATUS "")
299
300
301
message(STATUS "  Libraries")
message(STATUS "    - clib include directory     ${CLIB_INCLUDE_DIR}")
message(STATUS "    - clib library directory     ${CLIB_LIBRARIES}")