CMakeLists.txt 23.2 KB
Newer Older
1
##
2
## Copyright 2011-2015,2017 Centreon
3
##
4
5
6
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
7
##
8
##     http://www.apache.org/licenses/LICENSE-2.0
9
##
10
11
12
13
14
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
15
##
16
## For more information : contact@centreon.com
17
18
19
20
##

# Global options.
cmake_minimum_required(VERSION 2.8)
21
project("Centreon SSH Connector" CXX)
22
set(PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/..")
23
set(INC_DIR "${PROJECT_SOURCE_DIR}/inc/com/centreon/connector/ssh")
24
set(SRC_DIR "${PROJECT_SOURCE_DIR}/src")
25
set(TEST_DIR "${PROJECT_SOURCE_DIR}/test")
26
include_directories("${PROJECT_SOURCE_DIR}/inc")
27

28
# Project version.
29
set(CONNECTOR_SSH_MAJOR 1)
30
set(CONNECTOR_SSH_MINOR 1)
31
set(CONNECTOR_SSH_PATCH 3)
32
33
34
set(CONNECTOR_SSH_VERSION "${CONNECTOR_SSH_MAJOR}.${CONNECTOR_SSH_MINOR}.${CONNECTOR_SSH_PATCH}")
add_definitions(-DCENTREON_CONNECTOR_SSH_VERSION=\"${CONNECTOR_SSH_VERSION}\")

35
36
37
# We will use pkg-config if available.
include(FindPkgConfig)
if (PKG_CONFIG_FOUND)
38
39
40
  pkg_check_modules(CLIB QUIET "centreon-clib")  # Will be used below.
  pkg_check_modules(LIBSSH2 QUIET "libssh2")     # Will be used below.
  pkg_check_modules(LIBGCRYPT QUIET "libgcrypt") # Will be used below.
41
42
endif ()

43
# Find libssh2's headers.
44
if (WITH_LIBSSH2_INCLUDE_DIR)
45
46
47
48
49
50
51
52
53
54
  find_file(
    LIBSSH2_HEADER_FOUND
    "libssh2.h"
    PATHS "${WITH_LIBSSH2_INCLUDE_DIR}"
    NO_DEFAULT_PATH)
  if (NOT LIBSSH2_HEADER_FOUND)
    message(FATAL_ERROR "Could not find libssh2's headers in ${WITH_LIBSSH2_INCLUDE_DIR}.")
  endif ()
  include_directories("${WITH_LIBSSH2_INCLUDE_DIR}")
elseif (LIBSSH2_FOUND) # Was libssh2 detected with pkg-config ?
55
  if (CMAKE_CXX_FLAGS)
56
57
58
59
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBSSH2_CFLAGS}")
  else ()
    set(CMAKE_CXX_FLAGS "${LIBSSH2_CFLAGS}")
  endif ()
60
else ()
61
62
  find_path(LIBSSH2_INCLUDE_DIR "libssh2.h")
  if (NOT LIBSSH2_INCLUDE_DIR)
63
    message(FATAL_ERROR "Could not find libssh2's headers (try WITH_LIBSSH2_INCLUDE_DIR).")
64
  endif ()
65
  include_directories("${LIBSSH2_INCLUDE_DIR}")
66
67
68
endif ()

# Find libssh2's library.
69
70
if (WITH_LIBSSH2_LIBRARIES)
  set(LIBSSH2_LIBRARIES "${WITH_LIBSSH2_LIBRARIES}")
71
72
73
74
75
76
77
78
79
80
81
elseif (WITH_LIBSSH2_LIBRARY_DIR)
  find_library(
    LIBSSH2_LIBRARIES
    "ssh2"
    PATHS "${WITH_LIBSSH2_LIBRARY_DIR}"
    NO_DEFAULT_PATH)
  if (NOT LIBSSH2_LIBRARIES)
    message(FATAL_ERROR "Could not find libssh2's library in ${WITH_LIBSSH2_LIBRARY_DIR}.")
  endif ()
elseif (LIBSSH2_FOUND) # Was libssh2 detected with pkg-config ?
  set(LIBSSH2_LIBRARIES "${LIBSSH2_LDFLAGS}")
82
83
84
else ()
  find_library(LIBSSH2_LIBRARIES "ssh2")
  if (NOT LIBSSH2_LIBRARIES)
85
86
87
88
    message(FATAL_ERROR "Could not find libssh2's library (try WITH_LIBSSH2_LIBRARY_DIR or WITH_LIBSSH2_LIBRARIES).")
  endif ()
endif ()

89
# Check if libssh2 is using libgcrypt or OpenSSL.
90
91
92
93
94
if (WITH_LIBSSH2_WITH_LIBGCRYPT)
  set(LIBSSH2_WITH_LIBGCRYPT "${WITH_LIBSSH2_WITH_LIBGCRYPT}")
else ()
  set(LIBSSH2_WITH_LIBGCRYPT 1)
endif ()
95
if (LIBSSH2_WITH_LIBGCRYPT)
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  # Find libgcrypt's required header.
  if (WITH_LIBGCRYPT_INCLUDE_DIR)
    find_file(
      LIBGCRYPT_HEADER_FOUND
      "gcrypt.h"
      PATHS "${WITH_LIBGCRYPT_INCLUDE_DIR}"
      NO_DEFAULT_PATH)
    if (NOT LIBGCRYPT_HEADER_FOUND)
      message(FATAL_ERROR "Could not find libgcrypt's headers in ${WITH_LIBGCRYPT_INCLUDE_DIR}.")
    endif ()
    include_directories("${WITH_LIBGCRYPT_INCLUDE_DIR}")
  else ()
    find_file(LIBGCRYPT_HEADER_FOUND "gcrypt.h")
    if (NOT LIBGCRYPT_HEADER_FOUND)
      message(FATAL_ERROR "Could not find libgcrypt's headers (try WITH_LIBGCRYPT_INCLUDE_DIR).")
    endif ()
  endif ()

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  # Find libgcrypt's library.
  if (WITH_LIBGCRYPT_LIBRARIES)
    set(LIBGCRYPT_LIBRARIES "${WITH_LIBGCRYPT_LIBRARIES}")
  elseif (WITH_LIBGCRYPT_LIBRARY_DIR)
    find_library(
      LIBGCRYPT_LIBRARIES
      "gcrypt"
      PATHS "${WITH_LIBGCRYPT_LIBRARY_DIR}"
      NO_DEFAULT_PATH)
    if (NOT LIBGCRYPT_LIBRARIES)
      message(FATAL_ERROR "Could not find libgcrypt's library in ${WITH_LIBGCRYPT_LIBRARY_DIR}.")
    endif ()
  elseif (LIBGCRYPT_FOUND) # Was libgcrypt detected with pkg-config ?
    set(LIBGCRYPT_LIBRARIES "${LIBGCRYPT_LDFLAGS}")
  else ()
    find_library(LIBGCRYPT_LIBRARIES "gcrypt")
    if (NOT LIBGCRYPT_LIBRARIES)
      message(FATAL_ERROR "Could not find libgcrypt's library (try WITH_LIBGCRYPT_LIBRARY_DIR).")
    endif ()
  endif ()

135
  # Add macro.
136
137
138
  add_definitions(-DLIBSSH2_WITH_LIBGCRYPT)
endif ()

139
140
141
142
143
144
145
146
147
148
149
# 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}")
150
  set(CLIB_INCLUDE_DIR "${WITH_CENTREON_CLIB_INCLUDE_DIR}")
151
elseif (CLIB_FOUND) # Was Centreon Clib detected with pkg-config ?
152
  if (CMAKE_CXX_FLAGS)
153
154
155
156
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CLIB_CFLAGS}")
  else ()
    set(CMAKE_CXX_FLAGS "${CLIB_CFLAGS}")
  endif ()
