MLPP uses CMake 3.20+ as its build system, providing flexible configuration options and modern package management integration. The library can be used as a standalone project or integrated into larger CMake-based builds.
CMake configuration options
MLPP exposes several options to control build behavior and optional dependencies:
option(MLPP_BUILD_TESTS "Build tests" ON)
option(MLPP_BUILD_EXAMPLES "Build examples" ON)
option(MLPP_WITH_PYPLOT "Enable matplotlibcpp (Python+NumPy)" ON)
option(MLPP_WITH_OPENCV "Enable OpenCV support" ON)
option(MLPP_USE_EIGEN "Use Eigen when available" ON)
Core options
Build the test suite. Useful during development but can be disabled for production integration.
Compile example programs demonstrating library usage. Disable to speed up builds when examples aren’t needed.
Enable Eigen 3.4+ integration for linear algebra operations. Highly recommended for performance.
Enable matplotlib visualization support via matplotlibcpp. Requires Python3 and NumPy.
Enable OpenCV integration for computer vision tasks. Optional but useful for image-based ML.
Dependency management
MLPP uses find_package() to locate optional dependencies and automatically configures compile definitions:
if(MLPP_USE_EIGEN)
find_package(Eigen3 3.4 QUIET NO_MODULE)
if(Eigen3_FOUND)
target_link_libraries(mlpp INTERFACE Eigen3::Eigen)
target_compile_definitions(mlpp INTERFACE MLPP_HAS_EIGEN)
endif()
endif()
if(MLPP_WITH_PYPLOT)
find_package(Python3 REQUIRED COMPONENTS Interpreter Development NumPy)
target_link_libraries(mlpp INTERFACE Python3::Python Python3::NumPy)
target_compile_definitions(mlpp INTERFACE MLPP_WITH_PYPLOT)
endif()
if(MLPP_WITH_OPENCV)
find_package(OpenCV QUIET COMPONENTS core imgproc highgui)
if(OpenCV_FOUND)
target_link_libraries(mlpp INTERFACE opencv_core opencv_imgproc opencv_highgui)
target_compile_definitions(mlpp INTERFACE MLPP_HAS_OPENCV)
endif()
endif()
Dependencies are linked with INTERFACE visibility, meaning they propagate to consuming targets automatically.
Integration patterns
MLPP supports multiple integration workflows depending on your project structure.
Method 1: FetchContent (recommended)
Use CMake’s FetchContent module to download and integrate MLPP directly:
cmake_minimum_required ( VERSION 3.20)
project (my_ml_project)
include (FetchContent)
FetchContent_Declare(
mlpp
GIT_REPOSITORY https://github.com/your-org/mlpp.git
GIT_TAG v0.3.0
)
# Optionally configure MLPP options before making it available
set (MLPP_BUILD_TESTS OFF )
set (MLPP_BUILD_EXAMPLES OFF )
FetchContent_MakeAvailable(mlpp)
add_executable (my_app main.cpp)
target_link_libraries (my_app PRIVATE mlpp::mlpp)
Method 2: find_package (installed library)
If MLPP is installed system-wide, use find_package() with the generated config file:
cmake_minimum_required ( VERSION 3.20)
project (my_ml_project)
find_package (mlpp 0.3 REQUIRED)
add_executable (my_app main.cpp)
target_link_libraries (my_app PRIVATE mlpp::mlpp)
Method 3: add_subdirectory (local copy)
For projects with MLPP as a subdirectory:
cmake_minimum_required ( VERSION 3.20)
project (my_ml_project)
add_subdirectory (external/mlpp)
add_executable (my_app main.cpp)
target_link_libraries (my_app PRIVATE mlpp::mlpp)
Package installation
MLPP includes complete installation support with CMake package config files:
include(GNUInstallDirs)
install(DIRECTORY include/mlpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS mlpp EXPORT mlppTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(EXPORT mlppTargets
FILE mlppTargets.cmake
NAMESPACE mlpp::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/mlpp
)
Installation workflow
Configure
Configure the build with desired options: cmake -B build -DCMAKE_BUILD_TYPE=Release \
-DMLPP_BUILD_TESTS=OFF \
-DMLPP_BUILD_EXAMPLES=OFF
Install
Install headers and package configuration: cmake --install build --prefix /usr/local
Use in projects
Projects can now find MLPP via find_package(mlpp).
Package configuration
The installed package config automatically finds required dependencies:
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
if(@MLPP_USE_EIGEN@)
find_dependency(Eigen3 3.4)
endif()
if(@MLPP_WITH_PYPLOT@)
find_dependency(Python3 COMPONENTS NumPy)
endif()
if(@MLPP_WITH_OPENCV@)
find_dependency(OpenCV COMPONENTS core imgproc highgui)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/mlppTargets.cmake")
check_required_components(mlpp)
This ensures consuming projects automatically get all required transitive dependencies.
Compiler requirements
MLPP requires C++20 support:
target_compile_features(mlpp INTERFACE cxx_std_20)
Tested compilers
GCC 10+
Clang 12+
MSVC 2019+
AppleClang 13+
Build tips
For the smallest footprint, disable all optional features: cmake -B build -DMLPP_BUILD_TESTS=OFF \
-DMLPP_BUILD_EXAMPLES=OFF \
-DMLPP_WITH_PYPLOT=OFF \
-DMLPP_WITH_OPENCV=OFF
Development configuration
Enable all features for development and testing: cmake -B build -DCMAKE_BUILD_TYPE=Debug \
-DMLPP_BUILD_TESTS=ON \
-DMLPP_BUILD_EXAMPLES=ON
cmake --build build
ctest --test-dir build
Troubleshooting
If Eigen is not found automatically, set the Eigen3_DIR CMake variable to point to your Eigen installation’s CMake directory.
Common issues
Eigen not detected : Ensure Eigen 3.4+ is installed and discoverable via CMake. Set Eigen3_DIR if needed:
cmake -B build -DEigen3_DIR=/path/to/eigen3/share/eigen3/cmake
Python/NumPy errors : The Python3 development headers and NumPy must be available. Disable pyplot if not needed:
cmake -B build -DMLPP_WITH_PYPLOT=OFF
C++20 not supported : Update your compiler or explicitly specify the compiler version:
cmake -B build -DCMAKE_CXX_COMPILER=g++-11