Skip to content

Commit 24c01e7

Browse files
Updated Pcap++ and Fixed installation (#21)
- Pcap++ is now built from source when using built-in dependencies - udpcap now links against PcapPlusPlus::Pcap++ (it was pcapplusplus::pcapplusplus before) in order to be compatible with the officially introduced names. - Added UDPCAP_INSTALL cmake option to turn off installation - Prevent installing gtest libraries when using built-in dependencies - udpcap now explicitely links against delayimp, so ninja also links that lib - Updated GH Action to VS 2019 Toolchain - Static GH Action artifacts now include pcap++ libs
1 parent f270bce commit 24c01e7

File tree

11 files changed

+153
-229
lines changed

11 files changed

+153
-229
lines changed

.github/workflows/build-windows.yml

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ env:
99
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
1010
INSTALL_PREFIX: _install
1111
PROJECT_NAME: udpcap
12-
VS_TOOLSET: v140
13-
VS_NAME: vs2015
12+
VS_TOOLSET: v142
13+
VS_NAME: vs2019
1414

1515
jobs:
1616
build-windows:
@@ -19,6 +19,7 @@ jobs:
1919
matrix:
2020
library_type: [static, shared]
2121
build_arch: [x64, win32]
22+
fail-fast: false
2223

2324
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
2425
# You can convert this to a matrix build if you need cross-platform coverage.
@@ -29,15 +30,21 @@ jobs:
2930

3031
- name: Set Variables
3132
run: |
33+
# Always set build_shared_libs to OFF, as we want static dependencies.
34+
# The udpcap_library_type variable will be used to determine if we are
35+
# building a static or shared udpcap library.
36+
37+
echo "build_shared_libs=OFF" >> "$Env:GITHUB_ENV"
38+
3239
if ( '${{ matrix.library_type }}' -eq 'static' )
3340
{
34-
echo "build_shared_libs=OFF" >> "$Env:GITHUB_ENV"
35-
echo "package_postfix=static" >> "$Env:GITHUB_ENV"
41+
echo "udpcap_library_type=STATIC" >> "$Env:GITHUB_ENV"
42+
echo "package_postfix=static" >> "$Env:GITHUB_ENV"
3643
}
3744
else
3845
{
39-
echo "build_shared_libs=ON" >> "$Env:GITHUB_ENV"
40-
echo "package_postfix=shared" >> "$Env:GITHUB_ENV"
46+
echo "udpcap_library_type=SHARED" >> "$Env:GITHUB_ENV"
47+
echo "package_postfix=shared" >> "$Env:GITHUB_ENV"
4148
}
4249
4350
- name: Checkout
@@ -53,26 +60,48 @@ jobs:
5360
- name: Configure CMake
5461
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
5562
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
56-
shell: cmd
5763
run: |
58-
cmake -B ${{github.workspace}}/_build ^
59-
-G "Visual Studio 16 2019" ^
60-
-A ${{ matrix.build_arch }} ^
61-
-T ${{ env.VS_TOOLSET }} ^
62-
-DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} ^
64+
cmake -B ${{github.workspace}}/_build `
65+
-G "Visual Studio 16 2019" `
66+
-A ${{ matrix.build_arch }} `
67+
-T ${{ env.VS_TOOLSET }} `
68+
-DCMAKE_INSTALL_PREFIX=${{env.INSTALL_PREFIX}} `
69+
-DUDPCAP_LIBRARY_TYPE=${{ env.udpcap_library_type }} `
6370
-DBUILD_SHARED_LIBS=${{ env.build_shared_libs }}
6471
6572
- name: Build (Release)
66-
shell: cmd
6773
run: |
68-
cmake --build ${{github.workspace}}/_build --config Release --parallel
69-
cmake --build ${{github.workspace}}/_build --config Release --target INSTALL
74+
cmake --build ${{github.workspace}}/_build --config Release --parallel
75+
76+
# We only need to install everyhing (i.e. Pcap++ libs) for the static build.
77+
# For the shared build, we only need to install the udpcap library and headers.
78+
79+
if ( '${{ matrix.library_type }}' -eq 'static' )
80+
{
81+
cmake --install ${{github.workspace}}/_build --config Release
82+
}
83+
else
84+
{
85+
cmake --install ${{github.workspace}}/_build --config Release --component udpcap_dev
86+
cmake --install ${{github.workspace}}/_build --config Release --component udpcap_runtime
87+
}
7088
7189
- name: Build (Debug)
72-
shell: cmd
7390
run: |
74-
cmake --build ${{github.workspace}}/_build --config Debug --parallel
75-
cmake --build ${{github.workspace}}/_build --config Debug --target INSTALL
91+
cmake --build ${{github.workspace}}/_build --config Debug --parallel
92+
93+
# We only need to install everyhing (i.e. Pcap++ libs) for the static build.
94+
# For the shared build, we only need to install the udpcap library and headers.
95+
96+
if ( '${{ matrix.library_type }}' -eq 'static' )
97+
{
98+
cmake --install ${{github.workspace}}/_build --config Debug
99+
}
100+
else
101+
{
102+
cmake --install ${{github.workspace}}/_build --config Debug --component udpcap_dev
103+
cmake --install ${{github.workspace}}/_build --config Debug --component udpcap_runtime
104+
}
76105
77106
- name: Read Project Version from CMakeCache
78107
run: |
@@ -91,15 +120,13 @@ jobs:
91120
############################################
92121

