apps/system/microros: add CMake cross-compile toolchain template.

Add toolchain.cmake.in and include_override/assert.h for the colcon
cross-build.  Key differences from the old robertobucher port:
  - Drop -DCLOCK_MONOTONIC=0: NuttX defines CLOCK_MONOTONIC=1 and
    the override broke nanosleep() on newer kernels.
  - CMAKE_SYSTEM_PROCESSOR is a placeholder substituted per-arch.
  - include_override/assert.h works around the rosidl NDEBUG issue
    (https://github.com/ros2/rosidl/pull/739).

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
This commit is contained in:
Arjav Patel 2026-05-23 06:23:38 +00:00 committed by Lup Yuen Lee
parent 98d3a0bcb0
commit e764594d26
2 changed files with 70 additions and 0 deletions

View file

@ -0,0 +1,41 @@
/****************************************************************************
* apps/system/microros/micro_ros_lib/include_override/assert.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __MICROROS_INCLUDE_OVERRIDE_ASSERT_H
#define __MICROROS_INCLUDE_OVERRIDE_ASSERT_H
/****************************************************************************
* Included Files
****************************************************************************/
/* Pull the system assert.h, then redefine assert to a no-op when NDEBUG is
* set. Avoids an assert redefinition conflict in rosidl typesupport.
*/
#include_next <assert.h>
#ifdef NDEBUG
# undef assert
# define assert(x) ((void)(0))
#endif
#endif /* __MICROROS_INCLUDE_OVERRIDE_ASSERT_H */

View file

@ -0,0 +1,29 @@
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR @CMAKE_SYSTEM_PROCESSOR@)
set(CMAKE_CROSSCOMPILING 1)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(PLATFORM_NAME "nuttx")
set(CMAKE_C_COMPILER @CMAKE_C_COMPILER@)
set(CMAKE_CXX_COMPILER @CMAKE_CXX_COMPILER@)
set(CMAKE_C_FLAGS_INIT "-std=c11 @ARCH_C_FLAGS@ -D'__attribute__(x)='" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_INIT "-std=c++14 @ARCH_CPP_FLAGS@ -fno-rtti -D'__attribute__(x)='" CACHE STRING "" FORCE)
set(NUTTX_TOPDIR @NUTTX_TOPDIR@)
set(NUTTX_APPDIR @NUTTX_APPDIR@)
set(INCLUDE_OVR_DIR @INCLUDE_OVR_DIR@)
include_directories(SYSTEM
${NUTTX_TOPDIR}/include
${NUTTX_TOPDIR}/include/cxx
${NUTTX_APPDIR}/include
)
include_directories(AFTER SYSTEM
${INCLUDE_OVR_DIR}/include_override
)
set(__BIG_ENDIAN__ 0)