This is a CMake module that provides some utilities for configuring C++ projects developed in ERL.
cd <your_workspace>
mkdir -p src
cd src
git clone https://github.com/ExistentialRobotics/erl_cmake_tools.git-
Include the module in your project's
CMakeLists.txtfileadd_subdirectory(src/erl_cmake_tools)Or in the
CMakeLists.txtof your ROS package:if (NOT COMMAND erl_project_setup) find_package(erl_cmake_tools REQUIRED) endif ()
and in the
package.xml, add the buildtool dependency:<buildtool_depend>erl_cmake_tools</buildtool_depend>
-
Then, you can use the utilities provided by
erl_cmake_toolsin otherCMakeLists.txt. For example:cmake_minimum_required(VERSION 3.16) project(erl_covariance LANGUAGES CXX VERSION 0.1.0 DESCRIPTION "erl_covariance is a C++ library of kernel functions") message(STATUS "Configuring ${PROJECT_NAME} ${PROJECT_VERSION}") if (NOT COMMAND erl_project_setup) find_package(erl_cmake_tools REQUIRED) endif () erl_project_setup() erl_setup_ros() # ...
Full example can be found in 🚪erl_covariance.
-
Then build your project:
- As a standard CMake project:
cd <your_workspace> mkdir -p build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release make -j$(nproc)
- As a ROS package:
cd <your_workspace> source /opt/ros/<distro>/setup.bash catkin build # for ROS1 colcon build # for ROS2
- As a standard CMake project:
- Make sure you have the correct Python environment activated,
pipenvis recommended.
cd <your_workspace>/src/erl_cmake_tools
pip install . --verboseThis will install the erl_cmake_tools to the current Python environment. This package does not provide any Python code but cmake macros and functions that can be used by other CMake projects that depend on erl_cmake_tools and provide Python bindings.
This is a macro that does the following things:
- Detect ROS environment: call
erl_detect_ros - Setup compiler flags: call
erl_setup_compiler - Setup Python: call
erl_setup_python - Setup test: call
erl_setup_test - Setup project paths: call
erl_set_project_paths - Find required ERL packages if specified
Options:
ENABLE_CUDA: Enable CUDA supportERL_PACKAGES: List of ERL packages to find
This is a macro that supports both ROS1 and ROS2:
- For ROS1: finds catkin with required catkin components, sets up Python for catkin if
setup.pyis found - For ROS2: sets up ROS2 environment and components
- Supports message generation with MSG_FILES, SRV_FILES, ACTION_FILES
- Handles dependencies with CATKIN_COMPONENTS, CATKIN_DEPENDS, ROS2_COMPONENTS
This is a macro that includes ROS-specific source configuration:
- For ROS1: includes
src/ros1/ros.cmakeif it exists - For ROS2: includes
src/ros2/ros.cmakeif it exists - Provides warnings if ROS is not activated or configuration files don't exist
This is a function that automatically links targets with ERL package dependencies:
- Links with ERL packages specified in
${PROJECT_NAME}_ERL_PACKAGES - Supports additional dependencies via unparsed arguments
- Handles ROS1 catkin includes and libraries
- Supports ROS2 message linking with
LINK_MSGSoption to link the ${PROJECT_NAME}_msgs target
This is a macro that creates Python binding modules using pybind11:
- Creates pybind11 module from C++ sources in specified directory
- Handles include directories and library linking
- Sets up proper RPATH for portability
- Supports custom module names and source directories
Options:
PYBIND_MODULE_NAME: Name of the pybind11 modulePYBIND_SRC_DIR: Source directory containing .cpp filesINCLUDE_DIRS: Additional include directoriesLIBRARIES: Libraries to link against
This is a macro that sets up Python package build targets:
- Creates custom targets:
<project_name>_py_wheel,<project_name>_py_develop,<project_name>_py_install - Optionally creates stub generation target:
<project_name>_py_stub - Requires
setup.pyin project root directory - Supports user installation mode with
ERL_PYTHON_INSTALL_USERoption
This is a macro that automatically detects and adds GoogleTest tests:
- Scans
test/gtest/*.cppfiles for test sources - Supports excluding specific test files with
erl_ignore_gtest - Links with specified libraries
- Supports custom GTest arguments and working directories
Options:
LIBRARIES: Libraries to link test executables againstEXCLUDE_FROM_ALL: Exclude tests from default build target
This is a macro that finds packages with platform-specific installation suggestions:
- Supports standard CMake find_package and pkg-config modes
- Prints helpful installation commands for different platforms
- Handles REQUIRED, QUIET, and NO_RECORD options
Options:
PACKAGE: Package name to findREQUIRED: Make package requiredQUIET: Suppress verbose outputNO_RECORD: Don't record package as dependencyPKGCONFIG: Use pkg-config instead of find_packageCOMMANDS: Platform-specific installation suggestions
Example:
erl_find_package(
PACKAGE OpenMP
REQUIRED
COMMANDS APPLE "try `brew install libomp`"
COMMANDS UBUNTU_LINUX "try `sudo apt install libomp-dev`"
COMMANDS ARCH_LINUX "try `sudo pacman -S openmp`")This is a function to find directories containing required files with installation suggestions:
- Finds paths using standard CMake find_path
- Provides platform-specific installation suggestions when not found
- Supports custom output variable names
Options:
OUTPUT: Variable name for output (default: FILE_FOUND)PACKAGE: Package name for messagingCOMMANDS: Platform-specific installation suggestions
Example:
erl_find_path(
OUTPUT LAPACKE_INCLUDE_DIR
PACKAGE LAPACKE
NAMES lapacke.h
PATHS /usr/include /usr/local/include
COMMANDS UBUNTU_LINUX "try `sudo apt install liblapacke-dev`"
COMMANDS ARCH_LINUX "try `sudo pacman -S lapacke`")This is a macro that generates comprehensive install rules:
- Installs executables, libraries, header files, and other files
- Handles Python modules and ROS-specific installations
- Creates proper CMake export targets for libraries
- Supports both ROS1 (catkin) and ROS2 (ament) install patterns
Options:
EXECUTABLES: List of executable targets to installLIBRARIES: List of library targets to installPYBIND_MODULES: List of Python binding modules to installCATKIN_PYTHON_PROGRAMS: ROS1-specific Python programsOTHER_FILES: Additional files to install
Example:
erl_install(
EXECUTABLES ${${PROJECT_NAME}_COLLECTED_EXECUTABLES}
LIBRARIES ${${PROJECT_NAME}_COLLECTED_LIBRARIES}
PYBIND_MODULES py${PROJECT_NAME})This is a macro that marks the current project as found and finalizes the build:
- Sets
${PROJECT_NAME}_FOUNDto TRUE - For ROS2: calls
ament_package()with proper CONFIG_EXTRAS - Handles configuration extras for both ROS1 and ROS2
Detects ROS environment and sets ROS1_ACTIVATED or ROS2_ACTIVATED variables based on environment.
Sets up compiler flags including:
- C++17 standard
- OpenMP support
- Warning flags (-Wall, -Wextra)
- Optimization flags for different build types
- ccache support if available
- Platform-specific settings
Enables CUDA language support with proper compiler settings and flags.
Sets up Python build options and configures ERL_BUILD_PYTHON_${PROJECT_NAME} variable.
Sets up testing options and configures ERL_BUILD_TEST_${PROJECT_NAME} variable.
Sets up standard project directory paths for both build and install destinations, with ROS1/ROS2 specific paths.
Gets OS release information including distribution name, version, and codename from system files.
Parses key-value pairs from a list and sets variables with a given prefix.
Prints messages based on the current platform (Linux distribution, macOS, etc.).
Suggests platform-specific commands when assertions fail.
Prints all CMake variables for debugging purposes.
Prints a specific CMake variable value for debugging.
Collects targets of a specific type for later processing.
Adds files to the GTest ignore list.
Sets custom arguments for specific GTest executables.
Sets additional libraries for specific GTest executables.
Sets working directory for specific GTest executables.
Appends target properties to an output variable.
Recursively collects library dependencies and include directories.