diff options
Diffstat (limited to 'scripts/cmake')
-rw-r--r-- | scripts/cmake/bare-metal-sources.cmake | 42 | ||||
-rw-r--r-- | scripts/cmake/bare-metal-toolchain.cmake | 65 | ||||
-rw-r--r-- | scripts/cmake/cmsis-dsp.cmake | 25 | ||||
-rw-r--r-- | scripts/cmake/native-sources.cmake | 8 | ||||
-rw-r--r-- | scripts/cmake/toolchains/bare-metal-armclang.cmake | 134 | ||||
-rw-r--r-- | scripts/cmake/toolchains/bare-metal-gcc.cmake | 145 | ||||
-rw-r--r-- | scripts/cmake/toolchains/native-gcc.cmake (renamed from scripts/cmake/native-toolchain.cmake) | 40 |
7 files changed, 354 insertions, 105 deletions
diff --git a/scripts/cmake/bare-metal-sources.cmake b/scripts/cmake/bare-metal-sources.cmake index 8b348e3..2bfe616 100644 --- a/scripts/cmake/bare-metal-sources.cmake +++ b/scripts/cmake/bare-metal-sources.cmake @@ -28,13 +28,15 @@ set(SOURCE_GEN_DIR ${CMAKE_BINARY_DIR}/generated/bsp) if (NOT DEFINED MEM_PROFILES_SRC_DIR) set(MEM_PROFILES_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/subsystem-profiles) endif() + set(MEM_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_memmap.h.template) set(IRQ_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_irqs.h.template) set(MEM_REGIONS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/mem_regions.h.template) set(TA_SETTINGS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/timing_adapter_settings.template) +set(LINKER_SCRIPT_DIR "${PLAT_HAL}/bsp/mem_layout") set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a") set(TENSORFLOW_LITE_MICRO_FLAG "-DTF_LITE_STATIC_MEMORY") -set(ETHOS_U55_FLAG "-DARM_NPU=1") +set(ETHOS_U55_FLAG "-DARM_NPU=1") if (ETHOS_U55_ENABLED) set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${ETHOS_U55_FLAG}") @@ -54,23 +56,33 @@ if (TARGET_PLATFORM STREQUAL mps3) if (TARGET_SUBSYSTEM STREQUAL sse-300) message(STATUS "target subsystem is ${TARGET_SUBSYSTEM}") set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/mps3") - set(SCAT_FILE "${PLAT_HAL}/bsp/mem_layout/mps3-${TARGET_SUBSYSTEM}.sct") + set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}-${TARGET_SUBSYSTEM}") # Include the mem profile definitions specific to our target subsystem include(${MEM_PROFILES_SRC_DIR}/corstone-${TARGET_SUBSYSTEM}.cmake) set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${MPS3_PLATFORM_FLAG}") + + # For deployment on the MPS3 FPGA platform, we need to produce + # two bin files - one that is loaded into the ITCM, and another + # that is loaded into the DDR region. + set(MPS3_SECTION_PATTERNS "*.at_itcm" "*.at_ddr") + set(MPS3_OUTPUT_BIN_NAMES "itcm.bin" "ddr.bin") + set(MPS3_FPGA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/scripts/${TARGET_PLATFORM}/${TARGET_SUBSYSTEM}/images.txt") else () message(FATAL_ERROR "Non compatible target subsystem: ${TARGET_SUBSYSTEM}") endif () elseif (TARGET_PLATFORM STREQUAL simple_platform) set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/${TARGET_PLATFORM}") - set(SCAT_FILE "${PLAT_HAL}/bsp/mem_layout/${TARGET_PLATFORM}.sct") + set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}") include(${MEM_PROFILES_SRC_DIR}/${TARGET_PLATFORM}.cmake) set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS}") else () message(FATAL_ERROR "Non compatible target platform ${TARGET_PLATFORM}") endif () +# Add link options for the linker script to be used: +add_linker_script(${LINKER_SCRIPT_DIR} ${LINKER_SCRIPT_NAME}) + if (ETHOS_U55_ENABLED) USER_OPTION(TA_CONFIG_FILE "Path to the timing adapter configuration file" "${CMAKE_SCRIPTS_DIR}/ta_config.cmake" @@ -91,7 +103,6 @@ configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h") configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h") configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h") -message(STATUS "Scatter file: ${SCAT_FILE}") message(STATUS "Using BSP package from: ${BSP_PACKAGE_DIR}") if (DEFINED VERIFY_TEST_OUTPUT) @@ -114,27 +125,14 @@ if (DEFINED ARMCLANG_DEBUG_DWARF_LEVEL) set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}") endif() -set(COMPILER_FLAGS "${ALL_COMMON_FLAGS} ${TENSORFLOW_LITE_MICRO_FLAG} ${PROFILING_OPT} ${OPTIONAL_FLAGS}") +set(COMPILER_FLAGS "${TENSORFLOW_LITE_MICRO_FLAG} ${PROFILING_OPT} ${OPTIONAL_FLAGS}") # For some reason, cmake doesn't pass the c++ standard flag, adding it manually set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS} -std=c++11" CACHE INTERNAL "") set(CMAKE_C_FLAGS "${COMPILER_FLAGS}" CACHE INTERNAL "") -set(CMAKE_ASM_FLAGS "${CPU_LD}") set(CMAKE_ASM_COMPILE_OBJECT ${CMAKE_CXX_FLAGS}) -add_link_options(--strict --callgraph --load_addr_map_info --map) -add_link_options(--symbols --xref --scatter=${SCAT_FILE}) - -# Warnings to be ignored: -# L6314W = No section matches pattern -# L6439W = Multiply defined Global Symbol -add_link_options(--diag_suppress=L6439W,L6314W) -add_link_options(--info sizes,totals,unused,veneers --entry Reset_Handler) - -if (CMAKE_BUILD_TYPE STREQUAL Release) - add_link_options(--no_debug) -endif () - -set(CMAKE_EXE_LINKER_FLAGS "${CPU_LD}") +# Tell linker that reset interrupt handler is our entry point +add_link_options(--entry Reset_Handler) set(PLAT_BSP_INCLUDES ${PLAT_HAL}/bsp/cmsis-device/include @@ -168,3 +166,7 @@ file(GLOB_RECURSE SRC_PLAT_HAL "${PLAT_HAL}/bsp/bsp-core/*.c" "${BSP_PACKAGE_DIR}/*.c" ) + +# Special retarget source to direct stdin, stdout and stderr streams to the +# UART block. +set(PLAT_RETARGET_SOURCE "${PLAT_HAL}/bsp/bsp-core/retarget.c") diff --git a/scripts/cmake/bare-metal-toolchain.cmake b/scripts/cmake/bare-metal-toolchain.cmake deleted file mode 100644 index 5d91b98..0000000 --- a/scripts/cmake/bare-metal-toolchain.cmake +++ /dev/null @@ -1,65 +0,0 @@ -#---------------------------------------------------------------------------- -# Copyright (c) 2021 Arm Limited. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed 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. -#---------------------------------------------------------------------------- -# specify the cross compiler -set(CMAKE_C_COMPILER armclang) -set(CMAKE_CXX_COMPILER armclang) -set(CMAKE_C_LINKER_PREFERENCE armlink) -set(CMAKE_ASM_LINKER_PREFERENCE armlink) -set(CMAKE_ASM_COMPILER armasm) -set(CMAKE_ASM_COMPILER_AR armar) - -set(CMAKE_CROSSCOMPILING true) -set(CMAKE_SYSTEM_NAME Generic) - -set(MIN_ARM_CLANG_VERSION 6.14) - -if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) - set(CMAKE_SYSTEM_PROCESSOR cortex-m55) -endif() - -# Skip compiler test execution -set(CMAKE_C_COMPILER_WORKS 1) -set(CMAKE_CXX_COMPILER_WORKS 1) - -set(PLATFORM_HAL 1) - -set(WARNING_OPTS "-Wall -Wextra -Wvla") -set(SPECIAL_OPTS "-fno-rtti -funsigned-char -fno-function-sections -fno-exceptions") -set(PLATFORM_FLAGS "-mthumb --target=arm-arm-non-eabi -mlittle-endian -DPLATFORM_HAL=${PLATFORM_HAL}") - -set(CMAKE_C_FLAGS_DEBUG "-DDEBUG -O0") -set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O3") - -set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -O0") -set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3") - -if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m55) - # Flags for cortex-m55 - set(CPU_CORTEX_M55 1) - set(CPU_CC "-mcpu=cortex-m55 -mfloat-abi=hard -MD -DCPU_CORTEX_M55=1 -DARM_MATH_DSP -DARM_MATH_LOOPUNROLL -D__FPU_USED=1") - set(CPU_LD "--cpu=8.1-M.Main.dsp") -elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m33) - # Flags for cortex-m33 to go here -endif() - -set(ALL_COMMON_FLAGS "${CPU_CC} ${WARNING_OPTS} ${SPECIAL_OPTS} ${PLATFORM_FLAGS}") - -function(enforce_compiler_version) - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_ARM_CLANG_VERSION}) - message( FATAL_ERROR "Arm compiler version must be ${MIN_ARM_CLANG_VERSION} or greater to support ${CMAKE_SYSTEM_PROCESSOR} architecture." ) - endif() -endfunction() diff --git a/scripts/cmake/cmsis-dsp.cmake b/scripts/cmake/cmsis-dsp.cmake index cb0243b..bb26b69 100644 --- a/scripts/cmake/cmsis-dsp.cmake +++ b/scripts/cmake/cmsis-dsp.cmake @@ -37,7 +37,16 @@ set(CMSIS_CORE_INC_DIR "${CMSIS_SRC_PATH}/${CMSIS_CORE_PATH_SUFFIX}/Include file(GLOB_RECURSE CMSIS_DSP_SRC - "${CMSIS_DSP_SRC_DIR}/arm_*.c") + + "${CMSIS_DSP_SRC_DIR}/BasicMathFunctions/arm_*.c" + "${CMSIS_DSP_SRC_DIR}/FastMathFunctions/arm_*.c" + "${CMSIS_DSP_SRC_DIR}/CommonTables/arm_*.c" + "${CMSIS_DSP_SRC_DIR}/TransformFunctions/arm_*.c" + "${CMSIS_DSP_SRC_DIR}/StatisticsFunctions/arm_*.c" + + # Issue with q15 and q31 functions with Arm GNU toolchain, we only + # need f32 functions. + "${CMSIS_DSP_SRC_DIR}/ComplexMathFunctions/arm_*f32.c") # 4. Create static library set(CMSIS_DSP_TARGET cmsis-dsp) @@ -50,6 +59,20 @@ target_include_directories(${CMSIS_DSP_TARGET} PUBLIC target_include_directories(${CMSIS_DSP_TARGET} PRIVATE ${CMSIS_DSP_PRI_INC_DIR}) +if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options(${CMSIS_DSP_TARGET} PUBLIC -flax-vector-conversions) + + # There is a known issue with -O0 optimisation option that affects + # FFT functions from CMSIS-DSP when compiling with Arm GNU embedded + # toolchain version 10.2.1 + if (CMAKE_BUILD_TYPE STREQUAL Debug) + message(WARNING "There are known issues with CMSIS-DSP builds using " + "MVE extension without optimisation. Forcing -O3 " + "optimisation level") + target_compile_options(${CMSIS_DSP_TARGET} PUBLIC -O3) + endif() +endif () + # 5. Add any custom/conditional flags for compilation or linkage if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL cortex-m55) target_compile_definitions(${CMSIS_DSP_TARGET} PUBLIC diff --git a/scripts/cmake/native-sources.cmake b/scripts/cmake/native-sources.cmake index 743e075..1b1431a 100644 --- a/scripts/cmake/native-sources.cmake +++ b/scripts/cmake/native-sources.cmake @@ -34,13 +34,11 @@ set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a") set(TENSORFLOW_LITE_MICRO_FLAGS "-DTF_LITE_STATIC_MEMORY -DACTIVATION_BUF_SRAM_SZ=0") set(CMAKE_C_FLAGS - "${WARNING_FLAGS} ${SPECIAL_OPTS} ${PLATFORM_FLAGS}\ - ${PROFILING_OPT} ${TF_FLAG} ${LOG_FLAG} ${TENSORFLOW_LITE_MICRO_FLAGS}" + "${PROFILING_OPT} ${LOG_FLAG} ${TENSORFLOW_LITE_MICRO_FLAGS}" CACHE INTERNAL "") + set(CMAKE_CXX_FLAGS - "${WARNING_FLAGS} ${SPECIAL_OPTS} ${SPECIAL_OPTS_CXX}\ - ${PLATFORM_FLAGS} ${PROFILING_OPT} ${TF_FLAG} ${LOG_FLAG}\ - ${TENSORFLOW_LITE_MICRO_FLAGS}" + "${PROFILING_OPT} ${LOG_FLAG} ${TENSORFLOW_LITE_MICRO_FLAGS}" CACHE INTERNAL "") # Include directories: diff --git a/scripts/cmake/toolchains/bare-metal-armclang.cmake b/scripts/cmake/toolchains/bare-metal-armclang.cmake new file mode 100644 index 0000000..0a86eb6 --- /dev/null +++ b/scripts/cmake/toolchains/bare-metal-armclang.cmake @@ -0,0 +1,134 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2021 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed 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. +#---------------------------------------------------------------------------- +# specify the cross compiler +set(CMAKE_C_COMPILER armclang) +set(CMAKE_CXX_COMPILER armclang) +set(CMAKE_C_LINKER_PREFERENCE armlink) +set(CMAKE_ASM_LINKER_PREFERENCE armlink) +set(CMAKE_ASM_COMPILER armasm) +set(CMAKE_ASM_COMPILER_AR armar) + +set(CMAKE_CROSSCOMPILING true) +set(CMAKE_SYSTEM_NAME Generic) + +set(MIN_ARM_CLANG_VERSION 6.14) + +# Skip compiler test execution +set(CMAKE_C_COMPILER_WORKS 1) +set(CMAKE_CXX_COMPILER_WORKS 1) +set(PLATFORM_HAL 1) + +if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) + set(CMAKE_SYSTEM_PROCESSOR cortex-m55) +endif() + +if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m55) + # Flags for cortex-m55 + set(CPU_COMPILE_DEF CPU_CORTEX_M55) + set(CPU_NAME ${CMAKE_SYSTEM_PROCESSOR}) + set(FLOAT_ABI hard) + set(ARM_MATH_DSP 1) + set(ARM_MATH_LOOPUNROLL 1) + set(CPU_LINK_OPT "--cpu=8.1-M.Main.dsp") +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m33) + # Flags for cortex-m33 to go here +endif() + +set(${CPU_COMPILE_DEF} 1) + +# Warning options +add_compile_options( + -Wall + -Wextra + -Wvla) + +# General purpose compile options: +add_compile_options( + -funsigned-char + -fno-function-sections + "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>") + +# Arch compile options: +add_compile_options( + -mthumb + -mcpu=${CPU_NAME} + -mfloat-abi=${FLOAT_ABI} + --target=arm-arm-non-eabi + -mlittle-endian + -MD) + +# Compile definitions: +add_compile_definitions( + PLATFORM_HAL=${PLATFORM_HAL} + ${CPU_COMPILE_DEF}=1 + $<$<BOOL:${ARM_MATH_DSP}>:ARM_MATH_DSP> + $<$<BOOL:${ARM_MATH_LOOPUNROLL}>:ARM_MATH_LOOPUNROLL>) + +# Link options: +add_link_options(${CPU_LINK_OPT}) +set(CMAKE_ASM_FLAGS "${CPU_LINK_OPT}") + +# Warnings to be ignored: +# L6314W = No section matches pattern +# L6439W = Multiply defined Global Symbol +add_link_options( + --diag_suppress=L6439W,L6314W + --info sizes,totals,unused,veneers + --strict + --callgraph + --load_addr_map_info + --xref + "$<$<CONFIG:RELEASE>:--no_debug>") + +# Function to add a map file output for the linker to dump diagnostic information to. +function(add_target_map_file TARGET_NAME MAP_FILE_PATH) + target_link_options(${TARGET_NAME} PUBLIC + --map --symbols --list=${MAP_FILE_PATH}) +endfunction() + +# Function to add linker option to use the chosen linker script (scatter file). +function(add_linker_script SCRIPT_DIR SCRIPT_NAME) + set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.sct + CACHE STRING "Linker script path") + if (NOT EXISTS ${LINKER_SCRIPT_PATH}) + message(FATAL_ERROR "Scatter file not found: ${LINKER_SCRIPT_PATH}") + endif() + message(STATUS "Using linker script: ${LINKER_SCRIPT_PATH}") + add_link_options(--scatter=${LINKER_SCRIPT_PATH}) +endfunction() + +# Function to set the command to copy/extract contents from an elf +# into a binary file. +function(add_bin_generation_command) + + set(multiValueArgs SECTION_PATTERNS OUTPUT_BIN_NAMES) + set(oneValueArgs TARGET_NAME OUTPUT_DIR AXF_PATH) + cmake_parse_arguments(PARSED "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + add_custom_command(TARGET ${PARSED_TARGET_NAME} + POST_BUILD + COMMAND fromelf --bin --output=${PARSED_OUTPUT_DIR}/ + ${PARSED_AXF_PATH}) + +endfunction() + +# Function to assert the compiler version +function(enforce_compiler_version) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_ARM_CLANG_VERSION}) + message( FATAL_ERROR "Arm compiler version must be ${MIN_ARM_CLANG_VERSION} or greater to support ${CMAKE_SYSTEM_PROCESSOR} architecture." ) + endif() +endfunction() diff --git a/scripts/cmake/toolchains/bare-metal-gcc.cmake b/scripts/cmake/toolchains/bare-metal-gcc.cmake new file mode 100644 index 0000000..2ffc1bb --- /dev/null +++ b/scripts/cmake/toolchains/bare-metal-gcc.cmake @@ -0,0 +1,145 @@ +#---------------------------------------------------------------------------- +# Copyright (c) 2021 Arm Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed 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. +#---------------------------------------------------------------------------- +# specify the cross compiler +set(TRIPLET arm-none-eabi) + +set(CMAKE_C_COMPILER ${TRIPLET}-gcc) +set(CMAKE_CXX_COMPILER ${TRIPLET}-g++) + +set(CMAKE_CROSSCOMPILING true) +set(CMAKE_SYSTEM_NAME Generic) + +set(MIN_GCC_VERSION 10.2.1) + +# Skip compiler test execution +set(CMAKE_C_COMPILER_WORKS 1) +set(CMAKE_CXX_COMPILER_WORKS 1) +set(PLATFORM_HAL 1) + +if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) + set(CMAKE_SYSTEM_PROCESSOR cortex-m55) +endif() + +if (CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m55) + # Flags for cortex-m55 + set(CPU_COMPILE_DEF CPU_CORTEX_M55) + set(CPU_NAME ${CMAKE_SYSTEM_PROCESSOR}) + set(FLOAT_ABI hard) + set(ARM_MATH_DSP 1) + set(ARM_MATH_LOOPUNROLL 1) +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL cortex-m33) + # Flags for cortex-m33 to go here +endif() + +set(${CPU_COMPILE_DEF} 1) + +# Warning options +add_compile_options( + -Wall + -Wextra + -Wvla + -Wno-psabi) + +# General purpose compile options: +add_compile_options( + -funsigned-char + -fno-function-sections + "$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>") + +# Arch compile options: +add_compile_options( + -mthumb + -mcpu=${CPU_NAME} + -mfloat-abi=${FLOAT_ABI} + -mlittle-endian + -MD) + +# Compile definitions: +add_compile_definitions( + PLATFORM_HAL=${PLATFORM_HAL} + ${CPU_COMPILE_DEF}=1 + $<$<BOOL:${ARM_MATH_DSP}>:ARM_MATH_DSP> + $<$<BOOL:${ARM_MATH_LOOPUNROLL}>:ARM_MATH_LOOPUNROLL>) + +# Link options: +add_link_options( + -mthumb + -mcpu=${CPU_NAME} + -mfloat-abi=${FLOAT_ABI} + -mlittle-endian + --specs=nosys.specs + --stats + "$<$<CONFIG:RELEASE>:--no-debug>") + +# Function to add a map file output for the linker to dump diagnostic information to. +function(add_target_map_file TARGET_NAME MAP_FILE_PATH) + target_link_options(${TARGET_NAME} PUBLIC + -Xlinker -Map=${MAP_FILE_PATH}) +endfunction() + +# Function to add linker option to use the chosen linker script. +function(add_linker_script SCRIPT_DIR SCRIPT_NAME) + set(LINKER_SCRIPT_PATH ${SCRIPT_DIR}/${SCRIPT_NAME}.ld + CACHE STRING "Linker script path") + if (NOT EXISTS ${LINKER_SCRIPT_PATH}) + message(FATAL_ERROR "Linker script not found: ${LINKER_SCRIPT_PATH}") + endif() + message(STATUS "Using linker script: ${LINKER_SCRIPT_PATH}") + add_link_options("SHELL:-T ${LINKER_SCRIPT_PATH}") +endfunction() + +# Function to set the command to copy/extract contents from an elf +# into a binary file. +function(add_bin_generation_command) + + set(multiValueArgs SECTION_PATTERNS OUTPUT_BIN_NAMES) + set(oneValueArgs TARGET_NAME OUTPUT_DIR AXF_PATH) + cmake_parse_arguments(PARSED "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + list(LENGTH PARSED_SECTION_PATTERNS N_SECTION_PATTERNS) + list(LENGTH PARSED_OUTPUT_BIN_NAMES N_OUTPUT_BIN_NAMES) + + if (NOT ${N_SECTION_PATTERNS} STREQUAL ${N_OUTPUT_BIN_NAMES}) + message(FATAL_ERROR "Section patterns and the output binary names " + "should be of the same length") + endif() + + message(STATUS "${TRIPLET}-objcopy requested to generate " + "${N_OUTPUT_BIN_NAMES} bin files.") + + math(EXPR MAX_IDX "${N_SECTION_PATTERNS} - 1") + + foreach(IDX RANGE ${MAX_IDX}) + + list(GET PARSED_OUTPUT_BIN_NAMES ${IDX} OUTPUT_BIN_NAME) + list(GET PARSED_SECTION_PATTERNS ${IDX} SECTION_PATTERN) + + add_custom_command(TARGET ${PARSED_TARGET_NAME} + POST_BUILD + COMMAND ${TRIPLET}-objcopy -O binary + --only-section ${SECTION_PATTERN} ${PARSED_AXF_PATH} + ${PARSED_OUTPUT_DIR}/${OUTPUT_BIN_NAME}) + endforeach() + +endfunction() + +# Function to assert the compiler version +function(enforce_compiler_version) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${MIN_GCC_VERSION}) + message( FATAL_ERROR "arm-none-eabi-gcc version must be ${MIN_GCC_VERSION} or greater to support ${CMAKE_SYSTEM_PROCESSOR} architecture." ) + endif() +endfunction() diff --git a/scripts/cmake/native-toolchain.cmake b/scripts/cmake/toolchains/native-gcc.cmake index 2e28cd4..4b5a62b 100644 --- a/scripts/cmake/native-toolchain.cmake +++ b/scripts/cmake/toolchains/native-gcc.cmake @@ -19,22 +19,34 @@ set(CMAKE_C_COMPILER gcc) set(CMAKE_C_LINKER_PREFERENCE gcc) set(CMAKE_CXX_LINKER_PREFERENCE gcc) -set(CMAKE_C_FLAGS_DEBUG "-DDEBUG -O0 -g") -set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O3") - -set(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -O0 -g") -set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3") - # Platform specific directory: set(PLATFORM_HAL 3) -set(WARNING_FLAGS "-Wsign-compare -Wshadow \ - -Wextra -Wall -Wunused-function \ - -Wmissing-field-initializers \ - -Wswitch -Wvla -Wunused-parameter") -set(SPECIAL_OPTS "-fPIC -pthread") -set(PLATFORM_FLAGS "-DPLATFORM_HAL=${PLATFORM_HAL}") -set(SPECIAL_OPTS_CXX "-fno-threadsafe-statics") -set(CMAKE_EXE_LINKER_FLAGS "-lm -lc -lstdc++ --verbose") + +# Warning compiler definitions: +add_compile_options( + -Wsign-compare + -Wshadow + -Wextra + -Wall + -Wunused-function + -Wmissing-field-initializers + -Wswitch + -Wvla + -Wunused-parameter) + +# General purpose compile definitions: +add_compile_options( + -fPIC + -pthread + -DPLATFORM_HAL=${PLATFORM_HAL} + "$<$<COMPILE_LANGUAGE:CXX>:-fno-threadsafe-statics>") + +# Linker options +add_link_options( + -lm + -lc + -lstdc++ + --verbose) function(enforce_compiler_version) endfunction() |