Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows Support Phase 1 #17497

Merged
merged 158 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 152 commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
921b109
abstraction layer for O/S
ktsaou Apr 23, 2024
8c45694
updates
ktsaou Apr 23, 2024
86b2a87
updates
ktsaou Apr 23, 2024
83c6b2b
updates
ktsaou Apr 23, 2024
c73abf3
temp fix for protobuf
ktsaou Apr 23, 2024
71b274b
emulated waitid()
ktsaou Apr 23, 2024
5dd09d3
fix
ktsaou Apr 23, 2024
4f39c4a
fix
ktsaou Apr 23, 2024
38a6680
compatibility layer
ktsaou Apr 23, 2024
e1509fb
fix for idtype
ktsaou Apr 23, 2024
12c46a0
fix for missing includes
ktsaou Apr 23, 2024
31d6d02
fix for missing includes
ktsaou Apr 23, 2024
3878432
added missing includes
ktsaou Apr 23, 2024
16b2566
added missing includes
ktsaou Apr 23, 2024
c214beb
added missing includes
ktsaou Apr 23, 2024
fc146fa
added missing includes
ktsaou Apr 23, 2024
5919cc8
added missing includes
ktsaou Apr 23, 2024
fd35f43
added missing includes
ktsaou Apr 23, 2024
2426ae3
UUID renamed to ND_UUID to avoid conflict with windows.h
ktsaou Apr 23, 2024
b72eae5
include libnetdata.h always - no conflicts
ktsaou Apr 23, 2024
0a410c7
simplify abstraction headers
ktsaou Apr 23, 2024
34020eb
fix missing functions
ktsaou Apr 23, 2024
f752b63
fix missing functions
ktsaou Apr 23, 2024
2663d24
fix missing functions
ktsaou Apr 23, 2024
8c6865a
fix missing functions
ktsaou Apr 23, 2024
0af37eb
rename MSYS to WINDOWS
ktsaou Apr 24, 2024
6d7c417
moved byteorder.h
ktsaou Apr 24, 2024
cdf8c56
structure for an internal windows plugin
ktsaou Apr 24, 2024
19c6345
1st windows plugin
ktsaou Apr 24, 2024
be3a481
working plugin
ktsaou Apr 24, 2024
3c8b3b3
fix printf
ktsaou Apr 24, 2024
bac22d6
Special case windows for protobuf
vkalintiris Apr 24, 2024
9a1c005
remove cygwin, compile both as windows
ktsaou Apr 24, 2024
8347a17
log windows libraries used
ktsaou Apr 24, 2024
1e767bc
fix cmake
ktsaou Apr 24, 2024
8d2f0c2
fix protobuf
ktsaou Apr 24, 2024
0c5abaa
compilation
ktsaou Apr 24, 2024
1a5c69c
updated compilation script
ktsaou Apr 24, 2024
93180cd
Merge branch 'master' into windows
ktsaou Apr 24, 2024
57e1932
added system.ram
ktsaou Apr 24, 2024
f3eb7f7
windows uptime
ktsaou Apr 24, 2024
13590a0
perflib
ktsaou Apr 28, 2024
dc4f110
working perflibdump
ktsaou Apr 29, 2024
c7f37ce
minify dump
ktsaou Apr 29, 2024
666cb48
updates to windows plugins, enable ML
ktsaou Apr 29, 2024
01f3f4f
minor compatibility fixes for cygwin and msys
ktsaou Apr 29, 2024
330fc84
perflib-dump to its own file
ktsaou Apr 29, 2024
681c316
Merge branch 'master' into windows
ktsaou Apr 29, 2024
92975b8
perflib now indexes names
ktsaou Apr 29, 2024
40f440c
Merge branch 'master' into windows
ktsaou Apr 29, 2024
ca1f998
improvements to the library; disks module WIP
ktsaou Apr 29, 2024
053ebf7
API for selectively traversing the metrics
ktsaou Apr 29, 2024
d2f8b57
first working perflib chart: disk.space
ktsaou Apr 29, 2024
87b4778
working chart on logical and physical disks
ktsaou Apr 30, 2024
dec3a22
added windows protocols
ktsaou Apr 30, 2024
9b18ab3
fix datatypes for loops
ktsaou Apr 30, 2024
aaec922
tinysleep for native smallest sleep support
ktsaou Apr 30, 2024
a9a4aed
remove libuuid dependency on windows
ktsaou May 1, 2024
df79382
fix uuid functions for macos compilation
ktsaou May 1, 2024
e095f89
fix uuid comparison function
ktsaou May 1, 2024
cfb6602
do not overwrite uuid library functions, define them as aliases to ou…
ktsaou May 1, 2024
1e8b3c4
fixed uuid_unparse functions
ktsaou May 1, 2024
f3f295e
fixed typo
ktsaou May 1, 2024
fd1858e
Merge branch 'master' into windows
ktsaou May 1, 2024
00f0d0d
added perflib processor charts
ktsaou May 1, 2024
bdb3e8c
updates for compiling without posix emulation
ktsaou May 2, 2024
4696631
gather common contexts together
ktsaou May 2, 2024
14d7bfb
fix includes on linux
ktsaou May 2, 2024
6b58244
perflib-memory
ktsaou May 2, 2024
41edb91
Merge remote-tracking branch 'origin/master' into windows
vkalintiris May 2, 2024
f7b69b8
windows mem.available
ktsaou May 2, 2024
039084c
Update variable names for protobuf
vkalintiris May 2, 2024
08e2ae2
network traffic
ktsaou May 2, 2024
389d465
add network adapters that have traffic as virtual interfaces
ktsaou May 2, 2024
fdf3bb6
add -pipe to windows compilation
ktsaou May 2, 2024
dc1e578
reset or overflow flag is now per dimension
ktsaou May 3, 2024
988682f
dpc is now counted separately
ktsaou May 3, 2024
1e36da3
verified all perflib fields are processed and no text fields are pres…
ktsaou May 3, 2024
ac47421
more common contexts
ktsaou May 3, 2024
11e0678
fix crash
ktsaou May 3, 2024
1212d20
Merge remote-tracking branch 'upstream/master' into windows
ktsaou May 3, 2024
586cbd9
do not add system.net multiple times
ktsaou May 3, 2024
83a2884
install deps update and shortcut
ktsaou May 3, 2024
7b57b3f
all threads are now joinable behind the scenes
ktsaou May 4, 2024
53d9bcc
fix threads cleanup
ktsaou May 4, 2024
ba9e214
prepare for abstracting threads API
ktsaou May 4, 2024
62112bd
netdata threads full abstraction from pthreads
ktsaou May 4, 2024
a663d8d
more threads abstraction and cleanup
ktsaou May 4, 2024
f9ffaf8
more compatibility changes
ktsaou May 5, 2024
b9c7ad7
fix compiler warnings
ktsaou May 5, 2024
c418ea2
Merge branch 'master' into windows
ktsaou May 5, 2024
799a36c
add base-devel to packages
ktsaou May 6, 2024
a709e6a
removed duplicate base-devel
ktsaou May 6, 2024
b39feae
check for strndup
ktsaou May 6, 2024
4597eec
check headers in quotes
ktsaou May 6, 2024
e0c05d3
Merge remote-tracking branch 'upstream/master' into windows
ktsaou May 6, 2024
876eaef
fix linux compilation
ktsaou May 6, 2024
2c80fd1
fix attribute gnu_printf on macos
ktsaou May 6, 2024
bd85c7f
fix for threads on macos
ktsaou May 6, 2024
99d27c9
mingw64 compatibility
ktsaou May 6, 2024
ae44bfe
enable compilation on windows clion
ktsaou May 6, 2024
ce5f243
added instructions
ktsaou May 6, 2024
1c61a6c
enable cloud
ktsaou May 7, 2024
af36f70
Merge branch 'master' into windows
ktsaou May 7, 2024
e0d3ea0
compatibility fixes
ktsaou May 7, 2024
f14f387
compatibility fixes
ktsaou May 7, 2024
a6db585
compatibility fixes
ktsaou May 7, 2024
de7f1d7
clion works on windows
ktsaou May 7, 2024
37029a4
support both MSYSTEM=MSYS and MSYSTEM=MINGW64 for configure
ktsaou May 7, 2024
5ea0866
cleanup and docs
ktsaou May 7, 2024
f065661
Merge branch 'master' into windows
ktsaou May 7, 2024
11dbe93
rename uuid_t to nd_uuid_t to avoid conflict with windows uuid_t
ktsaou May 7, 2024
693af6b
leftovers uuid_t
ktsaou May 7, 2024
ac8b7d9
do not include uuid.h on macos
ktsaou May 7, 2024
b71a03c
threads signaled cancellations
ktsaou May 7, 2024
54bd655
Merge remote-tracking branch 'upstream/master' into windows
ktsaou May 7, 2024
6e61178
do not install v0 dashboard on windows
ktsaou May 8, 2024
66e5d75
script to install openssh server on windows
ktsaou May 8, 2024
27ad889
update openssh installation script
ktsaou May 8, 2024
d453915
update openssh installation script
ktsaou May 8, 2024
6e3879e
update openssh installation script
ktsaou May 8, 2024
d8b0b0f
update openssh installation script
ktsaou May 8, 2024
64ad21e
update openssh installation script
ktsaou May 8, 2024
45fc292
update openssh installation script
ktsaou May 8, 2024
adbfcc7
update openssh installation script
ktsaou May 8, 2024
0cc41ad
update openssh installation script
ktsaou May 8, 2024
335b30a
Merge remote-tracking branch 'upstream/master' into windows
ktsaou May 8, 2024
34de627
update openssh installation script
ktsaou May 8, 2024
8833208
use cleanup variable instead of pthreads push and pop
ktsaou May 8, 2024
60c17d5
replace all calls to netdata_thread_cleanup_push() and netdata_thread…
ktsaou May 8, 2024
2a5fb49
Merge branch 'master' into windows
ktsaou May 8, 2024
08f47bb
remove left-over freez
ktsaou May 8, 2024
ea93b4d
Merge branch 'master' into windows
ktsaou May 9, 2024
c13f50c
Merge remote-tracking branch 'upstream/master' into windows
ktsaou May 9, 2024
e20c563
make sure there are no locks acquired at thread exit
ktsaou May 9, 2024
afece9d
add missing parameter
ktsaou May 9, 2024
4dc765b
stream receivers and senders are now voluntarily cancelled
ktsaou May 10, 2024
a75d6fb
plugins.d now voluntarily exits its threads
ktsaou May 10, 2024
1a87d15
Merge branch 'master' into windows
ktsaou May 10, 2024
ecdc49f
uuid_t may not be aligned to word boundaries - fix the uuid_t functio…
ktsaou May 10, 2024
388fce3
Merge branch 'master' into windows
ktsaou May 10, 2024
f29de4a
collectors evloop is now using the new threading cancellation; ml is …
ktsaou May 10, 2024
309da7e
Merge remote-tracking branch 'upstream/master' into windows
ktsaou May 10, 2024
1249ffe
eliminate threads cancellability from the code base
ktsaou May 10, 2024
abfb838
fix exit timings and logs; fix uv_threads tags
ktsaou May 10, 2024
67a3c16
use SSL_has_pending() only when it is available
ktsaou May 10, 2024
bcea2a5
Merge branch 'master' into windows
ktsaou May 11, 2024
ef10da8
do not use SSL_has_pending()
ktsaou May 11, 2024
e353e1a
dyncfg files on windows escape collon and pipe characters
ktsaou May 11, 2024
1ee789a
fix compilation on older systems
ktsaou May 11, 2024
723075b
fix compilation on older systems
ktsaou May 11, 2024
9f8713d
Merge remote-tracking branch 'upstream/master' into windows
ktsaou May 11, 2024
75418e0
Create windows installer.
vkalintiris May 15, 2024
65aa32f
fixed typo
ktsaou May 15, 2024
b3c20b1
Merge branch 'master' into windows
ktsaou May 15, 2024
ba1c7bc
code cleanup
ktsaou May 15, 2024
b1a7118
Create uninstaller
vkalintiris May 16, 2024
b17c365
Merge branch 'master' into windows
ktsaou May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
152 changes: 134 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,51 @@ endif()
# detect OS
#

