Skip to content

Commit e950390

Browse files
committed
Squash a combination of 38 commits
Create cmake.yml Add MacOS builiding hints Add libtins as a submodule Add build hints for external libtins and gtest Create tests.yml Upgrade google test version 1.11.0 -> 1.13.0 Add build and tests badges to README Address the issues in the discussion of the PR: * use the system libraries, make alternatives optional, activated with switches * keep the lines up to 80 chars in length, unless technically not possible * set the level of redundant messages to DEBUG, mark them for removal with FIXME: * provide details of build problems using Apple/CLang in README * Use built type Debug for tests
1 parent de876dc commit e950390

13 files changed

Lines changed: 269 additions & 6 deletions

File tree

.github/workflows/cmake-macos.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CMake-MacOS
2+
3+
on:
4+
push:
5+
branches: [ "feature_branch" ]
6+
pull_request:
7+
branches: [ "feature_branch" ]
8+
9+
env:
10+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
11+
BUILD_TYPE: Release
12+
13+
jobs:
14+
build:
15+
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
16+
# You can convert this to a matrix build if you need cross-platform coverage.
17+
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
18+
runs-on: macos-12 # macos-11
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Configure CMake
24+
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
25+
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
26+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
27+
28+
- name: Build
29+
# Build your program with the given configuration
30+
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
31+
32+
- name: Test
33+
working-directory: ${{github.workspace}}/build
34+
# Execute tests defined by the CMake configuration.
35+
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
36+
run: ctest -C ${{env.BUILD_TYPE}}
37+

.github/workflows/cmake.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Build the library without tests
2+
name: Build
3+
4+
on:
5+
push:
6+
branches: [ "master" ]
7+
pull_request:
8+
branches: [ "master" ]
9+
10+
env:
11+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
12+
BUILD_TYPE: Release
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Configure CMake
22+
run: |
23+
cmake -B ${{github.workspace}}/build \
24+
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNF9_BUILD_TESTS=OFF
25+
26+
- name: Build
27+
# Build your program with the given configuration
28+
run: |
29+
cmake --build ${{github.workspace}}/build \
30+
--config ${{env.BUILD_TYPE}}

.github/workflows/tests-own.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Build tests using external libraries referencd by the project
2+
name: TestsOwnLibs
3+
4+
on:
5+
push:
6+
branches: [ "master" ]
7+
pull_request:
8+
branches: [ "master" ]
9+
10+
env:
11+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
12+
BUILD_TYPE: Debug
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Install libpcap
22+
run: sudo apt-get install -y libpcap-dev
23+
24+
- name: Initialize submodules
25+
run: git submodule init && git submodule update
26+
27+
- name: Build libtins library
28+
run: |
29+
cd ${{github.workspace}}/external/libtins && mkdir build && \
30+
cd build && cmake .. -DLIBTINS_ENABLE_CXX11=1 && cmake --build .
31+
32+
- name: Configure CMake
33+
run: |
34+
cmake -B ${{github.workspace}}/build \
35+
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNF9_BUILD_TESTS=ON \
36+
-DNF9_USE_OWN_LIBTINS=ON -DNF9_USE_OWN_GTEST=ON
37+
38+
- name: Build Tests
39+
run: |
40+
cmake --build ${{github.workspace}}/build \
41+
--config ${{env.BUILD_TYPE}}
42+
43+
- name: Test
44+
working-directory: ${{github.workspace}}/build
45+
run: ./test/netflowtests
46+
# ctest -C ${{env.BUILD_TYPE}}