93122
- name: CMake integration test
94-
shell: cmd
95123
run: |
96-
cmake -B ${{github.workspace}}/samples/integration_test/_build ^
97-
-A ${{ matrix.build_arch }} ^
124+
cmake -B ${{github.workspace}}/samples/integration_test/_build `
125+
-A ${{ matrix.build_arch }} `
98126
-DCMAKE_PREFIX_PATH=${{github.workspace}}/${{env.INSTALL_PREFIX}}
99127
working-directory: ${{ github.workspace }}/samples/integration_test
100128

101129
- name: Compile integration test (Release)
102-
shell: cmd
103130
run: cmake --build ${{github.workspace}}/samples/integration_test/_build --config Release
104131
working-directory: ${{ github.workspace }}/samples/integration_test
105132

@@ -113,7 +140,6 @@ jobs:
113140
working-directory: ${{ github.workspace }}/samples/integration_test/_build/Release
114141

115142
- name: Compile integration test (Debug)
116-
shell: cmd
117143
run: cmake --build ${{github.workspace}}/samples/integration_test/_build --config Debug
118144
working-directory: ${{ github.workspace }}/samples/integration_test
119145

CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ file(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH)
2828
message(STATUS "Module Path: ${CMAKE_MODULE_PATH}")
2929
message(STATUS "Prefix Path: ${CMAKE_PREFIX_PATH}")
3030

31+
# Set Debug postfix
32+
set(CMAKE_DEBUG_POSTFIX d)
33+
set(CMAKE_MINSIZEREL_POSTFIX minsize)
34+
set(CMAKE_RELWITHDEBINFO_POSTFIX reldbg)
35+
3136
# CMake Options
3237
include (CMakeDependentOption)
3338

@@ -39,6 +44,10 @@ option(UDPCAP_BUILD_TESTS
3944
"Build the udpcap GTests. Requires GTest::GTest to be available."
4045
OFF)
4146

47+
option(UDPCAP_INSTALL
48+
"Install udpcap library and headers"
49+
ON)
50+
4251
option(UDPCAP_THIRDPARTY_ENABLED
4352
"Enable building against the builtin dependencies"
4453
ON)
@@ -90,14 +99,8 @@ if (UDPCAP_THIRDPARTY_USE_BUILTIN_GTEST)
9099
include(thirdparty/GTest/GTest_make_available.cmake)
91100
endif()
92101

93-
94102
#----------------------------------------------
95103

96-
# Set Debug postfix
97-
set(CMAKE_DEBUG_POSTFIX d)
98-
set(CMAKE_MINSIZEREL_POSTFIX minsize)
99-
set(CMAKE_RELWITHDEBINFO_POSTFIX reldbg)
100-
101104
# Add main udpcap library
102105
add_subdirectory(udpcap)
103106

CMakeWindows.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mkdir _build
22
cd _build
33

