-
Notifications
You must be signed in to change notification settings - Fork 31
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
cmake: modify build system for OpenWrt compatibility #172
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Disable testing and documentation builds by default - Add conditional inclusion of tests and documentation - Handle argp dependency with find_library - Make development tools (clang-tidy, clang-format) optional - Add flexible bpftool handling with fallback paths - Improve build system modularity and configurability This modification adjusts the build system to ensure compatibility with the OpenWrt environment, making necessary changes for a successful build. Signed-off-by: Dengfeng Liu <liudf0716@gmail.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,16 +11,31 @@ project(bpfilter | |
|
||
include(GNUInstallDirs) | ||
|
||
find_package(Doxygen REQUIRED) | ||
option(BUILD_TESTING "Enable testing" OFF) | ||
option(BUILD_DOCS "Enable building documentation" OFF) | ||
|
||
if(BUILD_DOCS) | ||
find_package(Doxygen REQUIRED) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this in if (WITH_DOCS)
add_subdirectory(docs)
endif () |
||
endif() | ||
find_package(PkgConfig REQUIRED) | ||
find_package(FLEX REQUIRED) | ||
find_package(BISON REQUIRED) | ||
|
||
pkg_check_modules(bpf REQUIRED IMPORTED_TARGET libbpf) | ||
pkg_check_modules(elf REQUIRED IMPORTED_TARGET libelf) | ||
pkg_check_modules(cmocka REQUIRED IMPORTED_TARGET cmocka) | ||
if(BUILD_TESTING) | ||
pkg_check_modules(cmocka REQUIRED IMPORTED_TARGET cmocka) | ||
endif() | ||
Comment on lines
+26
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
pkg_check_modules(nl REQUIRED IMPORTED_TARGET libnl-3.0) | ||
|
||
find_library(ARGP_LIBRARY | ||
NAMES argp | ||
PATHS ${CMAKE_SYSROOT}/usr/lib | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to CMake's doc, search path are automatically prefixed with |
||
REQUIRED) | ||
if(NOT ARGP_LIBRARY) | ||
message(FATAL_ERROR "libargp not found") | ||
endif() | ||
Comment on lines
+35
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# Required to get CMake to pass PIE flags to the compiler/linker | ||
include(CheckPIESupported) | ||
check_pie_supported() | ||
|
@@ -30,13 +45,34 @@ if(NOT CMAKE_C_LINK_PIE_SUPPORTED) | |
"If PIE is enabled by default, test auto discovery might fail.") | ||
endif() | ||
|
||
find_program(SPHINX_BIN sphinx-build REQUIRED) | ||
find_program(LCOV_BIN lcov REQUIRED) | ||
find_program(GENHTML_BIN genhtml REQUIRED) | ||
find_program(CLANG_TIDY_BIN NAMES clang-tidy-18 clang-tidy REQUIRED) | ||
find_program(CLANG_FORMAT_BIN NAMES clang-format-18 clang-format REQUIRED) | ||
if(BUILD_DOCS) | ||
find_program(SPHINX_BIN sphinx-build REQUIRED) | ||
find_program(LCOV_BIN lcov REQUIRED) | ||
find_program(GENHTML_BIN genhtml REQUIRED) | ||
find_program(CLANG_TIDY_BIN NAMES clang-tidy-18 clang-tidy REQUIRED) | ||
find_program(CLANG_FORMAT_BIN NAMES clang-format-18 clang-format REQUIRED) | ||
Comment on lines
+52
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those two binaries are not part of the documentation generation, but the testing logic. |
||
endif() | ||
Comment on lines
+48
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All those |
||
|
||
# Replace mandatory REQUIRED flag | ||
find_program(BPFTOOL_BIN bpftool) | ||
|
||
# Add fallback paths | ||
if(NOT BPFTOOL_BIN) | ||
find_program(BPFTOOL_BIN bpftool | ||
PATHS | ||
${CMAKE_SYSROOT}/usr/sbin | ||
${CMAKE_SYSROOT}/sbin | ||
/usr/sbin | ||
/sbin | ||
) | ||
endif() | ||
|
||
# Make it optional with warning | ||
if(NOT BPFTOOL_BIN) | ||
message(WARNING "bpftool not found - some features may be disabled") | ||
set(BPFTOOL_BIN "bpftool") # Set default value | ||
endif() | ||
Comment on lines
+56
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to |
||
find_program(CLANG_BIN clang REQUIRED) | ||
find_program(BPFTOOL_BIN bpftool REQUIRED) | ||
find_program(JQ_BIN jq REQUIRED) | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
@@ -84,8 +120,12 @@ target_link_options(bf_global_flags | |
) | ||
|
||
add_subdirectory(src) | ||
add_subdirectory(tests) | ||
add_subdirectory(doc) | ||
if(BUILD_DOCS) | ||
add_subdirectory(doc) | ||
endif() | ||
if(BUILD_TESTING) | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
install(TARGETS bpfilter libbpfilter_a libbpfilter_so bfcli) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,5 @@ target_link_libraries(bfcli | |
bf_global_flags | ||
core | ||
libbpfilter_a | ||
${ARGP_LIBRARY} | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ target_link_libraries(e2e_bin | |
PRIVATE | ||
harness | ||
libbpfilter_a | ||
${ARGP_LIBRARY} | ||
) | ||
|
||
add_custom_target(e2e | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those should be enabled by default to keep the current behaviour. Use
WITH_XXX
instead ofBUILD_XXX
similarly to #174.