Skip to content

Commit f5bc7b9

Browse files
0xc0170hugueskamba
authored andcommitted
CMake: use CMAKE_TOOLCHAIN_FILE
We should define CMAKE_TOOLCHAIN_FILE (as we are providing Mbed OS toolchain file). This fixes also the issue we had with Unix makefiles where application would be without response files. For more details, see https://gitlab.kitware.com/cmake/cmake/-/issues/21104 As the Mbed OS toolchain file is included by CMake, we need to have enabling language in the main CMake (can be executed only once).
1 parent 158dad7 commit f5bc7b9

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

CMakeLists.txt

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,29 @@ if(POLICY CMP0076)
1010
cmake_policy(SET CMP0076 NEW)
1111
endif()
1212

13-
# Create Mbed OS library
14-
add_library(mbed-os OBJECT)
15-
1613
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
1714

15+
# Set default toolchain file
16+
if(NOT CMAKE_TOOLCHAIN_FILE)
17+
set(CMAKE_TOOLCHAIN_FILE "${MBED_ROOT}/cmake/toolchain.cmake" CACHE INTERNAL "")
18+
endif()
19+
20+
# Toolchain setup
21+
include(${MBED_ROOT}/cmake/toolchains/${MBED_TOOLCHAIN}.cmake)
22+
enable_language(C CXX ASM)
23+
1824
include(${MBED_ROOT}/cmake/core.cmake)
19-
mbed_set_cpu_core_options(mbed-os ${MBED_TOOLCHAIN})
25+
include(${MBED_ROOT}/cmake/util.cmake)
26+
include(${MBED_ROOT}/cmake/profile.cmake)
2027

21-
include(${MBED_ROOT}/cmake/toolchain.cmake)
28+
# Create Mbed OS library
29+
add_library(mbed-os OBJECT)
30+
31+
mbed_set_cpu_core_options(mbed-os ${MBED_TOOLCHAIN})
2232
mbed_set_toolchain_options(mbed-os)
2333
mbed_set_language_standard(mbed-os)
24-
25-
include(${MBED_ROOT}/cmake/profile.cmake)
2634
mbed_set_profile_options(mbed-os ${MBED_TOOLCHAIN})
2735

28-
include(${MBED_ROOT}/cmake/util.cmake)
29-
3036
set_target_properties(mbed-os
3137
PROPERTIES
3238
MBED_TARGET_LABELS "${MBED_TARGET_LABELS}"

cmake/toolchain.cmake

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,12 @@ elseif (MBED_CPU_CORE STREQUAL Cortex-M7FD)
4040
set(CMAKE_SYSTEM_PROCESSOR cortex-m7)
4141
endif()
4242

43-
44-
45-
include(${MBED_ROOT}/cmake/toolchains/${MBED_TOOLCHAIN}.cmake)
46-
4743
# Compiler setup
4844
set(CMAKE_SYSTEM_NAME Generic)
4945
set(CMAKE_CROSSCOMPILING TRUE)
5046
set(CMAKE_C_COMPILER_WORKS TRUE)
5147
set(CMAKE_CXX_COMPILER_WORKS TRUE)
5248

53-
# Project setup
54-
enable_language(C CXX ASM)
55-
5649
# Set the language standard to use per target
5750
function(mbed_set_language_standard target)
5851
set_target_properties(${target}

0 commit comments

Comments
 (0)