set(LINUX False)
set(FREEBSD False)
set(MACOS False)
set(LINUX False)
set(FREEBSD False)
set(MACOS False)
set(WINDOWS False)
set(FOREIGN_OS False)

if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(MACOS True)
set(COMPILED_FOR_MACOS True)

find_library(IOKIT IOKit)
find_library(FOUNDATION Foundation)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
message(INFO " Compiling for MacOS... ")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
set(FREEBSD True)
set(COMPILED_FOR_FREEBSD True)
else()
message(INFO " Compiling for FreeBSD... ")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
set(LINUX True)
set(COMPILED_FOR_LINUX True)
add_definitions(-D_GNU_SOURCE)
message(INFO " Compiling for Linux... ")
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
set(WINDOWS True)
set(COMPILED_FOR_WINDOWS True)
add_definitions(-D_GNU_SOURCE)

if($ENV{CLION_IDE})
# clion needs these to find the includes
if("${CMAKE_SYSTEM_NAME}" STREQUAL "MSYS" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
if("$ENV{MSYSTEM}" STREQUAL "MSYS")
include_directories(c:/msys64/usr/include)
include_directories(c:/msys64/usr/include/w32api)
elseif("$ENV{MSYSTEM}" STREQUAL "MINGW64")
include_directories(c:/msys64/mingw64/include)
elseif("$ENV{MSYSTEM}" STREQUAL "UCRT64")
include_directories(c:/msys64/ucrt64/include)
endif()
endif()
endif()

message(INFO " Compiling for Windows (${CMAKE_SYSTEM_NAME}, MSYSTEM=$ENV{MSYSTEM})... ")
else()
set(FOREIGN_OS True)
set(COMPILED_FOR_FOREIGN_OS True)
message(WARNING " Compiling for Unknown O/S... (${CMAKE_SYSTEM_NAME})")
endif()

if(ENABLE_PLUGIN_EBPF)
Expand Down Expand Up @@ -326,6 +354,20 @@ check_include_file("sys/statvfs.h" HAVE_SYS_STATVFS_H)
check_include_file("inttypes.h" HAVE_INTTYPES_H)
check_include_file("stdint.h" HAVE_STDINT_H)
check_include_file("sys/capability.h" HAVE_SYS_CAPABILITY_H)
check_include_file("arpa/inet.h" HAVE_ARPA_INET_H)
check_include_file("netinet/tcp.h" HAVE_NETINET_TCP_H)
check_include_file("sys/ioctl.h" HAVE_SYS_IOCTL_H)
check_include_file("grp.h" HAVE_GRP_H)
check_include_file("pwd.h" HAVE_PWD_H)
check_include_file("net/if.h" HAVE_NET_IF_H)
check_include_file("poll.h" HAVE_POLL_H)
check_include_file("syslog.h" HAVE_SYSLOG_H)
check_include_file("sys/mman.h" HAVE_SYS_MMAN_H)
check_include_file("sys/resource.h" HAVE_SYS_RESOURCE_H)
check_include_file("sys/socket.h" HAVE_SYS_SOCKET_H)
check_include_file("sys/wait.h" HAVE_SYS_WAIT_H)
check_include_file("sys/un.h" HAVE_SYS_UN_H)
check_include_file("spawn.h" HAVE_SPAWN_H)

#
# check symbols
Expand All @@ -340,9 +382,15 @@ check_symbol_exists(finite "math.h" HAVE_FINITE)
check_symbol_exists(isfinite "math.h" HAVE_ISFINITE)
check_symbol_exists(dlsym "dlfcn.h" HAVE_DLSYM)

check_function_exists(pthread_getthreadid_np HAVE_PTHREAD_GETTHREADID_NP)
check_function_exists(pthread_threadid_np HAVE_PTHREAD_THREADID_NP)
check_function_exists(gettid HAVE_GETTID)
check_function_exists(waitid HAVE_WAITID)
check_function_exists(nice HAVE_NICE)
check_function_exists(recvmmsg HAVE_RECVMMSG)
check_function_exists(getpriority HAVE_GETPRIORITY)
check_function_exists(setenv HAVE_SETENV)
check_function_exists(strndup HAVE_STRNDUP)

check_function_exists(sched_getscheduler HAVE_SCHED_GETSCHEDULER)
check_function_exists(sched_setscheduler HAVE_SCHED_SETSCHEDULER)
Expand Down Expand Up @@ -624,10 +672,10 @@ set(LIBNETDATA_FILES
src/libnetdata/log/journal.h
src/libnetdata/log/log.c
src/libnetdata/log/log.h
src/libnetdata/os.c
src/libnetdata/os.h
src/libnetdata/os/os.c
src/libnetdata/os/os.h
src/libnetdata/simple_hashtable.h
src/libnetdata/byteorder.h
src/libnetdata/os/byteorder.h
src/libnetdata/onewayalloc/onewayalloc.c
src/libnetdata/onewayalloc/onewayalloc.h
src/libnetdata/popen/popen.c
Expand Down Expand Up @@ -682,6 +730,34 @@ set(LIBNETDATA_FILES
src/libnetdata/linked-lists.h
src/libnetdata/storage-point.h
src/libnetdata/bitmap64.h
src/libnetdata/os/waitid.c
src/libnetdata/os/waitid.h
src/libnetdata/os/gettid.c
src/libnetdata/os/gettid.h
src/libnetdata/os/adjtimex.c
src/libnetdata/os/adjtimex.h
src/libnetdata/os/setresuid.c
src/libnetdata/os/setresuid.h
src/libnetdata/os/setresgid.c
src/libnetdata/os/setresgid.h
src/libnetdata/os/getgrouplist.c
src/libnetdata/os/getgrouplist.h
src/libnetdata/os/get_pid_max.c
src/libnetdata/os/get_pid_max.h
src/libnetdata/os/os-freebsd-wrappers.c
src/libnetdata/os/os-freebsd-wrappers.h
src/libnetdata/os/os-macos-wrappers.c
src/libnetdata/os/os-macos-wrappers.h
src/libnetdata/os/get_system_cpus.c
src/libnetdata/os/get_system_cpus.h
src/libnetdata/os/tinysleep.c
src/libnetdata/os/tinysleep.h
src/libnetdata/os/uuid_generate.c
src/libnetdata/os/uuid_generate.h
src/libnetdata/os/setenv.c
src/libnetdata/os/setenv.h
src/libnetdata/os/strndup.c
src/libnetdata/os/strndup.h
)

if(ENABLE_PLUGIN_EBPF)
Expand Down Expand Up @@ -956,6 +1032,16 @@ else()
)
endif()

set(INTERNAL_COLLECTORS_FILES
src/collectors/common-contexts/common-contexts.h
src/collectors/common-contexts/disk.io.h
src/collectors/common-contexts/system.io.h
src/collectors/common-contexts/system.ram.h
src/collectors/common-contexts/mem.swap.h
src/collectors/common-contexts/mem.pgfaults.h
src/collectors/common-contexts/mem.available.h
)

set(PLUGINSD_PLUGIN_FILES
src/collectors/plugins.d/plugins_d.c
src/collectors/plugins.d/plugins_d.h
Expand Down Expand Up @@ -1197,6 +1283,24 @@ set(FREEBSD_PLUGIN_FILES
src/collectors/proc.plugin/zfs_common.h
)

set(WINDOWS_PLUGIN_FILES
src/collectors/windows.plugin/windows_plugin.c
src/collectors/windows.plugin/windows_plugin.h
src/collectors/windows.plugin/GetSystemUptime.c
src/collectors/windows.plugin/GetSystemRAM.c
src/collectors/windows.plugin/GetSystemCPU.c
src/collectors/windows.plugin/perflib.c
src/collectors/windows.plugin/perflib.h
src/collectors/windows.plugin/perflib-rrd.c
src/collectors/windows.plugin/perflib-rrd.h
src/collectors/windows.plugin/perflib-names.c
src/collectors/windows.plugin/perflib-dump.c
src/collectors/windows.plugin/perflib-storage.c
src/collectors/windows.plugin/perflib-processor.c
src/collectors/windows.plugin/perflib-network.c
src/collectors/windows.plugin/perflib-memory.c
)

set(PROC_PLUGIN_FILES
src/collectors/proc.plugin/ipc.c
src/collectors/proc.plugin/plugin_proc.c
Expand Down Expand Up @@ -1315,6 +1419,7 @@ if(LINUX)
${PROC_PLUGIN_FILES}
${TC_PLUGIN_FILES}
${TIMEX_PLUGIN_FILES}
${INTERNAL_COLLECTORS_FILES}
)

if(ENABLE_SENTRY)
Expand All @@ -1327,12 +1432,20 @@ elseif(MACOS)
src/daemon/static_threads_macos.c
${MACOS_PLUGIN_FILES}
${TIMEX_PLUGIN_FILES}
${INTERNAL_COLLECTORS_FILES}
)
elseif(FREEBSD)
list(APPEND NETDATA_FILES
src/daemon/static_threads_freebsd.c
${FREEBSD_PLUGIN_FILES}
${TIMEX_PLUGIN_FILES}
${INTERNAL_COLLECTORS_FILES}
)
elseif(WINDOWS)
list(APPEND NETDATA_FILES
src/daemon/static_threads_windows.c
${WINDOWS_PLUGIN_FILES}
${INTERNAL_COLLECTORS_FILES}
)
endif()

Expand Down Expand Up @@ -1518,6 +1631,7 @@ target_include_directories(libnetdata BEFORE PUBLIC ${CONFIG_H_DIR} ${CMAKE_SOUR
target_link_libraries(libnetdata PUBLIC
"$<$<NOT:$<BOOL:${HAVE_BUILTIN_ATOMICS}>>:atomic>"
"$<$<OR:$<BOOL:${LINUX}>,$<BOOL:${FREEBSD}>>:pthread;rt>"
"$<$<BOOL:${WINDOWS}>:kernel32;advapi32;winmm;rpcrt4>"
"$<$<BOOL:${LINK_LIBM}>:m>"
"${SYSTEMD_LDFLAGS}")

Expand Down Expand Up @@ -1578,7 +1692,7 @@ if(LIBBROTLI_FOUND)
endif()

# uuid
if(MACOS)
if(MACOS OR WINDOWS)
# UUID functionality is part of the system libraries here, so no extra
# stuff needed.
else()
Expand Down Expand Up @@ -1879,9 +1993,9 @@ endif()

if(ENABLE_PLUGIN_CUPS)
pkg_check_modules(CUPS libcups)
if(NOT CUPS_LIBRARIES)
if(NOT CUPS_FOUND)
pkg_check_modules(CUPS cups)
if(NOT CUPS_LIBRARIES)
if(NOT CUPS_FOUND)
find_program(CUPS_CONFIG cups-config)
if(CUPS_CONFIG)
execute_process(COMMAND ${CUPS_CONFIG} --api-version OUTPUT_VARIABLE CUPS_API_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
Expand Down Expand Up @@ -2918,10 +3032,12 @@ install(FILES
COMPONENT netdata
DESTINATION ${WEB_DEST}/.well-known/dnt)

# v0 dashboard
install(FILES
src/web/gui/v0/index.html
COMPONENT netdata
DESTINATION ${WEB_DEST}/v0)
if(NOT WINDOWS)
# v0 dashboard
install(FILES
src/web/gui/v0/index.html
COMPONENT netdata
DESTINATION ${WEB_DEST}/v0)
endif()

include(Packaging)
97 changes: 55 additions & 42 deletions packaging/cmake/Modules/NetdataProtobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,54 +56,67 @@ endfunction()

# Handle detection of Protobuf
macro(netdata_detect_protobuf)
if(NOT ENABLE_BUNDLED_PROTOBUF)
if (NOT BUILD_SHARED_LIBS)
set(Protobuf_USE_STATIC_LIBS On)
if(COMPILED_FOR_WINDOWS)
set(PROTOBUF_PROTOC_EXECUTABLE "$ENV{PROTOBUF_PROTOC_EXECUTABLE}")
if(NOT PROTOBUF_PROTOC_EXECUTABLE)
set(PROTOBUF_PROTOC_EXECUTABLE "/bin/protoc")
endif()

# The FindProtobuf CMake module shipped by upstream CMake is
# broken for Protobuf version 22.0 and newer because it does
# not correctly pull in the new Abseil dependencies. Protobuf
# itself sometimes ships a CMake Package Configuration module
# that _does_ work correctly, so use that in preference to the
# Find module shipped with CMake.
#
# The code below works by first attempting to use find_package
# in config mode, and then checking for the existence of the
# target we actually use that gets defined by the protobuf
# CMake Package Configuration Module to determine if that
# worked. A bit of extra logic is required in the case of the
# config mode working, because some systems ship compatibility
# logic for the old FindProtobuf module while others do not.
#
# Upstream bug reference: https://gitlab.kitware.com/cmake/cmake/-/issues/24321
find_package(Protobuf CONFIG)

if(NOT TARGET protobuf::libprotobuf)
message(STATUS "Could not find Protobuf using Config mode, falling back to Module mode")
find_package(Protobuf REQUIRED)
set(PROTOBUF_CFLAGS_OTHER "")
set(PROTOBUF_INCLUDE_DIRS "")
set(PROTOBUF_LIBRARIES "-lprotobuf")

set(ENABLE_PROTOBUF True)
set(HAVE_PROTOBUF True)
else()
if(NOT ENABLE_BUNDLED_PROTOBUF)
if (NOT BUILD_SHARED_LIBS)
set(Protobuf_USE_STATIC_LIBS On)
endif()

# The FindProtobuf CMake module shipped by upstream CMake is
# broken for Protobuf version 22.0 and newer because it does
# not correctly pull in the new Abseil dependencies. Protobuf
# itself sometimes ships a CMake Package Configuration module
# that _does_ work correctly, so use that in preference to the
# Find module shipped with CMake.
#
# The code below works by first attempting to use find_package
# in config mode, and then checking for the existence of the
# target we actually use that gets defined by the protobuf
# CMake Package Configuration Module to determine if that
# worked. A bit of extra logic is required in the case of the
# config mode working, because some systems ship compatibility
# logic for the old FindProtobuf module while others do not.
#
# Upstream bug reference: https://gitlab.kitware.com/cmake/cmake/-/issues/24321
find_package(Protobuf CONFIG)

if(NOT TARGET protobuf::libprotobuf)
message(STATUS "Could not find Protobuf using Config mode, falling back to Module mode")
find_package(Protobuf REQUIRED)
endif()
endif()
endif()

if(TARGET protobuf::libprotobuf)
if(NOT Protobuf_PROTOC_EXECUTABLE AND TARGET protobuf::protoc)
set(Protobuf_PROTOC_EXECUTABLE protobuf::protoc)
if(TARGET protobuf::libprotobuf)
if(NOT Protobuf_PROTOC_EXECUTABLE AND TARGET protobuf::protoc)
set(Protobuf_PROTOC_EXECUTABLE protobuf::protoc)
endif()

# It is technically possible that this may still not
# be set by this point, so we need to check it and
# fail noisily if it isn't because the build won't
# work without it.
if(NOT Protobuf_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Could not determine the location of the protobuf compiler for the detected version of protobuf.")
endif()

set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
set(PROTOBUF_LIBRARIES protobuf::libprotobuf)
endif()

# It is technically possible that this may still not
# be set by this point, so we need to check it and
# fail noisily if it isn't because the build won't
# work without it.
if(NOT Protobuf_PROTOC_EXECUTABLE)
message(FATAL_ERROR "Could not determine the location of the protobuf compiler for the detected version of protobuf.")
endif()

set(PROTOBUF_PROTOC_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
set(PROTOBUF_LIBRARIES protobuf::libprotobuf)
set(ENABLE_PROTOBUF True)
set(HAVE_PROTOBUF True)
endif()

set(ENABLE_PROTOBUF True)
set(HAVE_PROTOBUF True)
endmacro()

# Helper function to compile protocol definitions into C++ code.
Expand Down