Skip to content

Commit 78be77e

Browse files
Change toolchain file to load core and toolchain options *before* compilers are loaded.
1 parent d2adc9e commit 78be77e

26 files changed

+340
-663
lines changed

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# This is the boilerplate for Mbed OS
55

6-
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
6+
cmake_minimum_required(VERSION 3.16.0 FATAL_ERROR)
77

88
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
99
include(${MBED_PATH}/tools/cmake/core.cmake)
@@ -55,7 +55,6 @@ endif()
5555

5656
mbed_set_cpu_core_definitions(mbed-core)
5757
if(${MBED_TOOLCHAIN_FILE_USED})
58-
mbed_set_cpu_core_options(mbed-core ${MBED_TOOLCHAIN})
5958
mbed_set_toolchain_options(mbed-core)
6059
mbed_set_profile_options(mbed-core ${MBED_TOOLCHAIN})
6160
mbed_set_c_lib(mbed-core ${MBED_C_LIB})

tools/cmake/app.cmake

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,11 @@ endif()
99

1010
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
1111

12-
# Set default toolchain file
13-
if(NOT CMAKE_TOOLCHAIN_FILE OR MBED_TOOLCHAIN_FILE_USED)
14-
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")
12+
# Load toolchain file
13+
set(MBED_TOOLCHAIN_FILE_USED TRUE CACHE INTERNAL "")
14+
include(${MBED_PATH}/tools/cmake/toolchain.cmake)
1515

16-
set(CMAKE_TOOLCHAIN_FILE "${MBED_PATH}/tools/cmake/toolchain.cmake" CACHE INTERNAL "")
17-
18-
# Specify locations for toolchains and generic options
19-
include(${MBED_PATH}/tools/cmake/toolchains/${MBED_TOOLCHAIN}.cmake)
20-
21-
# Specify available build profiles and add options for the selected build profile
22-
include(${MBED_PATH}/tools/cmake/profile.cmake)
23-
endif()
16+
# Specify available build profiles and add options for the selected build profile
17+
include(${MBED_PATH}/tools/cmake/profile.cmake)
2418

2519
enable_language(C CXX ASM)

tools/cmake/core.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
include(${MBED_PATH}/tools/cmake/cores/${MBED_CPU_CORE}.cmake)

tools/cmake/cores/Cortex-A9.cmake

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,26 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
# Sets cpu core options
5-
function(mbed_set_cpu_core_options target mbed_toolchain)
6-
if(${mbed_toolchain} STREQUAL "GCC_ARM")
7-
list(APPEND common_toolchain_options
8-
"-mthumb-interwork"
9-
"-marm"
10-
"-march=armv7-a"
11-
"-mfpu=vfpv3"
12-
"-mfloat-abi=hard"
13-
"-mno-unaligned-access"
14-
)
15-
16-
target_compile_options(${target}
17-
INTERFACE
18-
${common_toolchain_options}
19-
)
20-
21-
target_link_options(${target}
22-
INTERFACE
23-
${common_toolchain_options}
24-
)
25-
elseif(${mbed_toolchain} STREQUAL "ARM")
26-
list(APPEND compile_options
27-
"-mcpu=cortex-a9"
28-
)
29-
30-
target_compile_options(${target}
31-
INTERFACE
32-
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
33-
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
34-
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-A9>
35-
)
36-
37-
target_link_options(${target}
38-
INTERFACE
39-
"--cpu=Cortex-A9"
40-
)
41-
endif()
42-
endfunction()
4+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
5+
list(APPEND common_options
6+
"-mthumb-interwork"
7+
"-marm"
8+
"-march=armv7-a"
9+
"-mfpu=vfpv3"
10+
"-mfloat-abi=hard"
11+
"-mno-unaligned-access"
12+
)
13+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
14+
list(APPEND c_cxx_compile_options
15+
"-mcpu=cortex-a9"
16+
)
17+
list(APPEND asm_compile_options
18+
"-mcpu=Cortex-A9"
19+
)
20+
list(APPEND link_options
21+
"--cpu=Cortex-A9"
22+
)
23+
endif()
4324

