This directory contains a collection of example applications for the Mobile Robot Programming Toolkit (MRPT).
In MRPT v3, these examples are designed as independent CMake projects that can be built standalone or within a colcon workspace.
Follow these steps to add a new example to the MRPT tree:
-
Create the Directory: Create a folder named after your example in
[MRPT]/mrpt_examples_cpp/.- Example:
[MRPT]/mrpt_examples_cpp/my_feature_demo/.
- Example:
-
Add Source Code: Save your C++ file (typically
main.cpp) in that directory. -
Register the Example: Open
generate_cmake_files.cmakeand add your example name to the relevantLIST_EXAMPLES_IN_THIS_DIRblock.- Ensure you set
CMAKE_EXAMPLE_DEPSusing the v3 namespaced format (e.g.,mrpt::mrpt_math).
- Ensure you set
-
Generate the Build Script: From the command line, run the generator script to create the local
CMakeLists.txt:cmake -DMRPT_SOURCE_DIR=. -P generate_cmake_files.cmake
-
Commit Files: Add both your source code and the generated
CMakeLists.txtto version control:git add my_feature_demo/main.cpp my_feature_demo/CMakeLists.txt
The generate_cmake_files.cmake script uses CMakeLists_template.txt.in to produce a unique CMakeLists.txt for every example. Unlike previous versions, the v3 template "unrolls" dependencies so that each example contains explicit find_package() and target_link_libraries() calls without complex loops.
Dependencies must be defined using the namespaced target format:
- Correct:
mrpt::mrpt_core,mrpt::mrpt_system,mrpt::mrpt_gui. - Internal logic: The generator automatically strips the
mrpt::prefix to handlefind_package(mrpt_xxx)while retaining the full namespace for linking.
To include your example in the official documentation:
- Add a
README.mdand a screenshot in the example directory. - Place the screenshot in
[MRPT]/doc/source/images/. - The docs build (
make -C doc) generates the example page automatically.