diff --git a/arch/arm/src/cmake/Toolchain.cmake b/arch/arm/src/cmake/Toolchain.cmake index cd3b2a630c97b..0559ba5def4df 100644 --- a/arch/arm/src/cmake/Toolchain.cmake +++ b/arch/arm/src/cmake/Toolchain.cmake @@ -25,6 +25,23 @@ set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_VERSION 1) +# Compiler detection must not try to link a full executable. +# +# CMake validates a compiler by building and linking a test program. For a bare +# metal cross toolchain that link cannot succeed on its own terms: it has no +# start files, no default linker script and no libc, and the flags NuttX +# supplies for it (CMAKE_EXE_LINKER_FLAGS_INIT below adds --specs=nosys.specs) +# assume a toolchain shipped with newlib. A perfectly usable arm-none-eabi-gcc +# without those specs then fails configuration before a single NuttX source file +# is considered: +# +# arm-none-eabi-gcc: fatal error: cannot read spec file 'nosys.specs' +# +# Building a static library instead exercises the compiler and stops short of +# the link, which is the documented approach for this case. + +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + set(ARCH_SUBDIR) if(CONFIG_ARCH_ARMV7A) # ARMv7-A