4425
function(mbed_set_cpu_core_definitions target)
4526
target_compile_definitions(${target}

tools/cmake/cores/Cortex-M0+.cmake

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,22 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Sets cpu core options
5-
function(mbed_set_cpu_core_options target mbed_toolchain)
6-
if(${mbed_toolchain} STREQUAL "GCC_ARM")
7-
list(APPEND common_toolchain_options
8-
"-mthumb"
9-
"-mcpu=cortex-m0plus"
5+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
6+
list(APPEND common_options
7+
"-mthumb"
8+
"-mcpu=cortex-m0plus"
109
)
11-
12-
target_compile_options(${target}
13-
INTERFACE
14-
${common_toolchain_options}
15-
)
16-
17-
target_link_options(${target}
18-
INTERFACE
19-
${common_toolchain_options}
10+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
11+
list(APPEND c_cxx_compile_options
12+
"-mcpu=cortex-m0plus"
2013
)
21-
elseif(${mbed_toolchain} STREQUAL "ARM")
22-
list(APPEND compile_options
23-
"-mcpu=cortex-m0plus"
14+
list(APPEND asm_compile_options
15+
"-mcpu=Cortex-M0plus"
2416
)
25-
26-
target_compile_options(${target}
27-
INTERFACE
28-
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
29-
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
30-
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M0plus>
17+
list(APPEND link_options
18+
"--cpu=Cortex-M0plus"
3119
)
32-
33-
target_link_options(${target}
34-
INTERFACE
35-
"--cpu=Cortex-M0plus"
36-
)
37-
endif()
38-
endfunction()
20+
endif()
3921

4022
function(mbed_set_cpu_core_definitions target)
4123
target_compile_definitions(${target}

tools/cmake/cores/Cortex-M0.cmake

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,21 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Sets cpu core options
5-
function(mbed_set_cpu_core_options target mbed_toolchain)
6-
if(${mbed_toolchain} STREQUAL "GCC_ARM")
7-
list(APPEND common_toolchain_options
8-
"-mthumb"
9-
)
10-
11-
target_compile_options(${target}
12-
INTERFACE
13-
${common_toolchain_options}
14-
)
15-
16-
target_link_options(${target}
17-
INTERFACE
18-
${common_toolchain_options}
19-
)
20-
elseif(${mbed_toolchain} STREQUAL "ARM")
21-
list(APPEND options
22-
"-mcpu=cortex-m0"
23-
)
24-
25-
target_compile_options(${target}
26-
INTERFACE
27-
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
28-
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
29-
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M0>
30-
)
31-
32-
target_link_options(${target}
33-
INTERFACE
34-
"-cpu=Cortex-M0"
35-
)
36-
endif()
37-
endfunction()
5+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
6+
list(APPEND common_options
7+
"-mthumb"
8+
)
9+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
10+
list(APPEND c_cxx_compile_options
11+
"-mcpu=cortex-m0"
12+
)
13+
list(APPEND asm_compile_options
14+
"-mcpu=Cortex-M0"
15+
)
16+
list(APPEND link_options
17+
"--cpu=Cortex-M0"
18+
)
19+
endif()
3820

3921
function(mbed_set_cpu_core_definitions target)
4022
target_compile_definitions(${target}

tools/cmake/cores/Cortex-M1.cmake

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,20 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Sets cpu core options
5-
function(mbed_set_cpu_core_options target mbed_toolchain)
6-
if(${mbed_toolchain} STREQUAL "GCC_ARM")
7-
list(APPEND common_toolchain_options
8-
"-mthumb"
5+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
6+
list(APPEND common_options
7+
"-mthumb")
8+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
9+
list(APPEND c_cxx_compile_options
10+
"-mcpu=cortex-m1"
911
)
10-
11-
target_compile_options(${target}
12-
INTERFACE
13-
${common_toolchain_options}
14-
)
15-
16-
target_link_options(${target}
17-
INTERFACE
18-
${common_toolchain_options}
19-
)
20-
elseif(${mbed_toolchain} STREQUAL "ARM")
21-
list(APPEND options
22-
"-mcpu=cortex-m1"
12+
list(APPEND asm_compile_options
13+
"-mcpu=Cortex-M1"
2314
)
24-
25-
target_compile_options(${target}
26-
INTERFACE
27-
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
28-
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
29-
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M1>
30-
)
31-
32-
target_link_options(${target}
33-
INTERFACE
34-
"--cpu=Cortex-M1"
15+
list(APPEND link_options
16+
"--cpu=Cortex-M1"
3517
)
36-
endif()
37-
endfunction()
18+
endif()
3819

3920
function(mbed_set_cpu_core_definitions target)
4021
target_compile_definitions(${target}

tools/cmake/cores/Cortex-M23-NS.cmake

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,22 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Sets cpu core options
5-
function(mbed_set_cpu_core_options target mbed_toolchain)
6-
if(${mbed_toolchain} STREQUAL "GCC_ARM")
7-
list(APPEND common_toolchain_options
8-
"-mthumb"
5+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
6+
list(APPEND common_options
7+
"-mthumb"
98
)
10-
11-
target_compile_options(${target}
12-
INTERFACE
13-
${common_toolchain_options}
14-
)
15-
16-
target_link_options(${target}
17-
INTERFACE
18-
${common_toolchain_options}
9+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
10+
list(APPEND c_cxx_compile_options
11+
"-mcpu=cortex-m23"
1912
)
20-
elseif(${mbed_toolchain} STREQUAL "ARM")
21-
list(APPEND compile_options
22-
"-mcpu=cortex-m23"
13+
list(APPEND asm_compile_options
14+
"-mcpu=Cortex-M23"
2315
)
24-
25-
target_compile_options(${target}
26-
INTERFACE
27-
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
28-
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
29-
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M23>
16+
list(APPEND link_options
17+
"--cpu=Cortex-M23"
3018
)
19+
endif()
3120

32-
target_link_options(${target}
33-
INTERFACE
34-
"--cpu=Cortex-M23"
35-
)
36-
endif()
37-
endfunction()
3821

3922
function(mbed_set_cpu_core_definitions target)
4023
target_compile_definitions(${target}

tools/cmake/cores/Cortex-M23.cmake

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,22 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Sets cpu core options
5-
function(mbed_set_cpu_core_options target mbed_toolchain)
6-
if(${mbed_toolchain} STREQUAL "GCC_ARM")
7-
list(APPEND common_toolchain_options
8-
"-mthumb"
9-
)
10-
11-
target_compile_options(${target}
12-
INTERFACE
13-
${common_toolchain_options}
14-
)
15-
16-
target_link_options(${target}
17-
INTERFACE
18-
${common_toolchain_options}
19-
)
20-
elseif(${mbed_toolchain} STREQUAL "ARM")
21-
list(APPEND compile_options
22-
"-mcpu=cortex-m23"
23-
)
24-
25-
target_compile_options(${target}
26-
INTERFACE
27-
$<$<COMPILE_LANGUAGE:C>:${compile_options}>
28-
$<$<COMPILE_LANGUAGE:CXX>:${compile_options}>
29-
$<$<COMPILE_LANGUAGE:ASM>:-mcpu=Cortex-M23>
30-
)
5+
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
6+
list(APPEND common_options
7+
"-mthumb"
8+
)
9+
elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
10+
list(APPEND c_cxx_compile_options
11+
"-mcpu=cortex-m23"
12+
)
13+
list(APPEND asm_compile_options
14+
"-mcpu=Cortex-M23"
15+
)
16+
list(APPEND link_options
17+
"--cpu=Cortex-M23"
18+
)
19+
endif()
3120

32-
target_link_options(${target}
33-
INTERFACE
34-
"--cpu=Cortex-M23"
35-
)
36-
endif()
37-
endfunction()
3821

3922
function(mbed_set_cpu_core_definitions target)
4023
target_compile_definitions(${target}

0 commit comments

Comments
 (0)