Skip to content

Commit 8814295

Browse files
committed
CMake: set standard in specific toolchain files
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). Also providing C/C++ standard set functions per toolchain (we can refactor these to provide common or in util)
1 parent 6ee779b commit 8814295

File tree

5 files changed

+37
-23
lines changed

5 files changed

+37
-23
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ include(${MBED_CONFIG_PATH}/mbed_config.cmake)
2121
include(${MBED_ROOT}/cmake/core.cmake)
2222
mbed_set_cpu_core_options(mbed-os ${MBED_TOOLCHAIN})
2323

24-
set(CMAKE_TOOLCHAIN_FILE "${MBED_ROOT}/cmake/toolchain.cmake" CACHE INTERNAL "")
24+
# Set the toolchain file, do not include it as it's included by CMake on system level
25+
if(NOT CMAKE_TOOLCHAIN_FILE)
26+
set(CMAKE_TOOLCHAIN_FILE "${MBED_ROOT}/cmake/toolchain.cmake" CACHE INTERNAL "")
27+
endif()
28+
2529
include(${MBED_ROOT}/cmake/toolchains/${MBED_TOOLCHAIN}.cmake)
2630
enable_language(C CXX ASM)
2731
mbed_set_toolchain_options(mbed-os)

cmake/toolchain.cmake

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

43-
#include(${MBED_ROOT}/cmake/toolchains/${MBED_TOOLCHAIN}.cmake)
44-
45-
# Project setup
46-
#enable_language(C CXX ASM)
47-
4843
# Clear toolchains options for all languages as Mbed OS uses
4944
# different initialisation options (such as for optimization and debug symbols)
5045
set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "" FORCE)

cmake/toolchains/ARM.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ if(MBEDIDE)
1919
set_property(GLOBAL PROPERTY MBED_STUDIO_ARM_COMPILER "--ide=mbed")
2020
endif()
2121

22+
# Set the language standard to use per target
23+
function(mbed_set_language_standard target)
24+
set_target_properties(${target}
25+
PROPERTIES
26+
C_STANDARD 11
27+
C_STANDARD_REQUIRED YES
28+
C_EXTENSIONS YES
29+
)
30+
31+
set_target_properties(${target}
32+
PROPERTIES
33+
CXX_STANDARD 14
34+
CXX_STANDARD_REQUIRED YES
35+
CXX_EXTENSIONS YES
36+
)
37+
endfunction()
2238

2339
# Sets toolchain options
2440
function(mbed_set_toolchain_options target)

cmake/toolchains/GCC_ARM.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
1313
set(GCC_ELF2BIN "arm-none-eabi-objcopy")
1414
set_property(GLOBAL PROPERTY ELF2BIN ${GCC_ELF2BIN})
1515

16+
# Set the language standard to use per target
17+
function(mbed_set_language_standard target)
18+
set_target_properties(${target}
19+
PROPERTIES
20+
C_STANDARD 11
21+
C_STANDARD_REQUIRED YES
22+
C_EXTENSIONS YES
23+
)
24+
25+
set_target_properties(${target}
26+
PROPERTIES
27+
CXX_STANDARD 14
28+
CXX_STANDARD_REQUIRED YES
29+
CXX_EXTENSIONS YES
30+
)
31+
endfunction()
1632

1733
# Sets toolchain options
1834
function(mbed_set_toolchain_options target)

cmake/util.cmake

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,3 @@ function(mbed_add_cmake_directory_if_labels PREFIX)
1515
endif()
1616
endforeach()
1717
endfunction()
18-
19-
# Set the language standard to use per target
20-
function(mbed_set_language_standard target)
21-
set_target_properties(${target}
22-
PROPERTIES
23-
C_STANDARD 11
24-
C_STANDARD_REQUIRED YES
25-
C_EXTENSIONS YES
26-
)
27-
28-
set_target_properties(${target}
29-
PROPERTIES
30-
CXX_STANDARD 14
31-
CXX_STANDARD_REQUIRED YES
32-
CXX_EXTENSIONS YES
33-
)
34-
endfunction()

0 commit comments

Comments
 (0)