From 46c35965c5f6f0fe91b2d7d6565b7a93ea91a6c5 Mon Sep 17 00:00:00 2001 From: Hugues Kamba Date: Wed, 28 Oct 2020 16:24:32 +0000 Subject: [PATCH] CMake: Create separate function to set MCU core compile defintions The new function (mbed_set_cpu_core_definitions()) should always be called as it has defintions needed by Mbed OS to work with that particular MCU core. mbed_set_cpu_core_options() should only be called if a third-party toolchain file has not been used as it has compile options that can cause conflicts. --- tools/cmake/cores/Cortex-A9.cmake | 2 ++ tools/cmake/cores/Cortex-M0+.cmake | 2 ++ tools/cmake/cores/Cortex-M0.cmake | 2 ++ tools/cmake/cores/Cortex-M1.cmake | 2 ++ tools/cmake/cores/Cortex-M23-NS.cmake | 2 ++ tools/cmake/cores/Cortex-M23.cmake | 2 ++ tools/cmake/cores/Cortex-M3.cmake | 2 ++ tools/cmake/cores/Cortex-M33-NS.cmake | 2 ++ tools/cmake/cores/Cortex-M33.cmake | 2 ++ tools/cmake/cores/Cortex-M33F-NS.cmake | 2 ++ tools/cmake/cores/Cortex-M33F.cmake | 2 ++ tools/cmake/cores/Cortex-M33FE-NS.cmake | 2 ++ tools/cmake/cores/Cortex-M33FE.cmake | 2 ++ tools/cmake/cores/Cortex-M4.cmake | 2 ++ tools/cmake/cores/Cortex-M4F.cmake | 20 +++++++++++--------- tools/cmake/cores/Cortex-M7.cmake | 2 ++ tools/cmake/cores/Cortex-M7F.cmake | 2 ++ tools/cmake/cores/Cortex-M7FD.cmake | 2 ++ 18 files changed, 45 insertions(+), 9 deletions(-) diff --git a/tools/cmake/cores/Cortex-A9.cmake b/tools/cmake/cores/Cortex-A9.cmake index f21f462c82..f953c74878 100644 --- a/tools/cmake/cores/Cortex-A9.cmake +++ b/tools/cmake/cores/Cortex-A9.cmake @@ -39,7 +39,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-A9" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_A9 diff --git a/tools/cmake/cores/Cortex-M0+.cmake b/tools/cmake/cores/Cortex-M0+.cmake index 9f0b101356..4a3b62db61 100644 --- a/tools/cmake/cores/Cortex-M0+.cmake +++ b/tools/cmake/cores/Cortex-M0+.cmake @@ -35,7 +35,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M0plus" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M0PLUS diff --git a/tools/cmake/cores/Cortex-M0.cmake b/tools/cmake/cores/Cortex-M0.cmake index c15f4005fb..a6e376e4bb 100644 --- a/tools/cmake/cores/Cortex-M0.cmake +++ b/tools/cmake/cores/Cortex-M0.cmake @@ -34,7 +34,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "-cpu=Cortex-M0" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M0 diff --git a/tools/cmake/cores/Cortex-M1.cmake b/tools/cmake/cores/Cortex-M1.cmake index 25c01c8d07..46ac7da2ce 100644 --- a/tools/cmake/cores/Cortex-M1.cmake +++ b/tools/cmake/cores/Cortex-M1.cmake @@ -34,7 +34,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M1" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M3 diff --git a/tools/cmake/cores/Cortex-M23-NS.cmake b/tools/cmake/cores/Cortex-M23-NS.cmake index a1def24499..fcb043c33f 100644 --- a/tools/cmake/cores/Cortex-M23-NS.cmake +++ b/tools/cmake/cores/Cortex-M23-NS.cmake @@ -34,7 +34,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M23" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M23 diff --git a/tools/cmake/cores/Cortex-M23.cmake b/tools/cmake/cores/Cortex-M23.cmake index 6ebdabe852..2383f8c27f 100644 --- a/tools/cmake/cores/Cortex-M23.cmake +++ b/tools/cmake/cores/Cortex-M23.cmake @@ -34,7 +34,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M23" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M23 diff --git a/tools/cmake/cores/Cortex-M3.cmake b/tools/cmake/cores/Cortex-M3.cmake index 5ca3a6c79c..ae01ccf6a1 100644 --- a/tools/cmake/cores/Cortex-M3.cmake +++ b/tools/cmake/cores/Cortex-M3.cmake @@ -34,7 +34,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M3" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M3 diff --git a/tools/cmake/cores/Cortex-M33-NS.cmake b/tools/cmake/cores/Cortex-M33-NS.cmake index 1a7c819151..d8b8b696f7 100644 --- a/tools/cmake/cores/Cortex-M33-NS.cmake +++ b/tools/cmake/cores/Cortex-M33-NS.cmake @@ -36,7 +36,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M33.no_dsp.no_fp" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M33 diff --git a/tools/cmake/cores/Cortex-M33.cmake b/tools/cmake/cores/Cortex-M33.cmake index f4059918b9..51d935a84d 100644 --- a/tools/cmake/cores/Cortex-M33.cmake +++ b/tools/cmake/cores/Cortex-M33.cmake @@ -38,7 +38,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M33.no_dsp.no_fp" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M33 diff --git a/tools/cmake/cores/Cortex-M33F-NS.cmake b/tools/cmake/cores/Cortex-M33F-NS.cmake index f0583380ce..657a0d54b8 100644 --- a/tools/cmake/cores/Cortex-M33F-NS.cmake +++ b/tools/cmake/cores/Cortex-M33F-NS.cmake @@ -39,7 +39,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M33.no_dsp" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M33 diff --git a/tools/cmake/cores/Cortex-M33F.cmake b/tools/cmake/cores/Cortex-M33F.cmake index c5fd1bfdc4..583568793d 100644 --- a/tools/cmake/cores/Cortex-M33F.cmake +++ b/tools/cmake/cores/Cortex-M33F.cmake @@ -39,7 +39,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M33.no_dsp" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M33 diff --git a/tools/cmake/cores/Cortex-M33FE-NS.cmake b/tools/cmake/cores/Cortex-M33FE-NS.cmake index fe229b6bea..a9381289b0 100644 --- a/tools/cmake/cores/Cortex-M33FE-NS.cmake +++ b/tools/cmake/cores/Cortex-M33FE-NS.cmake @@ -37,7 +37,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M33" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M33 diff --git a/tools/cmake/cores/Cortex-M33FE.cmake b/tools/cmake/cores/Cortex-M33FE.cmake index 30f59eb8c1..aa3587271b 100644 --- a/tools/cmake/cores/Cortex-M33FE.cmake +++ b/tools/cmake/cores/Cortex-M33FE.cmake @@ -37,7 +37,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M33" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M33 diff --git a/tools/cmake/cores/Cortex-M4.cmake b/tools/cmake/cores/Cortex-M4.cmake index deece22b62..d6058a2ebb 100644 --- a/tools/cmake/cores/Cortex-M4.cmake +++ b/tools/cmake/cores/Cortex-M4.cmake @@ -36,7 +36,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M4.no_fp" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M4 diff --git a/tools/cmake/cores/Cortex-M4F.cmake b/tools/cmake/cores/Cortex-M4F.cmake index b4d2c76908..f064158bc9 100644 --- a/tools/cmake/cores/Cortex-M4F.cmake +++ b/tools/cmake/cores/Cortex-M4F.cmake @@ -3,15 +3,6 @@ # Sets cpu core options function(mbed_set_cpu_core_options target mbed_toolchain) - target_compile_definitions(${target} - INTERFACE - __CORTEX_M4 - ARM_MATH_CM4 - __FPU_PRESENT=1 - __CMSIS_RTOS - __MBED_CMSIS_RTOS_CM - ) - if(${mbed_toolchain} STREQUAL "GCC_ARM") list(APPEND common_toolchain_options "-mthumb" @@ -49,3 +40,14 @@ function(mbed_set_cpu_core_options target mbed_toolchain) ) endif() endfunction() + +function(mbed_set_cpu_core_definitions target) + target_compile_definitions(${target} + INTERFACE + __CORTEX_M4 + ARM_MATH_CM4 + __FPU_PRESENT=1 + __CMSIS_RTOS + __MBED_CMSIS_RTOS_CM + ) +endfunction() diff --git a/tools/cmake/cores/Cortex-M7.cmake b/tools/cmake/cores/Cortex-M7.cmake index 42c88a54af..8b4f3473cf 100644 --- a/tools/cmake/cores/Cortex-M7.cmake +++ b/tools/cmake/cores/Cortex-M7.cmake @@ -36,7 +36,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M7.no_fp" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M7 diff --git a/tools/cmake/cores/Cortex-M7F.cmake b/tools/cmake/cores/Cortex-M7F.cmake index b83c781af4..660968f5cd 100644 --- a/tools/cmake/cores/Cortex-M7F.cmake +++ b/tools/cmake/cores/Cortex-M7F.cmake @@ -39,7 +39,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M7.fp.sp" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M7 diff --git a/tools/cmake/cores/Cortex-M7FD.cmake b/tools/cmake/cores/Cortex-M7FD.cmake index dcbc163e7d..18b8b3268c 100644 --- a/tools/cmake/cores/Cortex-M7FD.cmake +++ b/tools/cmake/cores/Cortex-M7FD.cmake @@ -39,7 +39,9 @@ function(mbed_set_cpu_core_options target mbed_toolchain) "--cpu=Cortex-M7" ) endif() +endfunction() +function(mbed_set_cpu_core_definitions target) target_compile_definitions(${target} INTERFACE __CORTEX_M7