[wpinet] Add option to use directly linked Avahi from cmake (#8469)

This commit is contained in:
Thad House
2025-12-12 19:39:26 -08:00
committed by GitHub
parent cbe447aad7
commit d830c41063
5 changed files with 45 additions and 2 deletions

View File

@@ -68,4 +68,7 @@ Checks:
modernize-use-override,
modernize-use-using,
readability-braces-around-statements'
CheckOptions:
- key: modernize-use-using.IgnoreExternC
value: 'true'
FormatStyle: file

View File

@@ -96,6 +96,7 @@ option(WITH_BENCHMARK "Build the benchmark project" ON)
option(USE_SYSTEM_FMTLIB "Use system fmtlib" OFF)
option(USE_SYSTEM_LIBUV "Use system libuv" OFF)
option(USE_SYSTEM_EIGEN "Use system eigen" OFF)
option(USE_LINKED_AVAHI "Use directly linked Avahi instead of loading at runtime" OFF)
# Options for location of OpenCV Java.
set(OPENCV_JAVA_INSTALL_DIR "" CACHE PATH "Location to search for the OpenCV jar file")

View File

@@ -128,6 +128,21 @@ target_compile_features(wpinet PUBLIC cxx_std_20)
wpilib_target_warnings(wpinet)
target_link_libraries(wpinet PUBLIC wpiutil)
if(USE_LINKED_AVAHI)
find_library(AVAHI_COMMON REQUIRED NAMES avahi-common)
if(AVAHI_COMMON)
message(STATUS "Found avahi common: ${AVAHI_COMMON}")
endif()
find_library(AVAHI_CLIENT REQUIRED NAMES avahi-client)
if(AVAHI_CLIENT)
message(STATUS "Found avahi client: ${AVAHI_CLIENT}")
endif()
target_link_libraries(wpinet PUBLIC ${AVAHI_COMMON} ${AVAHI_CLIENT})
target_compile_definitions(wpinet PRIVATE DIRECT_LINK_AVAHI)
endif()
if(NOT USE_SYSTEM_LIBUV)
target_sources(wpinet PRIVATE ${uv_native_src})
install(

View File

@@ -11,6 +11,9 @@
using namespace wpi::net;
#ifdef DIRECT_LINK_AVAHI
#define AvahiFunctionLoad(snake_name) snake_name = &::avahi_##snake_name
#else
#define AvahiFunctionLoad(snake_name) \
do { \
snake_name = \
@@ -19,6 +22,7 @@ using namespace wpi::net;
return; \
} \
} while (false)
#endif
AvahiFunctionTable::AvahiFunctionTable() {
void* lib = dlopen("libavahi-common.so.3", RTLD_LAZY);

View File

@@ -8,6 +8,20 @@
#include <memory>
#ifdef DIRECT_LINK_AVAHI
#include "avahi-client/client.h"
#include "avahi-client/lookup.h"
#include "avahi-client/publish.h"
#include "avahi-common/address.h"
#include "avahi-common/alternative.h"
#include "avahi-common/domain.h"
#include "avahi-common/error.h"
#include "avahi-common/malloc.h"
#include "avahi-common/strlst.h"
#include "avahi-common/thread-watch.h"
#else
/***
This file is part of avahi.
avahi is free software; you can redistribute it and/or modify it
@@ -24,6 +38,8 @@
USA.
***/
extern "C" {
typedef struct AvahiPoll AvahiPoll;
typedef enum {
@@ -223,6 +239,10 @@ enum {
AVAHI_ERR_MAX = -54
};
} // extern "C"
#endif
namespace wpi::net {
class AvahiFunctionTable {
public:
@@ -235,8 +255,8 @@ class AvahiFunctionTable {
AvahiFunction(threaded_poll_get, const AvahiPoll*, (AvahiThreadedPoll*));
AvahiFunction(threaded_poll_start, int, (AvahiThreadedPoll*));
AvahiFunction(threaded_poll_stop, int, (AvahiThreadedPoll*));
AvahiFunction(threaded_poll_lock, int, (AvahiThreadedPoll*));
AvahiFunction(threaded_poll_unlock, int, (AvahiThreadedPoll*));
AvahiFunction(threaded_poll_lock, void, (AvahiThreadedPoll*));
AvahiFunction(threaded_poll_unlock, void, (AvahiThreadedPoll*));
AvahiFunction(client_new, AvahiClient*,
(const AvahiPoll* poll_api, AvahiClientFlags flags,