.github/workflows/tests.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Build tests using the libraries installed in system
2+
name: TestsSysLibs
3+
4+
on:
5+
push:
6+
branches: [ "master" ]
7+
pull_request:
8+
branches: [ "master" ]
9+
10+
env:
11+
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
12+
BUILD_TYPE: Debug
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Install libpcap
22+
run: sudo apt-get install -y libpcap-dev
23+
24+
- name: Install googletest
25+
run: sudo apt-get install -y libgtest-dev
26+
27+
- name: Install libtins
28+
run: sudo apt-get install -y libtins-dev
29+
30+
- name: Configure CMake
31+
run: |
32+
cmake -B ${{github.workspace}}/build \
33+
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNF9_BUILD_TESTS=ON
34+
35+
- name: Build Tests
36+
# Build your program with the given configuration
37+
run: |
38+
cmake --build ${{github.workspace}}/build \
39+
--config ${{env.BUILD_TYPE}}
40+
41+
- name: Test
42+
working-directory: ${{github.workspace}}/build
43+
run: ./test/netflowtests
44+
# ctest -C ${{env.BUILD_TYPE}}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/clang_build/
33
__pycache__
44
ENV
5+
.vscode/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "external/libtins"]
2+
path = external/libtins
3+
url = https://github.com/mfontanini/libtins.git

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ option(NF9_FUZZ "Enable fuzzing with LLVM fuzzer" OFF)
77
option(NF9_BUILD_BENCHMARK
88
"If set, build benchmarks (requires google benchmark library)" OFF)
99
option(NF9_BUILD_EXAMPLES "If set, build examples" OFF)
10+
option(NF9_USE_OWN_LIBTINS "If set, use the libtins in the submodule" OFF)
11+
option(NF9_USE_OWN_GTEST "If set, use googtest library from github" OFF)
1012

1113
include(CheckCXXCompilerFlag)
1214
include(CheckIncludeFileCXX)
@@ -29,7 +31,15 @@ else ()
2931
add_library(netflow9 STATIC ${CXX_SRC})
3032
endif ()
3133

32-
target_include_directories(netflow9 SYSTEM PUBLIC include)
34+
if (NOT NF9_USE_OWN_LIBTINS)
35+
target_include_directories(netflow9 SYSTEM PUBLIC include)
36+
else ()
37+
get_property(SRC_DIR DIRECTORY PROPERTY SOURCE_DIR)
38+
target_include_directories(netflow9 SYSTEM PUBLIC include
39+
${SRC_DIR}/external/libtins/include/
40+
)
41+
endif()
42+
3343
target_compile_features(netflow9 PRIVATE cxx_std_17)
3444

3545
if (MSVC)

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ information about the traffic.
77

88
libnetflow9 is written in C++17, and has a compatible C API.
99

10-
# Building #
10+
## Badges ##
11+
12+
### Building ###
13+
14+
![build workflow](https://github.com/doodeck/libnetflow9/actions/workflows/cmake.yml/badge.svg)
15+
16+
### Testing ###
17+
18+
![test workflow sys](https://github.com/doodeck/libnetflow9/actions/workflows/tests.yml/badge.svg)
19+
20+
![test workflow own](https://github.com/doodeck/libnetflow9/actions/workflows/tests-own.yml/badge.svg)
21+
1122

1223
## Dependencies ##
1324

@@ -33,6 +44,24 @@ cmake ..
3344
make -j4
3445
```
3546

47+
## Building on MacOS M1
48+
49+
```
50+
mkdir build
51+
cd build
52+
cmake .. -DCMAKE_C_COMPILER=/opt/homebrew/bin/gcc-12 -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/g++-12
53+
cmake --build .
54+
```
55+
56+
Otherwise it defaults to Clang toolset, which as of version:
57+
58+
`Apple clang version 14.0.0 (clang-1400.0.29.202)`
59+
60+
is incapable of compiling the library. More details in the build log
61+
62+
https://github.com/doodeck/libnetflow9/actions/runs/4681045806/jobs/8293144058
63+
64+
3665
## Building and running tests ##
3766

3867
```console

external/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# external libraries sources directory
2+
3+
The external libraries are not used by default, instead it's expected they
4+
are installed system-wide. System libraries have advantages, e.g. you can
5+
rely on them in an airgapped environment. On the other hand, they are missing
6+
from some distributions.
7+
8+
In order to activate the external libraries set to ON the correspoding cmake
9+
option[-s]:
10+
11+
* `NF9_USE_OWN_LIBTINS`
12+
* `NF9_USE_OWN_GTEST`
13+
14+
## libtins
15+
https://github.com/mfontanini/libtins.git
16+
17+
Incorporated as a submodule as described here:
18+
19+
https://git-scm.com/book/en/v2/Git-Tools-Submodules
20+
21+
## googtest
22+
pulled directly from github release as recommended here:
23+
24+
https://github.com/google/googletest/blob/main/googletest/README.md
25+
26+
Overthere see the description below the last bullet point "Use CMake
27+
to download GoogleTest as part of the build's configure step. This approach
28+
doesn't have the limitations of the other methods."

external/libtins

Submodule libtins added at fa87e1b

0 commit comments

Comments
 (0)