forked from mickem/nscp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
663 lines (593 loc) · 25.5 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
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
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
377
378
379
380
381
382
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
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
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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
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
547
548
549
550
551
552
553
554
555
556
557
558
559
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
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
cmake_minimum_required(VERSION 2.6)
PROJECT(NSCP CXX C)
ENABLE_TESTING()
IF(COMMAND CMAKE_POLICY)
CMAKE_POLICY(SET CMP0011 NEW)
ENDIF(COMMAND CMAKE_POLICY)
#############################################################################
#
# Setup cmake enviornment and include custom config overrides
#
#############################################################################
IF(NSCP_CMAKE_CONFIG)
MESSAGE(STATUS "Reading custom variables from: ${NSCP_CMAKE_CONFIG}")
INCLUDE(${NSCP_CMAKE_CONFIG})
ELSEIF(EXISTS ${CMAKE_SOURCE_DIR}/build.cmake)
MESSAGE(STATUS "Reading custom variables from: ${CMAKE_SOURCE_DIR}/build.cmake")
INCLUDE(${CMAKE_SOURCE_DIR}/build.cmake)
ELSEIF(EXISTS ${PROJECT_BINARY_DIR}/build.cmake)
MESSAGE(STATUS "Reading custom variables from: ${PROJECT_BINARY_DIR}/build.cmake")
INCLUDE(${PROJECT_BINARY_DIR}/build.cmake)
ELSEIF(EXISTS ${PROJECT_BINARY_DIR}/../build.cmake)
MESSAGE(STATUS "Reading custom variables from: ${PROJECT_BINARY_DIR}/../build.cmake")
INCLUDE(${PROJECT_BINARY_DIR}/../build.cmake)
ELSE(NSCP_CMAKE_CONFIG)
MESSAGE(STATUS "NO build configuration found")
ENDIF(NSCP_CMAKE_CONFIG)
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/build/cmake;${CMAKE_MODULE_PATH}")
SET(MODULE_SUBFOLDER "modules")
IF(WIN32)
SET(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR})
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(atlbase.h FOUND_ATL)
if(FOUND_ATL)
SET(VSTUDIO_EXPRESS OFF)
else(FOUND_ATL)
MESSAGE(WARNING "Visual studio express seem to be used, some modules will be missing")
SET(VSTUDIO_EXPRESS ON)
endif(FOUND_ATL)
ENDIF()
SET(BUILD_PYTHON_FOLDER "${CMAKE_SOURCE_DIR}/build/python")
SET(BUILD_CMAKE_FOLDER "${CMAKE_SOURCE_DIR}/build/cmake")
SET(BUILD_BATCH_FOLDER "${CMAKE_SOURCE_DIR}/build/batch")
SET(BUILD_ROOT_FOLDER "${CMAKE_SOURCE_DIR}")
SET(BUILD_TARGET_EXE_PATH "${PROJECT_BINARY_DIR}")
SET(BUILD_TARGET_ROOT_PATH "${PROJECT_BINARY_DIR}")
SET(BUILD_TARGET_LIB_PATH "${BUILD_TARGET_EXE_PATH}/${MODULE_SUBFOLDER}")
SET(BUILD_TARGET_INSTLIB_PATH "${BUILD_TARGET_EXE_PATH}/installer-dlls")
SET(NSCP_PROJECT_BINARY_DIR ${PROJECT_BINARY_DIR})
SET(NSCP_PROJECT_BINARY_DIR_NATIVE ${PROJECT_BINARY_DIR})
IF(WIN32)
STRING(REPLACE "/" "\\" NSCP_PROJECT_BINARY_DIR_NATIVE ${NSCP_PROJECT_BINARY_DIR_NATIVE})
ENDIF()
IF(NOT CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "/usr")
ENDIF()
SET(MODULE_TARGET_FOLDER lib/nsclient/modules)
SET(LIB_TARGET_FOLDER lib)
SET(SYSTEMD_TARGET_FOLDER /lib/systemd/system)
SET(SBIN_TARGET_FOLDER sbin)
SET(BIN_TARGET_FOLDER bin)
SET(LOG_TARGET_FOLDER /var/log)
SET(ETC_TARGET_FOLDER /etc)
IF(NOT DEFINED USE_STATIC_RUNTIME)
SET(USE_STATIC_RUNTIME FALSE)
ENDIF(NOT DEFINED USE_STATIC_RUNTIME)
IF(USE_STATIC_RUNTIME)
MESSAGE(STATUS "Using static runtime")
SET(BUILD_SHARED_LIBS OFF)
SET(NSCP_GLOBAL_DEFINES ${NSCP_GLOBAL_DEFINES} -DBOOST_ALL_NO_LIB)
add_definitions(-Dnscp_protobuf_NOLIB -Dplugin_api_NOLIB -Dwhere_filter_NOLIB -Djson_protobuf_NOLIB -Dlua_protobuf_NOLIB)
IF(WIN32)
SET(Boost_USE_STATIC_LIBS ON)
SET(Boost_USE_STATIC_RUNTIME ON)
SET(BOOST_USE_MULTITHREADED ON)
ENDIF(WIN32)
SET(CRYPTOPP_RUNTIME_TYPE "STATIC")
SET(JSON_SPIRIT_LIBRARY_TYPE "STATIC")
SET(BUILD_STATIC_LIBS ON)
ELSE(USE_STATIC_RUNTIME)
SET(NSCP_GLOBAL_DEFINES ${NSCP_GLOBAL_DEFINES} -DBOOST_ALL_NO_LIB -DBOOST_THREAD_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK)
MESSAGE(STATUS "Using dynamic runtime")
SET(BUILD_SHARED_LIBS ON)
IF(WIN32)
SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_STATIC_RUNTIME OFF)
SET(BOOST_USE_MULTITHREADED ON)
ENDIF(WIN32)
SET(CRYPTOPP_RUNTIME_TYPE "SHARED")
SET(JSON_SPIRIT_LIBRARY_TYPE "SHARED")
SET(BUILD_STATIC_LIBS OFF)
ENDIF(USE_STATIC_RUNTIME)
IF(WIN32)
SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
SET(CPACK_GENERATOR ZIP)
ELSE()
SET(CMAKE_INSTALL_PREFIX "/usr")
execute_process(COMMAND lsb_release -si OUTPUT_VARIABLE DISTRIBUTION OUTPUT_STRIP_TRAILING_WHITESPACE)
if(DISTRIBUTION STREQUAL "Fedora" OR DISTRIBUTION STREQUAL "CentOS")
execute_process(COMMAND rpm -qa *-release OUTPUT_VARIABLE LINUXVERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
STRING(REGEX REPLACE ".*\\.(el[0-9]+)\\..*" "\\1" LINUXDIST ${LINUXVERSION})
if(LINUXDIST STREQUAL "el7")
MESSAGE(STATUS "Linux detected as redhat clone with systemd (${LINUXDIST})")
SET(SYSTEMD ON)
SET(INITD OFF)
else()
MESSAGE(STATUS "Linux detected as redhat clone with initd (${LINUXDIST})")
SET(SYSTEMD OFF)
SET(INITD ON)
endif()
SET(REDHAT_CLONE ON)
SET(DEBIAN_CLONE OFF)
else()
MESSAGE(STATUS "Linux detected as debian clone with initd")
SET(SYSTEMD OFF)
SET(INITD ON)
SET(REDHAT_CLONE OFF)
SET(DEBIAN_CLONE ON)
endif()
ENDIF()
INCLUDE(${BUILD_CMAKE_FOLDER}/SetMultiThread.cmake)
INCLUDE(${BUILD_CMAKE_FOLDER}/GoogleProtoBuf.cmake)
INCLUDE(${BUILD_CMAKE_FOLDER}/functions.cmake)
#############################################################################
#
# Find all dependencies and report anything missing.
#
#############################################################################
INCLUDE(${BUILD_CMAKE_FOLDER}/dependencies.cmake)
#############################################################################
#
# Validate all required dependencies and terminate on failures.
#
#############################################################################
MESSAGE(STATUS "Validating required dependencies:")
SET(HAVE_REQUIRED_DEPENDENCIES TRUE)
IF(NOT PYTHONINTERP_FOUND)
SET(HAVE_REQUIRED_DEPENDENCIES FALSE)
MESSAGE(WARNING " - python(exe) not found! (Required by the build process)")
ENDIF(NOT PYTHONINTERP_FOUND)
IF(NOT PROTOBUF_FOUND)
SET(HAVE_REQUIRED_DEPENDENCIES FALSE)
MESSAGE(WARNING " - protocol buffers not found! XXX=${PROTOBUF_LIBRARYDIR}! (Required by nsclient++)")
ENDIF(NOT PROTOBUF_FOUND)
IF(NOT Boost_FOUND)
SET(HAVE_REQUIRED_DEPENDENCIES FALSE)
MESSAGE(WARNING " - boost libraries was not found: ${Boost_ERROR_REASON} (Required by nsclient++)")
ENDIF(NOT Boost_FOUND)
IF(NOT WIN32)
# IF(NOT CMAKE_USE_PTHREADS_INIT)
# SET(HAVE_REQUIRED_DEPENDENCIES FALSE)
# MESSAGE(WARNING " - Could not find POSIX threads")
# ENDIF(NOT CMAKE_USE_PTHREADS_INIT)
ENDIF(NOT WIN32)
IF(NOT HAVE_REQUIRED_DEPENDENCIES)
MESSAGE(FATAL_ERROR " - missing required dependencies found!")
ELSE(NOT HAVE_REQUIRED_DEPENDENCIES)
MESSAGE(STATUS " - All required dependecies found! (some modules and features migh stil be missing though)")
ENDIF(NOT HAVE_REQUIRED_DEPENDENCIES)
IF(USE_STATIC_RUNTIME)
ELSE(USE_STATIC_RUNTIME)
IF(WIN32)
message(STATUS "Copying redist libraries to target")
find_redist(REDIST_LIST)
foreach(LIB ${REDIST_LIST})
get_filename_component(_NAME ${LIB} NAME)
message(STATUS " + ${_NAME}")
copy_file(${LIB} ${PROJECT_BINARY_DIR})
install(FILES "${LIB}" DESTINATION .)
endforeach()
SET (LIBS DATE_TIME FILESYSTEM PROGRAM_OPTIONS PYTHON "REGEX" SYSTEM THREAD CHRONO)
FOREACH (LIB ${LIBS})
IF(Boost_${LIB}_LIBRARY_RELEASE)
STRING(REPLACE ".lib" ".dll" Boost_${LIB}_LIBRARY_RELEASE_DLL ${Boost_${LIB}_LIBRARY_RELEASE})
get_filename_component(_NAME "${Boost_${LIB}_LIBRARY_RELEASE_DLL}" NAME)
message(STATUS " + ${_NAME}")
COPY_FILE(${Boost_${LIB}_LIBRARY_RELEASE_DLL} ${PROJECT_BINARY_DIR})
STRING(REPLACE ".lib" ".dll" Boost_${LIB}_LIBRARY_DEBUG_DLL ${Boost_${LIB}_LIBRARY_DEBUG})
COPY_FILE(${Boost_${LIB}_LIBRARY_DEBUG_DLL} ${PROJECT_BINARY_DIR})
install(FILES ${Boost_${LIB}_LIBRARY_RELEASE_DLL} DESTINATION .)
ENDIF()
ENDFOREACH()
SET (LIBS LIB SSL)
FOREACH (LIB ${LIBS})
STRING(REPLACE ".lib" ".dll" ${LIB}_EAY_RELEASE_DLL "${${LIB}_EAY_RELEASE}")
get_filename_component(_NAME "${${LIB}_EAY_RELEASE_DLL}" NAME)
message(STATUS " + ${_NAME}")
COPY_FILE("${${LIB}_EAY_RELEASE_DLL}" ${PROJECT_BINARY_DIR})
install(FILES "${${LIB}_EAY_RELEASE_DLL}" DESTINATION .)
ENDFOREACH()
ENDIF()
ENDIF(USE_STATIC_RUNTIME)
IF(PYTHON_DIST)
SET (LIBS _socket.pyd python27.dll python27.zip unicodedata.pyd)
FOREACH (LIB ${LIBS})
COPY_FILE(${PYTHON_DIST}/${LIB} ${PROJECT_BINARY_DIR})
INSTALL(FILES ${PYTHON_DIST}/${LIB} DESTINATION .)
ENDFOREACH()
ENDIF(PYTHON_DIST)
#############################################################################
#
# Bump version number (if requested) and set up variables with current version
#
#############################################################################
SET(VERSION_TXT ${CMAKE_CURRENT_SOURCE_DIR}/version.txt)
IF("${INCREASE_BUILD}" STREQUAL "1")
EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE}
"${BUILD_PYTHON_FOLDER}/version.py"
--file ${VERSION_TXT}
--display
--update build
--generate-hpp ${PROJECT_BINARY_DIR}/include/version.hpp
OUTPUT_VARIABLE TMP_VERSION_OUT
)
ENDIF("${INCREASE_BUILD}" STREQUAL "1")
EXECUTE_PROCESS(
COMMAND ${PYTHON_EXECUTABLE}
"${BUILD_PYTHON_FOLDER}/version.py"
--file ${VERSION_TXT}
--display
--generate-hpp ${PROJECT_BINARY_DIR}/include/version.hpp
OUTPUT_VARIABLE TMP_VERSION_OUT
)
IF(TMP_VERSION_OUT STREQUAL "")
MESSAGE(FATA_ERROR, "Failed to generate version from: ${PYTHON_EXECUTABLE} ${BUILD_PYTHON_FOLDER}/version.py --file ${VERSION_TXT} --display ")
ENDIF(TMP_VERSION_OUT STREQUAL "")
STRING(REGEX REPLACE ".*([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\1" VERSION_SERIES ${TMP_VERSION_OUT})
STRING(REGEX REPLACE ".*([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\2" VERSION_MAJOR ${TMP_VERSION_OUT})
STRING(REGEX REPLACE ".*([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\3" VERSION_MINOR ${TMP_VERSION_OUT})
STRING(REGEX REPLACE ".*([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.([0-9]+).*" "\\4" VERSION_BUILD ${TMP_VERSION_OUT})
MESSAGE(STATUS "Version: ${VERSION_SERIES}.${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}")
SET(NSCP_LIB_VERSION "${VERSION_SERIES}.${VERSION_MAJOR}.${VERSION_MINOR}")
SET(NSCP_FULL_VERSION "${VERSION_SERIES}.${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_BUILD}")
IF(WIN32)
SET(VERSION_ARCH Win32)
IF(CMAKE_CL_64)
SET(VERSION_ARCH x64)
ENDIF(CMAKE_CL_64)
ELSE(WIN32)
SET(VERSION_ARCH Unknown)
ENDIF(WIN32)
#############################################################################
#
# Setup c/C++ build enviornment and flags
#
#############################################################################
SET(NSCP_INCLUDEDIR ${CMAKE_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${NSCP_INCLUDEDIR} ${CMAKE_CURRENT_BINARY_DIR}/libs)
SET(CMAKE_LIBRARY_PATH "${CMAKE_LIBRARY_PATH};${OPENSSL_LIBRARY_DIR};${NSCP_LIBRARYDIR};${BOOST_LIBRARYDIR}")
SET_MULTITHREAD()
if(MSVC)
# Force to always compile with W4
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# Update if necessary
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-long-long -pedantic -Wno-unused-parameter")
endif()
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
message(STATUS "Added parallel build arguments")
endif()
IF(NOT SHARED_LIBS)
IF(WIN32)
OPTION(SHARED_LIBS "Compile shared libraries" OFF)
ELSE(WIN32)
OPTION(SHARED_LIBS "Compile shared libraries" ON)
ENDIF(WIN32)
ENDIF(NOT SHARED_LIBS)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
INCLUDE_DIRECTORIES("${PROTOBUF_INCLUDE_DIR}")
INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
add_definitions(-DUNICODE -D_UNICODE)
IF(WIN32)
SET(RUNDIR "c:/nscp" CACHE PATH "Not really used in WIN32")
ELSE(WIN32)
SET(USERLIB_ROOT /usr CACHE PATH "Other installation prefix for dependent libraries")
SET(LIB_INSTALL_DIR "lib" CACHE STRING "Default path for libraries within ${CMAKE_INSTALL_PREFIX}")
SET(RUNDIR "/usr/wt/run" CACHE PATH "Default path for wt session management (only used by FCGI connector; not relative to CMAKE_INSTALL_PREFIX)")
SET(CONFIGURATION /etc/nscp/boot.ini CACHE PATH "Path to the boot configuration file")
SET(MAIN_CONFIGURATION /etc/nscp/nscp.xml CACHE PATH "Path for the client configurtion file")
SET(DEPLOYROOT /usr/bin CACHE PATH "Path to deploy examples into)")
ENDIF(WIN32)
IF(CMAKE_COMPILER_IS_GNUCXX)
IF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE)
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC" )
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC" )
ENDIF("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64" AND NOT APPLE)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
SET(NSCP_GLOBAL_DEFINES ${NSCP_GLOBAL_DEFINES} -DUNICODE -D_UNICODE)
IF (WIN32)
SET(NSCP_GLOBAL_DEFINES "${NSCP_GLOBAL_DEFINES} -D_CRT_SECURE_NO_WARNINGS -D_WIN32_WINNT=0x0501 -DWINVER=0x0501")
ENDIF (WIN32)
IF(WIN32)
SET(EXTRA_LIBS ${EXTRA_LIBS} Userenv ole32)
ENDIF(WIN32)
IF(CMAKE_HOST_UNIX)
SET(UNIX_FLAVOUR LINUX CACHE STRING "Choose your unix flavour UNIX, AIX, HPUX" FORCE)
IF(UNIX_FLAVOUR STREQUAL LINUX)
SET(NSCP_GLOBAL_DEFINES ${NSCP_GLOBAL_DEFINES} -DLINUX)
ENDIF(UNIX_FLAVOUR STREQUAL LINUX)
SET(EXTRA_LIBS ${EXTRA_LIBS} ${CMAKE_DL_LIBS})
ENDIF()
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
ENDIF(NOT CMAKE_BUILD_TYPE)
LINK_DIRECTORIES(${CMAKE_LIBRARY_PATH} ${OPENSSL_LIBRARY_DIR} ${NSCP_LIBRARYDIR} ${BOOST_LIBRARYDIR})
# Compile time constants & make sure our build finds it
SET(CONFIG_DEFAULT_SERVICE_NAME "NSCP" CACHE STRING "The name of the service")
SET(CONFIG_DEFAULT_SERVICE_DESC "Monitoring Agent (Provides performance data for monitoring solutions like Nagios)" CACHE STRING "The description used for the service")
SET(CONFIG_DEFAULT_SERVICE_DEPS "" CACHE STRING "Any service dependencies to use for the default service")
SET(CONFIG_CRASH_SUBMIT_URL "https://crash.nsclient.org/post" CACHE STRING "Where to submit crash dump files")
SET(CONFIG_CRASH_ARCHIVE_FOLDER "\${shared-path}/crash-dumps" CACHE STRING "Where to archive chras dump files on the local filesystem")
SET(CONFIG_DEFAULT_CONF_REG_LOCATION "registry://HKEY_LOCAL_MACHINE/software/NSClient++" CACHE STRING "Default location for registry based settings")
SET(CONFIG_DEFAULT_CONF_OLD_LOCATION "old://\${exe-path}/nsc.ini" CACHE STRING "Default location for old config file")
IF(WIN32)
SET(INSTALL_FILES_BASE "")
SET(CONFIG_BOOT_CONF_LOCATION "\${exe-path}/boot.ini" CACHE STRING "Location of boot ini (the file which specified where to load the config)")
SET(CONFIG_DEFAULT_CONF_LOCATION "old" CACHE STRING "Default configuration store")
SET(CONFIG_DEFAULT_CONF_INI_BASE "ini://\${shared-path}/" CACHE STRING "Base location for ini files")
SET(CONFIG_MODULE_FOLDER "\${shared-path}/modules" CACHE STRING "modules folder")
SET(CONFIG_WEB_FOLDER "\${shared-path}/web" CACHE STRING "web folder")
SET(CONFIG_SCRIPTS_FOLDER "\${shared-path}/scripts" CACHE STRING "script folder")
SET(CONFIG_CERT_FOLDER "\${shared-path}/security" CACHE STRING "securoty (certificates) folder")
SET(CONFIG_DEFAULT_CACHE_PATH "\${shared-path}/cache" CACHE STRING "Path for caching stuff")
SET(CONFIG_LOG_FOLDER "\${shared-path}/log" CACHE STRING "Path for log files")
SET(CONFIG_DEFAULT_LOG_LOCATION "\${exe-path}/nsclient.log" CACHE STRING "PAth for log file")
ELSE()
SET(INSTALL_FILES_BASE "share/nsclient/")
SET(CONFIG_BOOT_CONF_LOCATION "/etc/nsclient/boot.ini" CACHE STRING "Location of boot ini (the file which specified where to load the config)")
SET(CONFIG_DEFAULT_CONF_LOCATION "ini" CACHE STRING "Default configuration store")
SET(CONFIG_DEFAULT_CONF_INI_BASE "ini:///etc/nsclient/" CACHE STRING "Base location for ini files")
SET(CONFIG_MODULE_FOLDER "\${shared-path}/modules" CACHE STRING "modules folder")
SET(CONFIG_WEB_FOLDER "\${shared-path}/web" CACHE STRING "web folder")
SET(CONFIG_SCRIPTS_FOLDER "\${shared-path}/scripts" CACHE STRING "script folder")
SET(CONFIG_CERT_FOLDER "\${shared-path}/security" CACHE STRING "securoty (certificates) folder")
SET(CONFIG_DEFAULT_CACHE_PATH "\${shared-path}/cache" CACHE STRING "Path for caching stuff")
SET(CONFIG_LOG_FOLDER "\${shared-path}/log" CACHE STRING "Path for log files")
SET(CONFIG_DEFAULT_LOG_LOCATION "\${shared-path}/log/nsclient.log" CACHE STRING "PAth for log file")
ENDIF()
SET(CONFIG_DEFAULT_CONF_INI_LOCATION "${CONFIG_DEFAULT_CONF_INI_BASE}nsclient.ini" CACHE STRING "Default location for ini files")
CONFIGURE_FILE(
${NSCP_INCLUDEDIR}/config.h.in
${PROJECT_BINARY_DIR}/include/config.h
@ONLY
)
IF(NOT WIN32)
CONFIGURE_FILE(
${CMAKE_SOURCE_DIR}/files/nscp.spec.in
${PROJECT_BINARY_DIR}/SPECS/nscp.spec
@ONLY
)
ENDIF()
CONFIGURE_FILE(
${BUILD_PYTHON_FOLDER}/postbuild.py
${BUILD_TARGET_EXE_PATH}/postbuild.py
)
CONFIGURE_FILE(
${BUILD_PYTHON_FOLDER}/config.py
${BUILD_TARGET_EXE_PATH}/config.py
)
CONFIGURE_FILE(
${BUILD_BATCH_FOLDER}/postbuild.bat
${BUILD_TARGET_EXE_PATH}/postbuild.bat
)
#INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include)
INCLUDE_DIRECTORIES(${NSCP_LOCAL_INCLUDE_PATH})
# WHat does this do? INSTALL_FILES(/include FILES ${WCONFIG_H_PATH})
IF(WIN32)
SET(NSCP_ERROR_CPP
${NSCP_INCLUDEDIR}/error/error_w32.cpp
)
SET(NSCP_ERROR_HPP
${NSCP_INCLUDEDIR}/error/error_w32.hpp
${NSCP_INCLUDEDIR}/error/error.hpp
)
ELSE()
SET(NSCP_ERROR_CPP
)
SET(NSCP_ERROR_HPP
${NSCP_INCLUDEDIR}/error/error.hpp
)
ENDIF()
#############################################################################
#
# Build all included and required libraries
#
#############################################################################
MESSAGE(STATUS "Building support libraries")
IF(JSON_SPIRIT_CMAKE)
MESSAGE(STATUS " - Json-Spirit")
ADD_SUBDIRECTORY(${JSON_SPIRIT_CMAKE})
SET_TARGET_PROPERTIES(json_spirit PROPERTIES FOLDER "libraries")
ENDIF(JSON_SPIRIT_CMAKE)
IF(CRYPTOPP_CMAKE)
MESSAGE(STATUS " - Crypto++")
SET(CRYPTOPP_BUILD_TESTS FALSE)
SET(CRYPTOPP_LIBRARY_TYPE "STATIC")
ADD_SUBDIRECTORY(${CRYPTOPP_CMAKE})
SET_TARGET_PROPERTIES(cryptlib PROPERTIES FOLDER "libraries")
ENDIF(CRYPTOPP_CMAKE)
IF(GTEST_FOUND AND ( NOT GTEST_GTEST_FOUND OR NOT GTEST_GTEST_MAIN_FOUND ) )
MESSAGE(STATUS " - google test++")
IF(BUILD_SHARED_LIBS)
SET(gtest_force_shared_crt ON CACHE BOOL "Override shared crt")
ENDIF(BUILD_SHARED_LIBS)
SET(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
SET(BUILD_SHARED_LIBS OFF)
ADD_SUBDIRECTORY(${GTEST_SRC_DIR} ${PROJECT_BINARY_DIR}/ext/gtest)
SET(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS})
SET_TARGET_PROPERTIES(gtest_main PROPERTIES FOLDER "libraries")
SET_TARGET_PROPERTIES(gtest PROPERTIES FOLDER "libraries")
SET_TARGET_PROPERTIES(gtest_main PROPERTIES COMPILE_DEFINITIONS "_VARIADIC_MAX=10")
SET_TARGET_PROPERTIES(gtest PROPERTIES COMPILE_DEFINITIONS "_VARIADIC_MAX=10")
SET(GTEST_GTEST_FOUND TRUE)
SET(GTEST_GTEST_LIBRARY gtest)
SET(GTEST_GTEST_MAIN_FOUND TRUE)
SET(GTEST_GTEST_MAIN_LIBRARY gtest_main)
ENDIF()
IF(NETLIB_FOUND)
IF(NOT (Boost_VERSION LESS 105400))
MESSAGE(STATUS " - c++-netlib")
SET(CPP-NETLIB_BUILD_SHARED_LIBS ON CACHE BOOL "Override")
SET(CPP-NETLIB_BUILD_SINGLE_LIB ON CACHE BOOL "Override")
SET(CPP-NETLIB_BUILD_TESTS OFF CACHE BOOL "Override")
SET(CPP-NETLIB_BUILD_EXAMPLES OFF CACHE BOOL "Override")
SET(CPP-NETLIB_BUILD_FOLDER "../../" CACHE STRING "Override")
SET(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
SET(BUILD_SHARED_LIBS OFF)
ADD_SUBDIRECTORY(ext/cpp-netlib)
SET(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS})
SET_TARGET_PROPERTIES(cppnetlib-client-connections PROPERTIES FOLDER "libraries")
SET_TARGET_PROPERTIES(cppnetlib-server-parsers PROPERTIES FOLDER "libraries")
SET_TARGET_PROPERTIES(cppnetlib-uri PROPERTIES FOLDER "libraries")
SET_TARGET_PROPERTIES(cppnetlib-client-connections PROPERTIES COMPILE_DEFINITIONS "BOOST_ALL_NO_LIB")
ENDIF()
ENDIF()
MESSAGE(STATUS " - Mongoose")
SET(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
SET(BUILD_SHARED_LIBS OFF)
SET(ENABLE_SSL ON CACHE BOOL "Override SSL support")
ADD_SUBDIRECTORY("ext/mongoose-cpp")
SET_TARGET_PROPERTIES(_mongoose PROPERTIES FOLDER "libraries")
SET(BUILD_SHARED_LIBS ${OLD_BUILD_SHARED_LIBS})
MESSAGE(STATUS " - Docs")
ADD_SUBDIRECTORY("ext/docs")
SET(ALL_LIB_NAMES)
MESSAGE(STATUS "Adding libraries")
FILE(GLOB ALL_LIB_PROJECTS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "libs/*/CMakeLists.txt")
FOREACH(CURRENT_LIB ${ALL_LIB_PROJECTS})
GET_FILENAME_COMPONENT(CURRENT_LIB_PATH ${CURRENT_LIB} PATH)
GET_FILENAME_COMPONENT(CURRENT_LIB_NAME ${CURRENT_LIB_PATH} NAME)
MESSAGE(STATUS " + Library: ${CURRENT_LIB_PATH} (${CURRENT_LIB_NAME})")
ADD_SUBDIRECTORY("${CURRENT_LIB_PATH}")
SET(ALL_LIB_NAMES ${ALL_LIB_NAMES} ${CURRENT_LIB_NAME})
ENDFOREACH(CURRENT_LIB ${ALL_LIB_PROJECTS})
#############################################################################
#
# Construct the bases for plugins
#
#############################################################################
SET(NSCP_DEF_PLUGIN_CPP
${NSCP_INCLUDEDIR}/nscapi/nscapi_plugin_impl.cpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_settings_helper.cpp
)
SET(NSCP_DEF_PLUGIN_HPP
${NSCP_INCLUDEDIR}/utf8.hpp
${NSCP_INCLUDEDIR}/str/format.hpp
${NSCP_INCLUDEDIR}/str/utils.hpp
${NSCP_INCLUDEDIR}/config.h
${NSCP_INCLUDEDIR}/NSCAPI.h
${NSCP_INCLUDEDIR}/nscapi/nscapi_settings_helper.hpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_settings_object.hpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_common_options.hpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_metrics_helper.hpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_plugin_impl.hpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_plugin_wrapper.hpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_program_options.hpp
)
SET(NSCP_FILTER_CPP
${NSCP_INCLUDEDIR}/parsers/filter/modern_filter.cpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_settings_object.cpp
)
SET(NSCP_FILTER_HPP
${NSCP_INCLUDEDIR}/parsers/filter/modern_filter.hpp
${NSCP_INCLUDEDIR}/parsers/filter/realtime_helper.hpp
${NSCP_INCLUDEDIR}/parsers/filter/cli_helper.hpp
${NSCP_INCLUDEDIR}/parsers/where.hpp
)
SET(NSCP_FILTER_LIB
where_filter
perfconfig_parser
)
SET(NSCP_CLIENT_CPP
${NSCP_INCLUDEDIR}/client/command_line_parser.cpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_settings_object.cpp
)
SET(NSCP_CLIENT_HPP
${NSCP_INCLUDEDIR}/client/command_line_parser.hpp
${NSCP_INCLUDEDIR}/nscapi/nscapi_settings_object.hpp
)
SET(NSCP_DEF_PLUGIN_LIB
${CMAKE_THREAD_LIBS_INIT}
${Boost_SYSTEM_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${EXTRA_LIBS}
${PROTOBUF_LIBRARY}
${ICONV_LIBRARIES}
nscp_protobuf
plugin_api
)
#############################################################################
#
# Build everything (not already built lik libraries)!
#
#############################################################################
SET(MAIN_NSCP_TARGET "nscp" "nscp_full_config")
ADD_SUBDIRECTORY("service")
ADD_SUBDIRECTORY("scripts")
ADD_SUBDIRECTORY("op5/config")
ADD_SUBDIRECTORY("op5/scripts")
ADD_SUBDIRECTORY("web")
ADD_SUBDIRECTORY("files")
LOAD_SECTIONS(ALL_MODULE_NAMES "modules/*/module.cmake" "Modules")
LOAD_SECTIONS(ALL_CLIENT_NAMES "clients/*/module.cmake" "Clients")
IF(WIN32)
LOAD_SECTIONS(ALL_TOOL_NAMES "tools/*/module.cmake" "Tools")
ENDIF(WIN32)
SET_TARGET_PROPERTIES(${MAIN_NSCP_TARGET} ${ALL_CLIENT_NAMES} ${ALL_MODULE_NAMES} ${ALL_TOOL_NAMES} PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${BUILD_TARGET_EXE_PATH}"
LIBRARY_OUTPUT_DIRECTORY "${BUILD_TARGET_LIB_PATH}"
MODULE_OUTPUT_DIRECTORY "${BUILD_TARGET_LIB_PATH}"
)
ADD_SUBDIRECTORY("docs")
IF(WIN32)
LOAD_SECTIONS(ALL_INSTALLERS_NAMES "installers/*/CMakeLists.txt" "Installers")
ENDIF(WIN32)
#############################################################################
#
# CTest setup and add testcases
#
#############################################################################
FOREACH(case "none" "xor" "des" "3des" "cast128" "xtea" "blowfish" "twofish" "rc2" "aes" "aes256" "aes192" "aes128" "serpent" "gost" "3way")
add_nscp_py_test_case(nsca test_nsca ${case})
ENDFOREACH()
#add_nscp_py_test(nrpe test_nrpe)
add_nscp_lua_test(lua_nrpe test_nrpe)
add_nscp_py_test(python test_python)
add_nscp_py_test(log_file test_log_file)
add_nscp_py_test(external_script test_external_script)
IF(WIN32)
# Disabled as is is not a unit test per see, since it requires extenal non mocked stimula
# add_nscp_py_test(eventlog test_eventlog)
add_nscp_py_test(w32_system test_w32_system)
add_nscp_py_test(w32_system test_w32_file)
add_nscp_py_test(w32_taskScheduler test_w32_schetask)
ENDIF(WIN32)
#############################################################################
#
# CPacke setup
#
#############################################################################
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "NSClient++")
set(CPACK_PACKAGE_VENDOR "MySolutions NORDIC")
set(CPACK_PACKAGE_CONTACT "Michael Medin <[email protected]>")
#SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/docs/readme.txt")
#SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt")
set(CPACK_PACKAGE_VERSION ${NSCP_FULL_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Monitoring Agent")
set(CPACK_PACKAGE_NAME "nscp")
SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_SERIES}")
SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_MINOR}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "nscp-folder")
set(CPACK_RPM_PACKAGE_DESCRIPTION "NSClient++ (nscp) aims to be a simple yet powerful and secure monitoring daemon. It was built for Naemon/Nagios/Icinga, but nothing in the daemon is Naemon/Nagios/Icinga specific and it can be used in many other scenarios where you want to receive/distribute check metrics.")
IF(WIN32)
SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
set(CPACK_PACKAGE_FILE_NAME "NSCP-${CPACK_PACKAGE_VERSION}-${VERSION_ARCH}")
SET(CPACK_GENERATOR ZIP)
ELSE()
SET(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
set(CPACK_PACKAGE_FILE_NAME "NSCP-${CPACK_PACKAGE_VERSION}-${VERSION_ARCH}")
SET(CPACK_GENERATOR ZIP)
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
ENDIF()
include(CPack)