Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

liudf0716
Copy link

  • 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

- 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>
Signed-off-by: Dengfeng Liu <liudf0716@gmail.com>
@facebook-github-bot
Copy link

Hi @liudf0716!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Comment on lines +14 to +15
option(BUILD_TESTING "Enable testing" OFF)
option(BUILD_DOCS "Enable building documentation" OFF)
Copy link
Contributor

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 of BUILD_XXX similarly to #174.

option(BUILD_DOCS "Enable building documentation" OFF)

if(BUILD_DOCS)
find_package(Doxygen REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this in docs/CMakeLists.txt, and modify add_subdirectory(docs) below to:

if (WITH_DOCS)
    add_subdirectory(docs)
endif ()

Comment on lines +26 to +28
if(BUILD_TESTING)
pkg_check_modules(cmocka REQUIRED IMPORTED_TARGET cmocka)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to CMake's doc, search path are automatically prefixed with CMAKE_SYSROOT, so there is no need to add it here.

Comment on lines +35 to +37
if(NOT ARGP_LIBRARY)
message(FATAL_ERROR "libargp not found")
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARGP_LIBRARY is REQUIRED above, if not found, CMake will fail the generation and print an error message, no need for this condition.

Comment on lines +48 to +54
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)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All those find_program should be located in docs/CMakeLists.txt.

@@ -80,7 +78,7 @@ extern const char *strerrordesc_np(int errnum);
*
* @param v Error code, can be positive or negative.
*/
#define bf_strerror(v) strerrordesc_np(abs(v))
#define bf_strerror(v) strerror(abs(v))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Comment on lines +52 to +53
find_program(CLANG_TIDY_BIN NAMES clang-tidy-18 clang-tidy REQUIRED)
find_program(CLANG_FORMAT_BIN NAMES clang-format-18 clang-format REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Comment on lines +56 to +74
# 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to tests/bpf/CMakeLists.txt, where bpftool is actually used. It's not ideal, but better than the current situation and probably sufficient for your use case.

@qdeslandes
Copy link
Contributor

Thanks for the PR @liudf0716 ! I've recently modified the benchmarking configuration similarly to this PR, see #174 for a example of what I'm looking for. Long story short:

  • Dependencies of specific parts of the projects (e.g. doc, tests) should be discovered within the related CMakeLists.txt.
  • Options are defined in the top-level CMakeLists.txt to enable/disable those different parts (e.g. -DWITH_TESTS).
  • If a specific option is defined, the related directory should be processed by CMake.
  • The new option's default value should be set to maintain the current behaviour (e.g. WITH_TESTS should default to ON as tests are always enabled at the moment).

@qdeslandes qdeslandes self-requested a review November 25, 2024 15:25
Copy link
Contributor

@qdeslandes qdeslandes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants