CMake: Set compile defintions for supported toolchain at top level input source file

The compile defintions should always be added depending on the
selected toolchain.
mbed_set_toolchain_options() should only be called if a third-party
toolchain file has not been used as it has compile options that can
cause conflicts.
pull/13566/head
Hugues Kamba 2020-10-28 16:50:23 +00:00
parent 46c35965c5
commit 0bf4683f46
3 changed files with 17 additions and 14 deletions

View File

@ -10,6 +10,7 @@ if(POLICY CMP0076)
cmake_policy(SET CMP0076 NEW)
endif()
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
include(${MBED_PATH}/tools/cmake/core.cmake)
include(${MBED_PATH}/tools/cmake/profile.cmake)
@ -74,6 +75,22 @@ target_compile_definitions(mbed-core
${MBED_CONFIG_DEFINITIONS}
)
# Add compile definitions for backward compatibility with the toolchain
# supported. New source files should instead check for __GNUC__ and __clang__
# for the GCC_ARM and ARM toolchains respectively.
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
target_compile_definitions(mbed-core
INTERFACE
TOOLCHAIN_GCC_ARM
TOOLCHAIN_GCC
)
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
target_compile_definitions(mbed-core
INTERFACE
TOOLCHAIN_ARM
)
endif()
# Include mbed.h and config from generate folder
target_include_directories(mbed-core
INTERFACE

View File

@ -13,7 +13,6 @@ if(MBEDIDE)
set_property(GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER "--ide=mbed")
endif()
# Sets toolchain options
function(mbed_set_toolchain_options target)
get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER)
@ -48,11 +47,6 @@ function(mbed_set_toolchain_options target)
$<$<COMPILE_LANGUAGE:ASM>:${MBED_STUDIO_ARM_COMPILER}>
)
target_compile_definitions(${target}
INTERFACE
TOOLCHAIN_ARM
)
list(APPEND link_options
"${MBED_STUDIO_ARM_COMPILER}"
"--map"

View File

@ -7,7 +7,6 @@ set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
set(GCC_ELF2BIN "arm-none-eabi-objcopy")
set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN})
# Sets toolchain options
function(mbed_set_toolchain_options target)
list(APPEND link_options
@ -52,13 +51,6 @@ function(mbed_set_toolchain_options target)
${common_options}
)
target_compile_definitions(${target}
INTERFACE
TOOLCHAIN_GCC_ARM
TOOLCHAIN_GCC
)
target_link_options(${target}
INTERFACE
${common_options}