4-
cmake .. -DCMAKE_INSTALL_PREFIX=_install -A x64 -DBUILD_SHARED_LIBS=OFF
4+
cmake .. -DCMAKE_INSTALL_PREFIX=_install -A x64 -DBUILD_SHARED_LIBS=OFF -DUDPCAP_LIBRARY_TYPE=SHARED -DUDPCAP_BUILD_TESTS=ON -DUDPCAP_BUILD_SAMPLES=ON
55
cd ..
66
pause

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,14 @@ You can set the following CMake Options to control how Udpcap is supposed to bui
128128
|----------------------------------------------|----------|-------------|-----------------------------------------------------------------------------------------------------------------|
129129
| `UDPCAP_BUILD_SAMPLES` | `BOOL` | `ON` | Build the Udpcap (and asio) samples for sending and receiving dummy data |
130130
| `UDPCAP_BUILD_TESTS` | `BOOL` | `OFF` | Build the udpcap GTests. Requires GTest::GTest to be available. |
131+
| `UDPCAP_INSTALL` | `BOOL` | `ON` | Install udpcap library and headers |
131132
| `UDPCAP_THIRDPARTY_ENABLED` | `BOOL` | `ON` | Activate / Deactivate the usage of integrated dependencies. |
132133
| `UDPCAP_THIRDPARTY_USE_BUILTIN_NPCAP` | `BOOL` | `ON` | Fetch and build against an integrated Version of the npcap SDK. <br>Only available if `UDPCAP_THIRDPARTY_ENABLED=ON` |
133134
| `UDPCAP_THIRDPARTY_USE_BUILTIN_PCAPPLUSPLUS` | `BOOL` | `ON` | Fetch and build against an integrated Version of Pcap++. <br>_Only available if `UDPCAP_THIRDPARTY_ENABLED=ON`_ |
134135
| `UDPCAP_THIRDPARTY_USE_BUILTIN_ASIO` | `BOOL` | `ON` | Fetch and build against an integrated Version of asio. <br>Only available if `UDPCAP_THIRDPARTY_ENABLED=ON` |
135136
| `UDPCAP_THIRDPARTY_USE_BUILTIN_GTEST` | `BOOL` | `ON` | Fetch and build tests against a predefined version of GTest. If disabled, the targets have to be provided externally. <br>Only available if `UDPCAP_THIRDPARTY_ENABLED=ON` and `UDPCAP_BUILD_TESTS=ON`|
136137
| `UDPCAP_LIBRARY_TYPE` | `STRING` | | Controls the library type of Udpcap by injecting the string into the `add_library` call. Can be set to STATIC / SHARED / OBJECT. If set, this will override the regular `BUILD_SHARED_LIBS` CMake option. If not set, CMake will use the default setting, which is controlled by `BUILD_SHARED_LIBS`. |
138+
137139
# How to integrate Udpcap in your project
138140
139141
**Integrate as binaries**:
@@ -144,7 +146,7 @@ You can set the following CMake Options to control how Udpcap is supposed to bui
144146
145147
If you chose the **static** udpcap library (-> `.lib`), you need to make the following targets available for CMake as well:
146148
147-
- `pcapplusplus::pcapplusplus`
149+
- `PcapPlusPlus::Pcap++`
148150
- `npcap::npcap`
149151
150152
Check out the [Udpcap integration sample](samples/integration_test/CMakeLists.txt) for a suggestion on how to do that. You can find the scripts and modules for fetching and finding Npcap and Pcap++ here:

samples/integration_test/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ cmake_minimum_required(VERSION 3.13)
2121
project(integration_test)
2222

2323
################################################################################
24-
# Static udpcap -> we need to fetch npcap & pcap++ again
24+
# Static udpcap -> we need to fetch npcap again
2525
#
2626
# When forking this project and compiling against a static udpcap, you will
2727
# probably have to copy the scripts to your own directory structure.
2828
################################################################################
2929

3030
include("${CMAKE_CURRENT_LIST_DIR}/../../thirdparty/npcap/npcap_make_available.cmake")
31-
include("${CMAKE_CURRENT_LIST_DIR}/../../thirdparty/pcapplusplus/pcapplusplus_make_available.cmake")
3231
################################################################################
3332

3433
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE)

thirdparty/GTest/GTest_make_available.cmake

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@ FetchContent_Declare(GTest
55
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
66
)
77

8+
set(INSTALL_GTEST OFF) # Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)
9+
set(BUILD_GMOCK OFF) # Builds the googlemock subproject
10+
811
message(STATUS "Fetching GTest...")
912
FetchContent_MakeAvailable(GTest)
1013

