feat: add USE_SYSTEM_DLIB option and fix typo in vendor message by ashfak99 · Pull Request #21804 · netdata/netdata
This PR introduces a new CMake option, USE_SYSTEM_DLIB (default OFF), which allows developers and package maintainers to use a pre-installed system dlib library instead of vendoring/downloading it during the build process.
Design Decisions:
Added find_package(dlib REQUIRED) conditionally based on the USE_SYSTEM_DLIB flag in the main CMakeLists.txt.
Created an alias add_library(dlib ALIAS dlib::dlib) to ensure seamless linking with the rest of the Netdata codebase if the system package is utilized.
Retained the existing netdata_bundle_dlib() behavior when the option is OFF to ensure backward compatibility and avoid breaking existing build setups.
Minor Fix: Corrected a copy-paste typo in NetdataDlib.cmake where the vendoring status message incorrectly referenced "JSON-C" instead of "dlib".
Fixes #20147 Test Plan
Relying on the repository's robust CI/CD pipeline (GitHub Actions) to verify that the default build (vendored dlib) continues to compile successfully across all supported environments.
Manual verification (if testing locally): Run cmake -S . -B build -DENABLE_ML=ON -DUSE_SYSTEM_DLIB=ON on a system with dlib pre-installed to ensure find_package correctly locates and configures the system library.
Additional Information
This change addresses the feature request to avoid redundant downloads of dlib during the CMake build phase. It provides a standard "opt-in" approach widely used in C++ projects to prefer externally installed libraries.
For users: How does this change affect me?
Which area of Netdata is affected by the change? The CMake build system, specifically when compiling Machine Learning (ML) features.
Can they see the change or is it under the hood? It is strictly an under-the-hood change for developers and package maintainers building Netdata from source.
How is the user impacted by the change? Users building from source can now pass the -DUSE_SYSTEM_DLIB=ON flag to CMake. Standard end-users downloading pre-compiled binaries will not see any difference.
What are the benefits of the change? Faster build times, reuse of existing system resources, bandwidth savings, and better alignment with Linux distribution packaging guidelines (which generally prefer linking against system libraries over vendored dependencies).
Summary by cubic
Adds a CMake option USE_SYSTEM_DLIB (default OFF) to let builds use a system-installed dlib instead of a vendored copy. Fixes a typo in the dlib vendoring status message.
- New Features
- When ENABLE_ML and USE_SYSTEM_DLIB=ON, use find_package(dlib) and add_library(dlib ALIAS dlib::dlib) for seamless linking.
- When OFF, keep existing netdata_bundle_dlib() behavior.
- To use system dlib: cmake -S . -B build -DENABLE_ML=ON -DUSE_SYSTEM_DLIB=ON
Written for commit b4230c4. Summary will update on new commits.