Make CMake options for platform-dependent plugins depend on being build for a supported platform. (#17517)
* Move OS detection above option definitions. This will allow us to use the target platform to decide what options to actually show to users. * Make plugin options depend on the platforms that we support them on. This way users will only be able to enable plugins that will actually work on their system.
Austin S. Hemmelgarn committed
May 21, 2024 at 07:08 UTC
1b61aa9d215613c4c284fbfd5ddfb323d9fe4beb
1 file changed
+70
-71
CMakeLists.txt
+70
-71
@@ -135,6 +135,57 @@ endif()
135
set(CONFIG_H_DIR ${CMAKE_BINARY_DIR})
136
set(CONFIG_H ${CONFIG_H_DIR}/config.h)
137
138
+#
139
+# detect OS
140
+#
141
+
142
+set(LINUX False)
143
+set(FREEBSD False)
144
+set(MACOS False)
145
+set(WINDOWS False)
146
+set(FOREIGN_OS False)
147
+
148
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
149
+ set(MACOS True)
150
+ set(COMPILED_FOR_MACOS True)
151
+ find_library(IOKIT IOKit)
152
+ find_library(FOUNDATION Foundation)
153
+ message(INFO " Compiling for MacOS... ")
154
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
155
+ set(FREEBSD True)
156
+ set(COMPILED_FOR_FREEBSD True)
157
+ message(INFO " Compiling for FreeBSD... ")
158
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
159
+ set(LINUX True)
160
+ set(COMPILED_FOR_LINUX True)
161
+ add_definitions(-D_GNU_SOURCE)
162
+ message(INFO " Compiling for Linux... ")
163
+elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
164
+ set(WINDOWS True)
165
+ set(COMPILED_FOR_WINDOWS True)
166
+ add_definitions(-D_GNU_SOURCE)
167
+
168
+ if($ENV{CLION_IDE})
169
+ # clion needs these to find the includes
170
+ if("${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
171
+ if("$ENV{MSYSTEM}" STREQUAL "MSYS")
172
+ include_directories(c:/msys64/usr/include)
173
+ include_directories(c:/msys64/usr/include/w32api)
174
+ elseif("$ENV{MSYSTEM}" STREQUAL "MINGW64")
175
+ include_directories(c:/msys64/mingw64/include)
176
+ elseif("$ENV{MSYSTEM}" STREQUAL "UCRT64")
177
+ include_directories(c:/msys64/ucrt64/include)
178
+ endif()
179
+ endif()
180
+ endif()
181
+
182
+ message(INFO " Compiling for Windows (${CMAKE_SYSTEM_NAME}, MSYSTEM=$ENV{MSYSTEM})... ")
183
+else()
184
+ set(FOREIGN_OS True)
185
+ set(COMPILED_FOR_FOREIGN_OS True)
186
+ message(WARNING " Compiling for Unknown O/S... (${CMAKE_SYSTEM_NAME})")
187
+endif()
188
+
189
# This is intended to make life easier for developers who are working on one
190
# specific feature.
191
option(DEFAULT_FEATURE_STATE "Specify the default state for most optional features" True)
@@ -148,22 +199,25 @@ option(ENABLE_DBENGINE "Enable dbengine metrics storage" True)
199
200
# Data collection plugins
201
option(ENABLE_PLUGIN_APPS "Enable per-process resource usage monitoring" ${DEFAULT_FEATURE_STATE})
151
-option(ENABLE_PLUGIN_CGROUP_NETWORK "Enable Linux CGroup network usage monitoring" ${DEFAULT_FEATURE_STATE})
152
-option(ENABLE_PLUGIN_CUPS "Enable CUPS monitoring" ${DEFAULT_FEATURE_STATE})
153
-option(ENABLE_PLUGIN_DEBUGFS "Enable Linux DebugFS metric collection" ${DEFAULT_FEATURE_STATE})
154
-option(ENABLE_PLUGIN_EBPF "Enable Linux eBPF metric collection" ${DEFAULT_FEATURE_STATE})
155
-cmake_dependent_option(ENABLE_LEGACY_EBPF_PROGRAMS "Enable eBPF programs for kernels without BTF support" True ENABLE_PLUGIN_EBPF False)
156
-mark_as_advanced(ENABLE_LEGACY_EBPF_PROGRAMS)
157
-option(ENABLE_PLUGIN_FREEIPMI "Enable IPMI monitoring" ${DEFAULT_FEATURE_STATE})
202
option(ENABLE_PLUGIN_GO "Enable metric collectors written in Go" ${DEFAULT_FEATURE_STATE})
159
-option(ENABLE_PLUGIN_LOCAL_LISTENERS "Enable local listening socket tracking (including service auto-discovery support)" ${DEFAULT_FEATURE_STATE})
160
-option(ENABLE_PLUGIN_LOGS_MANAGEMENT "Enable log collection and monitoring based on Fluent Bit" ${DEFAULT_FEATURE_STATE})
161
-option(ENABLE_PLUGIN_NETWORK_VIEWER "Enable network viewer functionality" ${DEFAULT_FEATURE_STATE})
162
-option(ENABLE_PLUGIN_NFACCT "Enable Linux NFACCT metric collection" ${DEFAULT_FEATURE_STATE})
163
-option(ENABLE_PLUGIN_PERF "Enable Linux performance counter monitoring" ${DEFAULT_FEATURE_STATE})
164
-option(ENABLE_PLUGIN_SLABINFO "Enable Linux kernel SLAB allocator monitoring" ${DEFAULT_FEATURE_STATE})
165
-option(ENABLE_PLUGIN_SYSTEMD_JOURNAL "Enable systemd journal log collection" ${DEFAULT_FEATURE_STATE})
166
-option(ENABLE_PLUGIN_XENSTAT "Enable Xen domain monitoring" ${DEFAULT_FEATURE_STATE})
203
+
204
+cmake_dependent_option(ENABLE_PLUGIN_CUPS "Enable CUPS monitoring" ${DEFAULT_FEATURE_STATE} "LINUX OR FREEBSD OR MACOS" False)
205
+
206
+cmake_dependent_option(ENABLE_PLUGIN_FREEIPMI "Enable IPMI monitoring" ${DEFAULT_FEATURE_STATE} "LINUX OR FREEBSD" False)
207
+
208
+cmake_dependent_option(ENABLE_PLUGIN_CGROUP_NETWORK "Enable Linux CGroup network usage monitoring" ${DEFAULT_FEATURE_STATE} "LINUX" False)
209
+cmake_dependent_option(ENABLE_PLUGIN_DEBUGFS "Enable Linux DebugFS metric collection" ${DEFAULT_FEATURE_STATE} "LINUX" False)
210
+cmake_dependent_option(ENABLE_PLUGIN_EBPF "Enable Linux eBPF metric collection" ${DEFAULT_FEATURE_STATE} "LINUX" False)
211
+cmake_dependent_option(ENABLE_LEGACY_EBPF_PROGRAMS "Enable eBPF programs for kernels without BTF support" True "ENABLE_PLUGIN_EBPF" False)
212
+mark_as_advanced(ENABLE_LEGACY_EBPF_PROGRAMS)
213
+cmake_dependent_option(ENABLE_PLUGIN_LOCAL_LISTENERS "Enable local listening socket tracking (including service auto-discovery support)" ${DEFAULT_FEATURE_STATE} "LINUX" False)
214
+cmake_dependent_option(ENABLE_PLUGIN_LOGS_MANAGEMENT "Enable log collection and monitoring based on Fluent Bit" ${DEFAULT_FEATURE_STATE} "LINUX" False)
215
+cmake_dependent_option(ENABLE_PLUGIN_NETWORK_VIEWER "Enable network viewer functionality" ${DEFAULT_FEATURE_STATE} "LINUX" False)
216
+cmake_dependent_option(ENABLE_PLUGIN_NFACCT "Enable Linux NFACCT metric collection" ${DEFAULT_FEATURE_STATE} "LINUX" False)
217
+cmake_dependent_option(ENABLE_PLUGIN_PERF "Enable Linux performance counter monitoring" ${DEFAULT_FEATURE_STATE} "LINUX" False)
218
+cmake_dependent_option(ENABLE_PLUGIN_SLABINFO "Enable Linux kernel SLAB allocator monitoring" ${DEFAULT_FEATURE_STATE} "LINUX" False)
219
+cmake_dependent_option(ENABLE_PLUGIN_SYSTEMD_JOURNAL "Enable systemd journal log collection" ${DEFAULT_FEATURE_STATE} "LINUX" False)
220
+cmake_dependent_option(ENABLE_PLUGIN_XENSTAT "Enable Xen domain monitoring" ${DEFAULT_FEATURE_STATE} "LINUX" False)
221
222
# Metrics exporters
223
option(ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE "Enable exporting to Prometheus via remote write API" ${DEFAULT_FEATURE_STATE})
@@ -175,7 +229,7 @@ option(ENABLE_BUNDLED_YAML "Force use of a vendored copy of libyaml" False)
229
option(ENABLE_BUNDLED_PROTOBUF "Use a vendored copy of protobuf" False)
230
231
# Optional test code
178
-cmake_dependent_option(ENABLE_LOGS_MANAGEMENT_TESTS "Enable test code for logs-management plugin." True "NOT ENABLE_PLUGIN_LOGS_MANAGEMENT" False)
232
+cmake_dependent_option(ENABLE_LOGS_MANAGEMENT_TESTS "Enable test code for logs-management plugin." True "ENABLE_PLUGIN_LOGS_MANAGEMENT" False)
233
mark_as_advanced(ENABLE_LOGS_MANAGEMENT_TESTS)
234
235
# Experimental features
@@ -235,65 +289,10 @@ if(NEED_PROTOBUF)
289
endif()
290
endif()
291
238
-#
239
-# detect OS
240
-#
241
-
242
-set(LINUX False)
243
-set(FREEBSD False)
244
-set(MACOS False)
245
-set(WINDOWS False)
246
-set(FOREIGN_OS False)
247
-
248
-if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
249
- set(MACOS True)
250
- set(COMPILED_FOR_MACOS True)
251
- find_library(IOKIT IOKit)
252
- find_library(FOUNDATION Foundation)
253
- message(INFO " Compiling for MacOS... ")
254
-elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
255
- set(FREEBSD True)
256
- set(COMPILED_FOR_FREEBSD True)
257
- message(INFO " Compiling for FreeBSD... ")
258
-elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
259
- set(LINUX True)
260
- set(COMPILED_FOR_LINUX True)
261
- add_definitions(-D_GNU_SOURCE)
262
- message(INFO " Compiling for Linux... ")
263
-elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
264
- set(WINDOWS True)
265
- set(COMPILED_FOR_WINDOWS True)
266
- add_definitions(-D_GNU_SOURCE)
267
-
268
- if($ENV{CLION_IDE})
269
- # clion needs these to find the includes
270
- if("${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
271
- if("$ENV{MSYSTEM}" STREQUAL "MSYS")
272
- include_directories(c:/msys64/usr/include)
273
- include_directories(c:/msys64/usr/include/w32api)
274
- elseif("$ENV{MSYSTEM}" STREQUAL "MINGW64")
275
- include_directories(c:/msys64/mingw64/include)
276
- elseif("$ENV{MSYSTEM}" STREQUAL "UCRT64")
277
- include_directories(c:/msys64/ucrt64/include)
278
- endif()
279
- endif()
280
- endif()
281
-
282
- message(INFO " Compiling for Windows (${CMAKE_SYSTEM_NAME}, MSYSTEM=$ENV{MSYSTEM})... ")
283
-else()
284
- set(FOREIGN_OS True)
285
- set(COMPILED_FOR_FOREIGN_OS True)
286
- message(WARNING " Compiling for Unknown O/S... (${CMAKE_SYSTEM_NAME})")
287
-endif()
288
-
292
if(ENABLE_PLUGIN_EBPF)
293
include(NetdataLibBPF)
294
include(NetdataEBPFCORE)
295
293
- if(NOT LINUX)
294
- message(FATAL_ERROR "The eBPF plugin is not supported on non-Linux systems")
295
- endif()
296
-
296
netdata_bundle_libbpf()
297
netdata_fetch_ebpf_co_re()
298
endif()