Skip to content

Commit 955992e

Browse files
committed
CMake: Set language std per target using properties
1 parent 28d5e65 commit 955992e

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mbed_set_cpu_core_options(mbed-os ${MBED_TOOLCHAIN})
2020

2121
include(${MBED_ROOT}/cmake/toolchain.cmake)
2222
mbed_set_toolchain_options(mbed-os)
23+
mbed_set_language_standard(mbed-os)
2324

2425
include(${MBED_ROOT}/cmake/profile.cmake)
2526
mbed_set_profile_options(mbed-os ${MBED_TOOLCHAIN})
@@ -57,6 +58,13 @@ add_subdirectory(storage)
5758
add_subdirectory(targets)
5859

5960

61+
#
62+
# Configures the application
63+
#
64+
function(mbed_os_configure_app_target target)
65+
mbed_set_language_standard(${target})
66+
endfunction()
67+
6068
#
6169
# Specifies linker script used for linking `target`.
6270
#

cmake/profiles/debug.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function(mbed_set_profile_options target mbed_toolchain)
88
if(${mbed_toolchain} STREQUAL "GCC_ARM")
99
list(APPEND c_compile_options
1010
"-c"
11-
"-std=gnu11"
1211
"-Og"
1312
)
1413
target_compile_options(${target}
@@ -18,7 +17,6 @@ function(mbed_set_profile_options target mbed_toolchain)
1817

1918
list(APPEND cxx_compile_options
2019
"-c"
21-
"-std=gnu++14"
2220
"-fno-rtti"
2321
"-Wvla"
2422
"-Og"
@@ -51,7 +49,6 @@ function(mbed_set_profile_options target mbed_toolchain)
5149
)
5250
elseif(${mbed_toolchain} STREQUAL "ARM")
5351
list(APPEND c_compile_options
54-
"-std=gnu11"
5552
"-O1"
5653
)
5754
target_compile_options(${target}
@@ -60,7 +57,6 @@ function(mbed_set_profile_options target mbed_toolchain)
6057
)
6158

6259
list(APPEND cxx_compile_options
63-
"-std=gnu++14"
6460
"-fno-rtti"
6561
"-fno-c++-static-destructors"
6662
"-O1"

cmake/profiles/develop.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function(mbed_set_profile_options target mbed_toolchain)
88
if(${mbed_toolchain} STREQUAL "GCC_ARM")
99
list(APPEND c_compile_options
1010
"-c"
11-
"-std=gnu11"
1211
"-Os"
1312
)
1413
target_compile_options(${target}
@@ -17,7 +16,6 @@ function(mbed_set_profile_options target mbed_toolchain)
1716
)
1817

1918
list(APPEND cxx_compile_options
20-
"-std=gnu++14"
2119
"-fno-rtti"
2220
"-Wvla"
2321
"-Os"
@@ -49,7 +47,6 @@ function(mbed_set_profile_options target mbed_toolchain)
4947
)
5048
elseif(${mbed_toolchain} STREQUAL "ARM")
5149
list(APPEND c_compile_options
52-
"-std=gnu11"
5350
"-Os"
5451
)
5552
target_compile_options(${target}
@@ -58,7 +55,6 @@ function(mbed_set_profile_options target mbed_toolchain)
5855
)
5956

6057
list(APPEND cxx_compile_options
61-
"-std=gnu++14"
6258
"-fno-rtti"
6359
"-fno-c++-static-destructors"
6460
"-Os"

cmake/profiles/release.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ function(mbed_set_profile_options target mbed_toolchain)
88
if(${mbed_toolchain} STREQUAL "GCC_ARM")
99
list(APPEND c_compile_options
1010
"-c"
11-
"-std=gnu11"
1211
"-Os"
1312
)
1413
target_compile_options(${target}
@@ -18,7 +17,6 @@ function(mbed_set_profile_options target mbed_toolchain)
1817

1918
list(APPEND cxx_compile_options
2019
"-c"
21-
"-std=gnu++14"
2220
"-fno-rtti"
2321
"-Wvla"
2422
"-Os"
@@ -51,7 +49,6 @@ function(mbed_set_profile_options target mbed_toolchain)
5149
)
5250
elseif(${mbed_toolchain} STREQUAL "ARM")
5351
list(APPEND c_compile_options
54-
"-std=gnu11"
5552
"-Oz"
5653
)
5754
target_compile_options(${target}
@@ -60,7 +57,6 @@ function(mbed_set_profile_options target mbed_toolchain)
6057
)
6158

6259
list(APPEND cxx_compile_options
63-
"-std=gnu++14"
6460
"-fno-rtti"
6561
"-fno-c++-static-destructors"
6662
"-Oz"

cmake/toolchain.cmake

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ elseif (MBED_CPU_CORE STREQUAL Cortex-M7FD)
4141
endif()
4242

4343

44+
4445
include(${MBED_ROOT}/cmake/toolchains/${MBED_TOOLCHAIN}.cmake)
4546

4647
# Compiler setup
@@ -52,6 +53,23 @@ set(CMAKE_CXX_COMPILER_WORKS TRUE)
5253
# Project setup
5354
enable_language(C CXX ASM)
5455

56+
# Set the language standard to use per target
57+
function(mbed_set_language_standard target)
58+
set_target_properties(${target}
59+
PROPERTIES
60+
C_STANDARD 11
61+
C_STANDARD_REQUIRED YES
62+
C_EXTENSIONS YES
63+
)
64+
65+
set_target_properties(${target}
66+
PROPERTIES
67+
CXX_STANDARD 14
68+
CXX_STANDARD_REQUIRED YES
69+
CXX_EXTENSIONS YES
70+
)
71+
endfunction()
72+
5573
# Clear toolchains options for all languages as Mbed OS uses
5674
# different initialisation options (such as for optimization and debug symbols)
5775
set(CMAKE_C_FLAGS_DEBUG "" CACHE STRING "" FORCE)

0 commit comments

Comments
 (0)