157
else ()
Dorian Guillois's avatar
Dorian Guillois committed
158
  find_path(CLIB_INCLUDE_DIR "com/centreon/clib/version.hh" PATH_SUFFIXES "centreon-clib")
159
  if (NOT CLIB_INCLUDE_DIR)
Dorian Guillois's avatar
Dorian Guillois committed
160
    message(FATAL_ERROR "Could not find Centreon Clib's headers (try WITH_CENTREON_CLIB_INCLUDE_DIR).")
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  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).")
183
  endif ()
184
185
endif ()

186
187
188
189
190
191
# Should the connector perform check against known_hosts file ?
option(WITH_KNOWN_HOSTS_CHECK "Check hosts against user's known_hosts file." OFF)
if (WITH_KNOWN_HOSTS_CHECK)
  add_definitions(-DWITH_KNOWN_HOSTS_CHECK)
endif ()

192
193
# SSH connector library.
set(CONNECTORLIB "centreonconnectorssh")
194
195
add_library("${CONNECTORLIB}"
  # Sources.
196
  "${SRC_DIR}/checks/check.cc"
197
  "${SRC_DIR}/checks/listener.cc"
198
  "${SRC_DIR}/checks/result.cc"
199
  "${SRC_DIR}/checks/timeout.cc"
200
  "${SRC_DIR}/multiplexer.cc"
201
  "${SRC_DIR}/options.cc"
202
  "${SRC_DIR}/orders/listener.cc"
203
  "${SRC_DIR}/orders/parser.cc"
Dorian Guillois's avatar
Dorian Guillois committed
204
  "${SRC_DIR}/orders/options.cc"
205
  "${SRC_DIR}/policy.cc"
206
  "${SRC_DIR}/reporter.cc"
207
  "${SRC_DIR}/sessions/credentials.cc"
208
  "${SRC_DIR}/sessions/listener.cc"
209
  "${SRC_DIR}/sessions/session.cc"
210
  "${SRC_DIR}/sessions/socket_handle.cc"
211
  # Headers.
212
  "${INC_DIR}/checks/check.hh"
213
  "${INC_DIR}/checks/listener.hh"
214
  "${INC_DIR}/checks/result.hh"
215
  "${INC_DIR}/checks/timeout.hh"
216
  "${INC_DIR}/multiplexer.hh"
217
  "${INC_DIR}/namespace.hh"
218
  "${INC_DIR}/options.hh"
219
  "${INC_DIR}/orders/listener.hh"
220
  "${INC_DIR}/orders/parser.hh"
Dorian Guillois's avatar
Dorian Guillois committed
221
  "${INC_DIR}/orders/options.hh"
222
  "${INC_DIR}/policy.hh"
223
  "${INC_DIR}/reporter.hh"
224
  "${INC_DIR}/sessions/credentials.hh"
225
  "${INC_DIR}/sessions/listener.hh"
226
  "${INC_DIR}/sessions/session.hh"
227
  "${INC_DIR}/sessions/socket_handle.hh"
228
229
230
231
)
target_link_libraries(
  "${CONNECTORLIB}"
  ${LIBSSH2_LIBRARIES}
Dorian Guillois's avatar
Dorian Guillois committed
232
  ${CLIB_LIBRARIES}
233
  ${LIBGCRYPT_LIBRARIES}
234
  "pthread"
Dorian Guillois's avatar
Dorian Guillois committed
235
)
236
237
238
239
240
241
242

