Library Creation Guide
The ADORe libraryes CMake system automatically generates library targets based
on directory structure in the lib/ folder.
Library Types
Static Library
lib/
└── my_library/
├── include/
│ └── my_library/
│ └── header.hpp
└── src/
└── implementation.cpp
- Requires: Both
include/andsrc/directories - Generated:
add_library(my_library STATIC) - Auto-includes: All
*.cppfiles insrc/
Interface Library (Header-only)
lib/
└── my_header_lib/
└── include/
└── my_header_lib/
└── header<.hpp or .h>
- Requires: Only
include/directory (nosrc/) - Generated:
add_library(my_header_lib INTERFACE) - Use case: Header-only libraries, templates
Executable Targets
Executable targets are automatically generated for any .cpp file containing int main(.
Auto-Detection
lib/
├── my_library/
│ └── src/
│ └── library_code.cpp
└── test_programs/
├── demo_app/
│ └── main.cpp # Contains int main()
└── unit_tests/
└── test_runner.cpp # Contains int main()
Generated Targets
- Target name: Based on filename without extension
- Example:
demo_app/main.cpp→mainexecutable - Output: Built to
build/bin/ - Auto-linking: All library targets automatically linked
Requirements
// File: lib/examples/hello_world.cpp
#include <iostream>
int main() { // This pattern triggers auto-generation
std::cout << "Hello World!" << std::endl;
return 0;
}
Auto-Generated Features
- Include directories: Automatically set up for consumers
- Linking: All libraries auto-link to each other (configurable)
- Output location: Libraries built to
build/lib/
Exclusions
Add patterns to .cmakeignore to skip auto-generation:
lib/experimental_lib
lib/*/test
**/debug_*.cpp
Dependencies
Create lib/my_library/requirements.cmake for external dependencies:
find_package(SomePackage REQUIRED)
target_link_libraries(my_library PRIVATE SomePackage::SomePackage)
Example
- Create directory:
mkdir -p lib/math_utils/{include/math_utils,src} - Add header:
lib/math_utils/include/math_utils/calculator.hpp - Add source:
lib/math_utils/src/calculator.cpp - Run
make build- library/targetmath_utilsis automatically created
Consuming an Auto-generated Library
- In the
CMakeLists.txtfor your program include theadore_libraries.cmakefile. Inside theADORE CLIdocker context the environmental variableSOURCE_DIRECTORYwill be set. This can be used to locate theadore_libraries.cmake:
include($ENV{SOURCE_DIRECTORY}/libraries/adore_libraries.cmake)
2. Create a `requirements.cmake` file in the same directory as your
`CMakeLists.txt` and add any special cmake requirements:
```cmake
include(requirements.cmake)
Example requirements.cmake file:
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(Eigen3 REQUIRED)
set(Eigen3_TARGETS Eigen3::Eigen)
- Invoke the helper functions on your target provided by
adore_libraries.cmaketo auto link and include libraries:
add_all_target_include_directories(${PROJECT})
add_all_target_link_libraries(${PROJECT})