-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeListsLinux.txt
203 lines (168 loc) · 6.95 KB
/
CMakeListsLinux.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
#
# Copyright 2009-2023 Centreon
#
# 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
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#
# For more information : [email protected]
#
#
# Global settings.
#
option(LEGACY_ENGINE
"Enable this option to compile the old Engine version." OFF)
option(WITH_ASAN
"Add the libasan to check memory leaks and other memory issues." OFF)
option(WITH_TSAN
"Add the libtsan to check threads and other multithreading issues." OFF)
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID
STREQUAL "Clang")
message(
FATAL_ERROR "You can build broker with g++ or clang++. CMake will exit.")
endif()
option(WITH_MALLOC_TRACE "compile centreon-malloc-trace library." OFF)
option(DEBUG_ROBOT OFF)
if(LEGACY_ENGINE)
message(STATUS "Collect compilation with the legacy Engine configuration library.")
add_definitions(-DLEGACY_CONF)
else()
message(STATUS "Collect compilation with the Protobuf Engine configuration library.")
endif()
if(WITH_TSAN)
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread")
set(CMAKE_LINKER_FLAGS_DEBUG
"${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=thread")
endif()
if(WITH_ASAN)
set(CMAKE_BUILD_TYPE Debug)
if(WITH_CLANG)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address")
set(CMAKE_LINKER_FLAGS_DEBUG
"${CMAKE_LINKER_FLAGS_DEBUG} -fsanitize=address")
else()
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set(CMAKE_LINKER_FLAGS_DEBUG
"${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address"
)
endif()
endif()
set(ALLOW_DUPLICATE_EXECUTABLE TRUE)
set(BUILD_ARGS "-w" "dupbuild=warn")
# Version.
add_definitions(-DCENTREON_CONNECTOR_VERSION=\"${COLLECT_VERSION}\")
if (DEBUG_ROBOT)
add_definitions(-DDEBUG_ROBOT)
endif()
# ########### CONSTANTS ###########
set(USER_BROKER centreon-broker)
set(USER_ENGINE centreon-engine)
find_package(fmt CONFIG REQUIRED)
find_package(spdlog CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
find_package(Protobuf REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(GTest CONFIG REQUIRED)
find_package(CURL REQUIRED)
find_package(Boost REQUIRED COMPONENTS url)
find_package(ryml CONFIG REQUIRED)
add_definitions("-DSPDLOG_FMT_EXTERNAL")
add_definitions("-DCOLLECT_MAJOR=${COLLECT_MAJOR}")
add_definitions("-DCOLLECT_MINOR=${COLLECT_MINOR}")
add_definitions("-DCOLLECT_PATCH=${COLLECT_PATCH}")
include(FindPkgConfig)
pkg_check_modules(MARIADB REQUIRED libmariadb)
pkg_check_modules(LIBSSH2 REQUIRED libssh2)
# There is a bug with grpc. It is not put in the triplet directory. So we have
# to search for its plugin.
file(GLOB_RECURSE GRPC_CPP_PLUGIN_EXE
RELATIVE ${CMAKE_BINARY_DIR} grpc_cpp_plugin)
find_program(GRPC_CPP_PLUGIN
NAMES ${GRPC_CPP_PLUGIN_EXE}
PATHS ${CMAKE_BINARY_DIR}
REQUIRED
NO_DEFAULT_PATH)
set(PROTOBUF_LIB_DIR ${Protobuf_DIR}/../../lib)
set(OTLP_LIB_DIR ${opentelemetry-cpp_DIR}/../../lib)
set(VCPKG_INCLUDE_DIR ${Protobuf_INCLUDE_DIR})
include(GNUInstallDirs)
#import opentelemetry-proto
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto
${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto
${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto
${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto
COMMENT "get opentelemetry proto files from git repository"
COMMAND /bin/rm -rf ${CMAKE_SOURCE_DIR}/opentelemetry-proto
COMMAND git ARGS clone --depth=1 --single-branch https://github.com/open-telemetry/opentelemetry-proto.git ${CMAKE_SOURCE_DIR}/opentelemetry-proto
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
add_custom_target(opentelemetry-proto-files DEPENDS ${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/collector/metrics/v1/metrics_service.proto
${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/metrics/v1/metrics.proto
${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/common/v1/common.proto
${CMAKE_SOURCE_DIR}/opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto
)
# var directories.
set(BROKER_VAR_LOG_DIR
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-broker")
set(BROKER_VAR_LIB_DIR
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/centreon-broker")
set(ENGINE_VAR_LOG_DIR
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-engine")
set(ENGINE_VAR_LOG_ARCHIVE_DIR
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/log/centreon-engine/archives")
set(ENGINE_VAR_LIB_DIR
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/centreon-engine")
add_definitions(-DDEFAULT_COMMAND_FILE="${ENGINE_VAR_LIB_DIR}/rw/centengine.cmd"
-DDEFAULT_DEBUG_FILE="${ENGINE_VAR_LOG_DIR}/centengine.debug"
-DDEFAULT_LOG_FILE="${ENGINE_VAR_LOG_DIR}/centengine.log"
-DDEFAULT_RETENTION_FILE="${ENGINE_VAR_LOG_DIR}/retention.dat"
-DDEFAULT_STATUS_FILE="${ENGINE_VAR_LOG_DIR}/status.dat")
set(CMAKE_INSTALL_PREFIX "/usr")
option(WITH_TESTING "Build unit tests." OFF)
option(WITH_CONF "Install configuration files." ON)
# Code coverage on unit tests
option(WITH_COVERAGE "Add code coverage on unit tests." OFF)
if(WITH_TESTING AND WITH_COVERAGE)
set(CMAKE_BUILD_TYPE "Debug")
include(cmake/CodeCoverage.cmake)
append_coverage_compiler_flags()
endif()
set(protobuf_MODULE_COMPATIBLE True)
include_directories(${CMAKE_SOURCE_DIR}
${VCPKG_INCLUDE_DIR}
fmt::fmt
spdlog::spdlog
${CMAKE_SOURCE_DIR}/clib/inc
${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(clib)
add_subdirectory(common)
add_subdirectory(broker)
add_subdirectory(bbdo)
add_subdirectory(engine)
add_subdirectory(connectors)
add_subdirectory(ccc)
add_subdirectory(agent)
if (WITH_MALLOC_TRACE)
add_subdirectory(malloc-trace)
endif()
add_custom_target(test-broker COMMAND tests/ut_broker)
add_custom_target(test-engine COMMAND tests/ut_engine)
add_custom_target(test-clib COMMAND tests/ut_clib)
add_custom_target(test-connector COMMAND tests/ut_connector)
add_custom_target(test-common COMMAND tests/ut_common)
add_custom_target(test-agent COMMAND tests/ut_agent)
add_custom_target(test DEPENDS test-broker test-engine test-clib test-connector
test-common test-agent)
add_custom_target(test-coverage DEPENDS broker-test-coverage
engine-test-coverage clib-test-coverage)