Skip to content

Commit 0bf4683

Browse files
committed
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.
1 parent 46c3596 commit 0bf4683

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ if(POLICY CMP0076)
1010
cmake_policy(SET CMP0076 NEW)
1111
endif()
1212

13+
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
1314
include(${MBED_PATH}/tools/cmake/core.cmake)
1415
include(${MBED_PATH}/tools/cmake/profile.cmake)
1516

@@ -74,6 +75,22 @@ target_compile_definitions(mbed-core
7475
${MBED_CONFIG_DEFINITIONS}
7576
)
7677

78+
# Add compile definitions for backward compatibility with the toolchain
79+
# supported. New source files should instead check for __GNUC__ and __clang__
80+
# for the GCC_ARM and ARM toolchains respectively.
81+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
82+
target_compile_definitions(mbed-core
83+
INTERFACE
84+
TOOLCHAIN_GCC_ARM
85+
TOOLCHAIN_GCC
86+
)
87+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
88+
target_compile_definitions(mbed-core
89+
INTERFACE
90+
TOOLCHAIN_ARM
91+
)
92+
endif()
93+
7794
# Include mbed.h and config from generate folder
7895
target_include_directories(mbed-core
7996
INTERFACE

tools/cmake/toolchains/ARM.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ if(MBEDIDE)
1313
set_property(GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER "--ide=mbed")
1414
endif()
1515

16-
1716
# Sets toolchain options
1817
function(mbed_set_toolchain_options target)
1918
get_property(mbed_studio_arm_compiler GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER)
@@ -48,11 +47,6 @@ function(mbed_set_toolchain_options target)
4847
$<$<COMPILE_LANGUAGE:ASM>:${MBED_STUDIO_ARM_COMPILER}>
4948
)
5049

51-
target_compile_definitions(${target}
52-
INTERFACE
53-
TOOLCHAIN_ARM
54-
)
55-
5650
list(APPEND link_options
5751
"${MBED_STUDIO_ARM_COMPILER}"
5852
"--map"

tools/cmake/toolchains/GCC_ARM.cmake

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
77
set(GCC_ELF2BIN "arm-none-eabi-objcopy")
88
set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN})
99

10-
1110
# Sets toolchain options
1211
function(mbed_set_toolchain_options target)
1312
list(APPEND link_options
@@ -52,13 +51,6 @@ function(mbed_set_toolchain_options target)
5251
${common_options}
5352
)
5453

55-
target_compile_definitions(${target}
56-
INTERFACE
57-
TOOLCHAIN_GCC_ARM
58-
TOOLCHAIN_GCC
59-
)
60-
61-
6254
target_link_options(${target}
6355
INTERFACE
6456
${common_options}

0 commit comments

Comments
 (0)