# SSH connector.
set(CONNECTOR "centreon_connector_ssh")
add_executable("${CONNECTOR}"
  # Sources.
  "${SRC_DIR}/main.cc"
)
243
target_link_libraries("${CONNECTOR}" ${CONNECTORLIB})
244

245
246
247
248
249
250
251
# Installation path.
if (WITH_PREFIX)
  set(CMAKE_INSTALL_PREFIX "${WITH_PREFIX}")
endif ()
if (WITH_PREFIX_BINARY)
  set(PREFIX_BINARY "${WITH_PREFIX_BINARY}")
else ()
252
  set(PREFIX_BINARY "${CMAKE_INSTALL_PREFIX}/bin")
253
254
255
256
257
endif ()

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

259
# Packaging.
260
include("package.cmake")
261

262
263
264
265
266
# Testing.
option(WITH_TESTING "Build unit tests." OFF)
if (WITH_TESTING)
  # Enable testing.
  enable_testing()
267
  include_directories("${PROJECT_SOURCE_DIR}")
268
269
270
271
272
273
  get_property(CONNECTOR_SSH_BINARY
    TARGET "${CONNECTOR}"
    PROPERTY LOCATION)
  configure_file(
    "${TEST_DIR}/connector/binary.hh.in"
    "${TEST_DIR}/connector/binary.hh")
274

275
276
  # checks namespace tests.
  # result tests.
277
  #   Default constructor.
278
  set(TEST_NAME "checks_result_ctor_default")
279
  add_executable("${TEST_NAME}"
280
    "${TEST_DIR}/checks/result/ctor_default.cc")
281
282
283
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Command ID property.
284
  set(TEST_NAME "checks_result_command_id")
285
  add_executable("${TEST_NAME}"
286
    "${TEST_DIR}/checks/result/command_id.cc")
287
288
289
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Error property.
290
  set(TEST_NAME "checks_result_error")
291
  add_executable("${TEST_NAME}"
292
    "${TEST_DIR}/checks/result/error.cc")
