Skip to content

Commit 670edea

Browse files
authored
Add standardized feature set properties to Pcap++ target. (#2136)
* Add standardized feature set properties to Pcap++ target. The feature set options follow the pattern `PCPP_HAS_XXX_SUPPORT`, with XXX being the target feature set. Currently if a feature set is active the cmake Pcap++ target will have a property with the corresponding name set to a truthy value and a corresponding compile time definition will be added to the compilation. This should allow consumers of the library to query the target at for features both at configure time and compile time. * Lint * Lint fixups. * Remove file support which is always true.
1 parent 27f3418 commit 670edea

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

Pcap++/CMakeLists.txt

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,67 @@ target_link_libraries(
109109
)
110110

111111
if(LIGHT_PCAPNG_ZSTD)
112-
target_compile_definitions(Pcap++ PRIVATE PCPP_PCAPNG_ZSTD_SUPPORT)
113112
target_link_libraries(Pcap++ PRIVATE light_pcapng)
114113
endif()
115114

115+
# Pcap++ Feature sets:
116+
# - PCPP_HAS_PCAPNG_ZSTD_SUPPORT - Whether Pcap++ was built with support for zstd-compressed pcapng files using the light_pcapng library
117+
# - PCPP_HAS_PCAP_LIVE_SUPPORT - Whether Pcap++ was built with support for live packet capture using libpcap
118+
# - PCPP_HAS_PCAP_REMOTE_SUPPORT - Whether Pcap++ was built with support for remote packet capture using libpcap (only supported on Windows)
119+
# - PCPP_HAS_DPDK_SUPPORT - Whether Pcap++ was built with support for DPDK-based packet capture
120+
# - PCPP_HAS_DPDK_KNI_SUPPORT - Whether Pcap++ was built with support for DPDK KNI-based packet capture
121+
# - PCPP_HAS_PF_RING_SUPPORT - Whether Pcap++ was built with support for PF_RING-based packet capture
122+
# - PCPP_HAS_XDP_SUPPORT - Whether Pcap++ was built with support for XDP-based packet capture
123+
# - PCPP_HAS_WINDIVERT_SUPPORT - Whether Pcap++ was built with support for WinDivert-based packet capture
124+
125+
if(WIN32 AND PCAPPP_USE_PCAP)
126+
set(PCPP_HAS_PCAP_REMOTE_SUPPORT ON)
127+
else()
128+
set(PCPP_HAS_PCAP_REMOTE_SUPPORT OFF)
129+
endif()
130+
131+
set_target_properties(
132+
Pcap++
133+
PROPERTIES
134+
PCPP_HAS_PCAPNG_ZSTD_SUPPORT ${LIGHT_PCAPNG_ZSTD}
135+
PCPP_HAS_PCAP_LIVE_SUPPORT ${PCAPPP_USE_PCAP}
136+
PCPP_HAS_PCAP_REMOTE_SUPPORT ${PCPP_HAS_PCAP_REMOTE_SUPPORT}
137+
PCPP_HAS_DPDK_SUPPORT ${PCAPPP_USE_DPDK}
138+
PCPP_HAS_DPDK_KNI_SUPPORT ${PCAPPP_USE_DPDK_KNI}
139+
PCPP_HAS_PF_RING_SUPPORT ${PCAPPP_USE_PF_RING}
140+
PCPP_HAS_XDP_SUPPORT ${PCAPPP_USE_XDP}
141+
PCPP_HAS_WINDIVERT_SUPPORT ${PCAPPP_USE_WINDIVERT}
142+
)
143+
144+
target_compile_definitions(
145+
Pcap++
146+
PUBLIC
147+
$<$<BOOL:${LIGHT_PCAPNG_ZSTD}>:PCPP_HAS_PCAPNG_ZSTD_SUPPORT>
148+
$<$<BOOL:${PCAPPP_USE_PCAP}>:PCPP_HAS_PCAP_LIVE_SUPPORT>
149+
$<$<BOOL:${PCPP_HAS_PCAP_REMOTE_SUPPORT}>:PCPP_HAS_PCAP_REMOTE_SUPPORT>
150+
$<$<BOOL:${PCAPPP_USE_DPDK}>:PCPP_HAS_DPDK_SUPPORT>
151+
$<$<BOOL:${PCAPPP_USE_DPDK_KNI}>:PCPP_HAS_DPDK_KNI_SUPPORT>
152+
$<$<BOOL:${PCAPPP_USE_PF_RING}>:PCPP_HAS_PF_RING_SUPPORT>
153+
$<$<BOOL:${PCAPPP_USE_XDP}>:PCPP_HAS_XDP_SUPPORT>
154+
$<$<BOOL:${PCAPPP_USE_WINDIVERT}>:PCPP_HAS_WINDIVERT_SUPPORT>
155+
)
156+
157+
# Export the feature set properties along with the target so they can be used by downstream consumers of the Pcap++ target.
158+
set_property(
159+
TARGET Pcap++
160+
APPEND
161+
PROPERTY
162+
EXPORT_PROPERTIES
163+
PCPP_HAS_PCAPNG_ZSTD_SUPPORT
164+
PCPP_HAS_PCAP_LIVE_SUPPORT
165+
PCPP_HAS_PCAP_REMOTE_SUPPORT
166+
PCPP_HAS_DPDK_SUPPORT
167+
PCPP_HAS_DPDK_KNI_SUPPORT
168+
PCPP_HAS_PF_RING_SUPPORT
169+
PCPP_HAS_XDP_SUPPORT
170+
PCPP_HAS_WINDIVERT_SUPPORT
171+
)
172+
116173
if(PCAPPP_INSTALL)
117174
install(
118175
TARGETS Pcap++

Pcap++/src/PcapFileDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace pcpp
1414
{
1515
constexpr bool checkZstdSupport()
1616
{
17-
#ifdef PCPP_PCAPNG_ZSTD_SUPPORT
17+
#ifdef PCPP_HAS_PCAPNG_ZSTD_SUPPORT
1818
return true;
1919
#else
2020
return false;

0 commit comments

Comments
 (0)