Skip to main content

CMake Configuration

LibXR exports the CMake target xr and uses C++20. The upper project supplies the toolchain, startup code, linker script and vendor SDK; LibXR selects its system layer, peripheral backend and feature options.

Basic integration​

A Linux project can select the host system and driver directly:

cmake_minimum_required(VERSION 3.12)
project(example LANGUAGES C CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(LIBXR_SYSTEM linux CACHE STRING "" FORCE)
set(LIBXR_DRIVER linux CACHE STRING "" FORCE)
add_subdirectory(libxr)

add_executable(app main.cpp)
target_link_libraries(app PRIVATE xr)

Cross-compiled projects set LIBXR_SYSTEM and LIBXR_DRIVER before adding LibXR. STM32 + FreeRTOS, for example:

set(LIBXR_SYSTEM freertos CACHE STRING "" FORCE)
set(LIBXR_DRIVER st CACHE STRING "" FORCE)
add_subdirectory(libxr)

Systems and drivers​

Current system/ implementations are:

  • freertos
  • linux
  • none
  • threadx
  • webasm
  • webots

Current driver/ backends are:

  • st
  • ch
  • esp
  • hpm
  • linux
  • mspm0
  • webasm
  • webots

Names are normalized to lowercase internally. Cross-compiling requires LIBXR_SYSTEM; without it, configuration stops with No system selected.. When not cross-compiling, an unset LIBXR_SYSTEM and LIBXR_DRIVER follow the host: a Linux host selects linux, or webots when the CMake variable WEBOTS_HOME is set. A Windows host is used to cross-compile MCU projects; host programs are built in the Linux environment of WSL or the docker-image-linux image (see Docker Environment Setup). Configuring on a Windows host without cross-compiling stops with LibXR has no Windows system or driver layer., followed by these two ways.

Common options​

OptionPurpose
LIBXR_NO_EIGENExclude Eigen-dependent geometry and kinematics
LIBXR_DEFAULT_SCALARDefault math scalar, double by default
LIBXR_SINGLE_CORESingle-core concurrency alignment policy
LIBXR_DEV_ASSERT_BUILDEnable maintainer assertions; OFF by default
LIBXR_TEST_BUILDBuild repository tests
LIBXR_STATIC_BUILDBuild a static library
LIBXR_SHARED_BUILDBuild a shared library
LIBXR_OBJECT_BUILDBuild an object library

The default library kind is static. LIBXR_DEBUG_BUILD follows the build type by default: when it is not set explicitly, it is recomputed on every configure from the current build type (on for Debug, off otherwise) as a normal variable that is not written to the cache, so switching the build type in an existing build directory takes effect immediately; once set explicitly with -DLIBXR_DEBUG_BUILD=ON/OFF, the value becomes a cache entry and is kept on later reconfigures. LIBXR_DEV_ASSERT_BUILD separately controls DEV_ASSERT.

Logging and formatting​

These variables become public compile definitions:

LIBXR_LOG_LEVEL
LIBXR_LOG_OUTPUT_LEVEL
XR_LOG_MESSAGE_MAX_LEN
LIBXR_DEFAULT_SCALAR

Formatting support can also be trimmed for 64-bit integers, double, scientific notation, pointers, explicit argument indexing and related features. The options and their defaults are listed in the "Print configuration" section of Compile-Time Formatting.

XRobot modules​

Set XROBOT_MODULES_DIR before adding LibXR (CMake 3.19 or newer is required):

set(XROBOT_MODULES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Modules")
add_subdirectory(libxr)

LibXR then includes the CMakeLists.txt that xrobot setup generates in that directory and checks User/xrobot_main.hpp; see the XRobot CMake integration.

Use a fresh build directory after changing the system, driver, compiler or SDK so the previous CMake cache does not carry over detection results.