293
294
295
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Executed
296
  set(TEST_NAME "checks_result_executed")
297
  add_executable("${TEST_NAME}"
298
    "${TEST_DIR}/checks/result/executed.cc")
299
300
301
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Exit code property.
302
  set(TEST_NAME "checks_result_exit_code")
303
  add_executable("${TEST_NAME}"
304
    "${TEST_DIR}/checks/result/exit_code.cc")
305
306
307
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Output property.
308
  set(TEST_NAME "checks_result_output")
309
  add_executable("${TEST_NAME}"
310
    "${TEST_DIR}/checks/result/output.cc")
311
312
313
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Copy constructor.
314
  set(TEST_NAME "checks_result_ctor_copy")
315
  add_executable("${TEST_NAME}"
316
    "${TEST_DIR}/checks/result/ctor_copy.cc")
317
318
319
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Assignment operator.
320
  set(TEST_NAME "checks_result_assignment")
321
  add_executable("${TEST_NAME}"
322
    "${TEST_DIR}/checks/result/assignment.cc")
323
324
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
  # timeout tests.
  #   Constructor.
  set(TEST_NAME "checks_timeout_ctor")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/checks/timeout/ctor.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Copy constructor.
  set(TEST_NAME "checks_timeout_ctor_copy")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/checks/timeout/ctor_copy.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Assignment operator.
  set(TEST_NAME "checks_timeout_assignment")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/checks/timeout/assignment.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Set target check object.
  set(TEST_NAME "checks_timeout_set_check")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/checks/timeout/set_check.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")

351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376

  #
  # orders namespace tests.
  #
  # Common library.
  add_library("test_orders" STATIC
    # Sources.
    "${TEST_DIR}/orders/buffer_handle.cc"
    "${TEST_DIR}/orders/fake_listener.cc"
    # Headers.
    "${TEST_DIR}/orders/buffer_handle.hh"
    "${TEST_DIR}/orders/fake_listener.hh")
  set(ORDERS_LIBRARIES "test_orders" "${CONNECTORLIB}")
  # parser tests.
  #   Default constructor.
  set(TEST_NAME "orders_parser_ctor_default")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/ctor_default.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   EOF detection.
  set(TEST_NAME "orders_parser_eof")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/eof.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
377
378
379
380
381
382
  #   Close detection.
  set(TEST_NAME "orders_parser_close")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/close.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
  #   Error detection.
  set(TEST_NAME "orders_parser_error")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/error.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Version order.
  set(TEST_NAME "orders_parser_version")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/version.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Quit order.
  set(TEST_NAME "orders_parser_quit")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/quit.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Execute order.
  set(TEST_NAME "orders_parser_execute")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/execute.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Order suite.
  set(TEST_NAME "orders_parser_suite")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/suite.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
  #   Copy constructor.
  set(TEST_NAME "orders_parser_ctor_copy")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/ctor_copy.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Assignment operator.
  set(TEST_NAME "orders_parser_assignment")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/assignment.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Invalid command.
  set(TEST_NAME "orders_parser_invalid_command")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/invalid_command.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Not enough arguments for execution.
  set(TEST_NAME "orders_parser_execute_not_enough_args")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/execute_not_enough_args.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Invalid command ID in execution order.
  set(TEST_NAME "orders_parser_execute_invalid_id")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/execute_invalid_id.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Invalid timeout in execution order.
  set(TEST_NAME "orders_parser_execute_invalid_timeout")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/execute_invalid_timeout.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Invalid start time in execution order.
  set(TEST_NAME "orders_parser_execute_invalid_start_time")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/orders/parser/execute_invalid_start_time.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
455

456

457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
  #
  # sessions namespace tests.
  #
  # credentials tests.
  #   Default constructor.
  set(TEST_NAME "sessions_credentials_ctor_default")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/sessions/credentials/ctor_default.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Host property.
  set(TEST_NAME "sessions_credentials_host")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/sessions/credentials/host.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   User property.
  set(TEST_NAME "sessions_credentials_user")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/sessions/credentials/user.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Password property.
  set(TEST_NAME "sessions_credentials_password")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/sessions/credentials/password.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
485
486
487
488
489
490
  #   Constructor which set values.
  set(TEST_NAME "sessions_credentials_ctor_values")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/sessions/credentials/ctor_values.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
