0

I'm developing a build system using CMake to build applications using the arm-none-eabi toolchain. This is my folder structure:

project/
├── apps/
│   ├── test_app
│   │   ├── inc/
│   │   ├── src/
│   │   ├── CMakeLists.txt
├── arch/
│   ├── CMSIS/
│   ├── include/
│   ├── startup/
│   ├── CMakeLists.txt
├── cmake/
│   ├── toolchain-samd51.cmake
├── CMakeLists.txt

This is my top level CMakeLists.txt:

cmake_minimum_required(VERSION 3.17)

project(SMALL-FW LANGUAGES C)

add_subdirectory(arch)
add_subdirectory(apps/test_app)

This is the toolchain cmake file:

# Set target architecture
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

# Set compiler to use
set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
#set(CMAKE_LINKER "arm-none-eabi-ld")

# Clear default compiler and linker flags.
set(CMAKE_C_FLAGS "")
set(CMAKE_C_LINK_FLAGS "")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# FIX - Bypass compiler check
set(CMAKE_C_COMPILER_FORCED TRUE)

# Define common compiler and linker flags
set(ARM_OPTIONS 
    -mthumb
    -mabi=aapcs-linux
    -mcpu=cortex-m4
    -mfpu=fpv4-sp-d16
    -mfloat-abi=softfp
    --specs=nano.specs
    -mlong-calls
    -DSAMD51
)

# Define compiler specific flags
add_compile_options(
    ${ARM_OPTIONS}
    -D__SAMD51J19A__
    -ffunction-sections
    -Wall
)

# Define linker specific flags
add_link_options(
    ${ARM_OPTIONS}
    #--specs=nano.specs
    LINKER:--gc-sections
)

This is the CMakeList.txt inside the arch folder:

add_library(asf OBJECT
    startup/startup_samd51.c
    startup/system_samd51.c
)

# Every target that links against asf needs to know where the ASF headers are.
target_include_directories(asf PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/CMSIS/Include
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# Use the custom linker script provided with ASF.
target_link_options(asf PUBLIC
    -T${CMAKE_CURRENT_SOURCE_DIR}/startup/samd51j19a_flash.ld
)

And this is the app CMakeLists.txt:

add_executable(APP)

target_sources(APP PRIVATE src/main.c src/module.c)

target_include_directories(APP PRIVATE inc/)

target_link_libraries(APP asf)

CMake is running fine when the CMAKE_C_COMPILER_FORCED options is set to true, but when I try to make the project it fails with multiple undefined references errors like the next one:

/build/arm-none-eabi-newlib/src/build-nano/arm-none-eabi/thumb/v7e-m+fp/softfp/newlib/libc/reent/../../../../../../../../newlib-4.2.0.20211231/newlib/libc/reent/sbrkr.c:51: undefined reference to _sbrk'`

I have tried using nosys.specs flag but similar errors occurs.

Gaspar S.
  • 1
  • 1

1 Answers1

0

Try this, it looks like typo

# Define linker specific flags
add_link_options(
    ${ARM_OPTIONS}
    --specs=nano.specs
    --gc-sections
)
Pierwiastek
  • 134
  • 9
  • The option `--specs=nano.specs` is already listed in `ARM_OPTIONS` variable. So specifying it in addition to that variable should change nothing. – Tsyvarev Nov 10 '22 at 17:39