11-
set(GTest_ROOT_DIR "${gtest_SOURCE_DIR}")
12-
13-
# Googletest automatically forces MT instead of MD if we do not set this option.
14-
if(MSVC)
15-
set(gtest_force_shared_crt ON CACHE BOOL "My option" FORCE)
16-
set(BUILD_GMOCK OFF CACHE BOOL "My option" FORCE)
17-
set(INSTALL_GTEST OFF CACHE BOOL "My option" FORCE)
18-
endif()
1914

2015
# Prepend googletest-module/FindGTest.cmake to Module Path
2116
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Modules/")

thirdparty/npcap/npcap_make_available.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ FetchContent_Declare(npcap_sdk
1313
message(STATUS "Fetching npcap_sdk...")
1414
FetchContent_MakeAvailable(npcap_sdk)
1515

16+
# Findnpcap (for finding the npcap SDK from within UDPCAP)
1617
set(npcap_ROOT_DIR "${npcap_sdk_SOURCE_DIR}")
17-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Modules/)
18+
set(PCAP_ROOT "${npcap_sdk_SOURCE_DIR}") # Also set the set PCAP_ROOT for the PcapPlusPlus FindPCAP.cmake module
19+
set(Packet_ROOT "${npcap_sdk_SOURCE_DIR}") # Also set the set Packet_ROOT for the PcapPlusPlus FindPacket.cmake module
20+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Modules/)
21+
Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1 @@
1-
# - Try to find pcapplusplus include dirs and libraries
2-
#
3-
# Usage of this module as follows:
4-
#
5-
# find_package(pcapplusplus)
6-
#
7-
# Variables used by this module, they can change the default behaviour and need
8-
# to be set before calling find_package:
9-
#
10-
# pcapplusplus_ROOT_DIR Set this variable to the root directory of
11-
# the pcapplusplus SDK
12-
#
13-
# Targets created by this module:
14-
#
15-
# pcapplusplus::pcapplusplus Interface target for all libraries below
16-
# pcapplusplus::common Common++.lib
17-
# pcapplusplus::packet Packet++.lib
18-
# pcapplusplus::pcap Pcap++.lib
19-
#
20-
# Variables defined by this module:
21-
#
22-
# pcapplusplus_FOUND System has pcapplusplus, include and library dirs found
23-
# pcapplusplus_INCLUDE_DIR The pcapplusplus include directories.
24-
# pcapplusplus_LIBS The pcapplusplus libraries
25-
#
26-
27-
# Root dir
28-
find_path(pcapplusplus_ROOT_DIR
29-
NAMES
30-
header/PcapFileDevice.h
31-
header/Packet.h
32-
)
33-
34-
# Include dir
35-
find_path(pcapplusplus_INCLUDE_DIR
36-
NAMES
37-
PcapFileDevice.h
38-
Packet.h
39-
HINTS
40-
"${pcapplusplus_ROOT_DIR}/header"
41-
)
42-
43-
# Lib dir
44-
if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8)
45-
# Find 64-bit libraries
46-
find_path (pcapplusplus_LIB_DIR
47-
NAMES "Release/Pcap++.lib"
48-
HINTS "${pcapplusplus_ROOT_DIR}/x64/"
49-
)
50-
else()
51-
# Find 32-bit libraries
52-
find_path (pcapplusplus_LIB_DIR
53-
NAMES "Release/Pcap++.lib"
54-
HINTS "${pcapplusplus_ROOT_DIR}/x86/"
55-
)
56-
endif()
57-
58-
# Lib files
59-
set(pcapplusplus_LIBS
60-
optimized "${pcapplusplus_LIB_DIR}/Release/Common++.lib"
61-
optimized "${pcapplusplus_LIB_DIR}/Release/Packet++.lib"
62-
optimized "${pcapplusplus_LIB_DIR}/Release/Pcap++.lib"
63-
64-
debug "${pcapplusplus_LIB_DIR}/Debug/Common++.lib"
65-
debug "${pcapplusplus_LIB_DIR}/Debug/Packet++.lib"
66-
debug "${pcapplusplus_LIB_DIR}/Debug/Pcap++.lib"
67-
)
68-
69-
include(FindPackageHandleStandardArgs)
70-
find_package_handle_standard_args(pcapplusplus DEFAULT_MSG
71-
pcapplusplus_LIBS
72-
pcapplusplus_INCLUDE_DIR
73-
)
74-
75-
if (pcapplusplus_FOUND AND NOT TARGET pcapplusplus::pcapplusplus)
76-
77-
add_library(pcapplusplus::common UNKNOWN IMPORTED)
78-
set_target_properties(pcapplusplus::common PROPERTIES
79-
INTERFACE_INCLUDE_DIRECTORIES "${pcapplusplus_INCLUDE_DIR}"
80-
IMPORTED_LOCATION "${pcapplusplus_LIB_DIR}/Release/Common++.lib"
81-
IMPORTED_LOCATION_DEBUG "${pcapplusplus_LIB_DIR}/Debug/Common++.lib")
82-
83-
add_library(pcapplusplus::packet UNKNOWN IMPORTED)
84-
set_target_properties(pcapplusplus::packet PROPERTIES
85-
INTERFACE_INCLUDE_DIRECTORIES "${pcapplusplus_INCLUDE_DIR}"
86-
IMPORTED_LOCATION "${pcapplusplus_LIB_DIR}/Release/Packet++.lib"
87-
IMPORTED_LOCATION_DEBUG "${pcapplusplus_LIB_DIR}/Debug/Packet++.lib")
88-
89-
add_library(pcapplusplus::pcap UNKNOWN IMPORTED)
90-
set_target_properties(pcapplusplus::pcap PROPERTIES
91-
INTERFACE_INCLUDE_DIRECTORIES "${pcapplusplus_INCLUDE_DIR}"
92-
IMPORTED_LOCATION "${pcapplusplus_LIB_DIR}/Release/Pcap++.lib"
93-
IMPORTED_LOCATION_DEBUG "${pcapplusplus_LIB_DIR}/Debug/Pcap++.lib")
94-
95-
add_library(pcapplusplus::pcapplusplus INTERFACE IMPORTED)
96-
set_property(TARGET pcapplusplus::pcapplusplus PROPERTY
97-
INTERFACE_LINK_LIBRARIES
98-
pcapplusplus::common
99-
pcapplusplus::packet
100-
pcapplusplus::pcap)
101-
102-
endif()
103-
104-
mark_as_advanced(
105-
pcapplusplus_ROOT_DIR
106-
pcapplusplus_INCLUDE_DIR
107-
pcapplusplus_LIB_DIR
108-
pcapplusplus_LIBS
109-
)
1+
set(PcapPlusPlus_FOUND TRUE CACHE BOOL "Found Pcap++" FORCE)
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
if (NOT DEFINED PCAPPLUSPLUS_ARCHIVE_URL)
2-
set(PCAPPLUSPLUS_ARCHIVE_URL "https://github.com/seladb/PcapPlusPlus/releases/download/v22.11/pcapplusplus-22.11-windows-vs2015.zip")
3-
set(PCAPPLUSPLUS_ARCHIVE_HASH "MD5=d20cc0706c6a246b8c4cfb44ce149ffa")
4-
endif()
5-
61
include(FetchContent)
72
FetchContent_Declare(pcapplusplus
8-
URL "${PCAPPLUSPLUS_ARCHIVE_URL}"
9-
URL_HASH "${PCAPPLUSPLUS_ARCHIVE_HASH}"
3+
GIT_REPOSITORY https://github.com/seladb/PcapPlusPlus.git
4+
GIT_TAG cb97f6e7d22cbacd6a5ad843356dc6be012fa7e1 # 2025-05-07: The latest release 24.09 is not CMake 4.0 ready, so I am using the latest master, here
5+
DOWNLOAD_EXTRACT_TIMESTAMP FALSE
106
)
117

8+
set(PCAPPP_INSTALL ON)
9+
1210
message(STATUS "Fetching Pcap++...")
1311
FetchContent_MakeAvailable(pcapplusplus)
1412

15-
set(pcapplusplus_ROOT_DIR "${pcapplusplus_SOURCE_DIR}")
16-
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Modules/)
13+
if(NOT TARGET PcapPlusPlus::Pcap++)
14+
add_library(PcapPlusPlus::Pcap++ ALIAS Pcap++)
15+
endif()
16+
17+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/Modules/")

0 commit comments

Comments
 (0)