491
492
493
494
495
496
497
498
499
500
501
502
  #   Copy constructor.
  set(TEST_NAME "sessions_credentials_ctor_copy")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/sessions/credentials/ctor_copy.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Assignment operator.
  set(TEST_NAME "sessions_credentials_assignment")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/sessions/credentials/assignment.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
503
504
505
506
507
508
  #   Less-than operator.
  set(TEST_NAME "sessions_credentials_less_than")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/sessions/credentials/less_than.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
509

510

511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
  #
  # Root namespace tests.
  #
  # multiplexer tests.
  #   Check singleton.
  set(TEST_NAME "multiplexer_singleton")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/multiplexer/singleton.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  # reporter tests.
  #   Default constructor.
  set(TEST_NAME "reporter_ctor_default")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/reporter/ctor_default.cc")
  target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Report protocol version.
  set(TEST_NAME "reporter_send_version")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/reporter/send_version.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Report check result.
  set(TEST_NAME "reporter_send_result")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/reporter/send_result.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  #   Handle has error.
  set(TEST_NAME "reporter_error")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/reporter/error.cc")
  target_link_libraries("${TEST_NAME}" ${ORDERS_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")

547

548
549
550
  #
  # Process tests.
  #
551
  set(TEST_LIBRARIES ${CLIB_LIBRARIES})
552
553
554
555
556
  # Help.
  add_test("connector_help" "${CONNECTOR}" "--help")
  # Version.
  add_test("connector_version" "${CONNECTOR}" "--version")
  # Invalid flag.
557
558
  add_test("connector_invalid_flag" "${CONNECTOR}" "--merethis")
  set_tests_properties("connector_invalid_flag"
559
    PROPERTIES WILL_FAIL TRUE)
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
  # Invalid command.
  set(TEST_NAME "connector_invalid_command")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/invalid_command.cc")
  target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  # Invalid command ID.
  set(TEST_NAME "connector_invalid_command_id")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/invalid_command_id.cc")
  target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  # 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}")
  # Quit command.
  set(TEST_NAME "connector_command_quit")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/command_quit.cc")
  target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
  # Version command.
  set(TEST_NAME "connector_command_version")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/command_version.cc")
  target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
590
591
592
593
594
595
  # Execute command.
  set(TEST_NAME "connector_command_execute")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/command_execute.cc")
  target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
596
597
598
599
600
601
  # Execute command with a log file
  set(TEST_NAME "connector_command_execute_log_file")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/command_execute_log_file.cc")
  target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
602
603
604
605
606
607
  # Non-existent host.
  set(TEST_NAME "connector_non_existent_host")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/non_existent_host.cc")
  target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
608
609
610
611
612
613
  # Single check that timeouts.
  set(TEST_NAME "connector_single_check_timeout")
  add_executable("${TEST_NAME}"
    "${TEST_DIR}/connector/single_check_timeout.cc")
  target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
  add_test("${TEST_NAME}" "${TEST_NAME}")
614

615
endif ()
616
617
618
619
620
621

# Summary.
message(STATUS "")
message(STATUS "Configuration Summary")
message(STATUS "---------------------")
message(STATUS "")
622
message(STATUS "  Project")
623
message(STATUS "    - Name                       Centreon SSH Connector")
624
message(STATUS "    - Version                    ${CONNECTOR_SSH_VERSION}")
625
626
627
628
629
if (WITH_KNOWN_HOSTS_CHECK)
  message(STATUS "    - Known hosts check          enabled")
else ()
  message(STATUS "    - Known hosts check          disabled")
endif ()
630
631
632
633
634
635
636
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")
637
message(STATUS "    - Compiler                   ${CMAKE_CXX_COMPILER} (${CMAKE_CXX_COMPILER_ID})")
638
message(STATUS "    - Extra compilation flags    ${CMAKE_CXX_FLAGS}")
639
640
641
642
643
if (WITH_TESTING)
  message(STATUS "    - Unit tests                 enabled")
else ()
  message(STATUS "    - Unit tests                 disabled")
endif ()
644
message(STATUS "")
645
message(STATUS "  Install")
646
647
message(STATUS "    - Prefix                     ${CMAKE_INSTALL_PREFIX}")
message(STATUS "    - Binary prefix              ${PREFIX_BINARY}")
648
649
message(STATUS "    - Package                    ${PACKAGE_LIST}")
message(STATUS "")
650
651
652
message(STATUS "  Libraries")
message(STATUS "    - clib include directory     ${CLIB_INCLUDE_DIR}")
message(STATUS "    - clib library directory     ${CLIB_LIBRARIES}")