Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ elseif(CONFIG_SPEED_OPTIMIZATIONS)
elseif(CONFIG_SIZE_OPTIMIZATIONS)
set(OPTIMIZATION_FLAG ${OPTIMIZE_FOR_SIZE_FLAG}) # Default in kconfig
else()
assert(0 "Unreachable code. Expected optimization level to have been chosen. See Kconfig.zephyr")
message(FATAL_ERROR
"Unreachable code. Expected optimization level to have been chosen. See Kconfig.zephyr")
endif()

if(NOT CONFIG_ARCH_IS_SET)
Expand Down Expand Up @@ -247,7 +248,8 @@ if(CONFIG_CPP)
set(STD_CPP_DIALECT_FLAGS $<TARGET_PROPERTY:compiler-cpp,dialect_cpp2b>)
list(APPEND CMAKE_CXX_COMPILE_FEATURES ${compile_features_cpp20})
else()
assert(0 "Unreachable code. Expected C++ standard to have been chosen. See Kconfig.zephyr.")
message(FATAL_ERROR
"Unreachable code. Expected C++ standard to have been chosen. See Kconfig.zephyr.")
endif()
set(CMAKE_CXX_COMPILE_FEATURES ${CMAKE_CXX_COMPILE_FEATURES} PARENT_SCOPE)

Expand Down Expand Up @@ -955,7 +957,28 @@ if(CONFIG_USERSPACE)
endif()

get_property(CSTD GLOBAL PROPERTY CSTD)
set_ifndef(CSTD c99)
if(NOT DEFINED CSTD)
if(CONFIG_STD_C23)
set(CSTD c2x)
elseif(CONFIG_STD_C17)
set(CSTD c17)
elseif(CONFIG_STD_C11)
set(CSTD c11)
elseif(CONFIG_STD_C99)
set(CSTD c99)
elseif(CONFIG_STD_C90)
set(CSTD c90)
else()
message(FATAL_ERROR "Unreachable code. Expected C standard to have been chosen.")
endif()

if(CONFIG_GNU_C_EXTENSIONS)
string(REPLACE "c" "gnu" CSTD "${CSTD}")
endif()
else()
message(DEPRECATION
"Global CSTD property is deprecated, see Kconfig.zephyr for C Standard options.")
endif()

# @Intent: Obtain compiler specific flag for specifying the c standard
zephyr_compile_options(
Expand Down
78 changes: 78 additions & 0 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,84 @@ endmenu

menu "Compiler Options"

config REQUIRES_STD_C99
bool
help
Hidden option to select compiler support C99 standard or higher.

config REQUIRES_STD_C11
bool
select REQUIRES_STD_C99
help
Hidden option to select compiler support C11 standard or higher.

config REQUIRES_STD_C17
bool
select REQUIRES_STD_C11
help
Hidden option to select compiler support C17 standard or higher.

config REQUIRES_STD_C23
bool
select REQUIRES_STD_C17
help
Hidden option to select compiler support C23 standard or higher.

choice STD_C
prompt "C Standard"
default STD_C23 if REQUIRES_STD_C23
default STD_C17 if REQUIRES_STD_C17
default STD_C11 if REQUIRES_STD_C11
default STD_C99
help
C Standards.

config STD_C90
bool "C90"
depends on !REQUIRES_STD_C99
help
1989 C standard as completed in 1989 and ratified by ISO/IEC
as ISO/IEC 9899:1990. This version is known as "ANSI C".

config STD_C99
bool "C99"
depends on !REQUIRES_STD_C11
help
1999 C standard.

config STD_C11
bool "C11"
depends on !REQUIRES_STD_C17
help
2011 C standard.

config STD_C17
bool "C17"
depends on !REQUIRES_STD_C23
help
2017 C standard, addresses defects in C11 without introducing
new language features.

config STD_C23
bool "C23"
help
2023 C standard.

endchoice

config TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
bool
default y if "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "zephyr"
help
Hidden option to signal that toolchain supports GNU Extensions.

config GNU_C_EXTENSIONS
bool "GNU C Extensions"
depends on TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
help
Enable GNU C Extensions. GNU C provides several language features
not found in ISO standard C.

config CODING_GUIDELINE_CHECK
bool "Enforce coding guideline rules"
help
Expand Down
6 changes: 6 additions & 0 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ config ARCH_POSIX
select BARRIER_OPERATIONS_BUILTIN
# POSIX arch based targets get their memory cleared on entry by the host OS
select SKIP_BSS_CLEAR
# Override the C standard used for compilation to C 2011
# This is due to some tests using _Static_assert which is a 2011 feature, but
# otherwise relying on compilers supporting it also when set to C99.
# This was in general ok, but with some host compilers and C library versions
# it led to problems. So we override it to 2011 for the native targets.
select REQUIRES_STD_C11
help
POSIX (native) architecture

Expand Down
7 changes: 0 additions & 7 deletions arch/posix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,4 @@ if(NOT ${LLVM_SANITIZERS_ARG} STREQUAL "")
target_compile_options(native_simulator INTERFACE ${LLVM_SANITIZERS_ARG})
endif()

# Override the C standard used for compilation to C 2011
# This is due to some tests using _Static_assert which is a 2011 feature, but
# otherwise relying on compilers supporting it also when set to C99.
# This was in general ok, but with some host compilers and C library versions
# it led to problems. So we override it to 2011 for the native targets.
set_property(GLOBAL PROPERTY CSTD c11)

add_subdirectory(core)
2 changes: 0 additions & 2 deletions cmake/compiler/arcmwdt/compiler_flags.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
set_property(GLOBAL PROPERTY CSTD gnu99)

# List the warnings that are not supported for C++ compilations
list(APPEND CXX_EXCLUDED_OPTIONS
-Werror=implicit-int
Expand Down
4 changes: 4 additions & 0 deletions cmake/toolchain/arcmwdt/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
config TOOLCHAIN_ARCMWDT_SUPPORTS_THREAD_LOCAL_STORAGE
def_bool y
select TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE

config TOOLCHAIN_ARCMWDT_SUPPORTS_GNU_EXTENSIONS
def_bool y
select TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
4 changes: 4 additions & 0 deletions cmake/toolchain/armclang/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ config ARMCLANG_STD_LIBC
not provided by ARM Compiler standard libraries.

endchoice

config TOOLCHAIN_ARMCLANG_SUPPORTS_GNU_EXTENSIONS
def_bool y
select TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
7 changes: 7 additions & 0 deletions cmake/toolchain/cross-compile/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ config TOOLCHAIN_CROSS_COMPILE_SUPPORTS_THREAD_LOCAL_STORAGE
help
Set this if the cross-compile toolchain being used for the build
supports thread local storage.

config TOOLCHAIN_CROSS_COMPILE_SUPPORTS_GNU_EXTENSIONS
bool "Cross-compile toolchain supports GNU Extensions"
select TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
help
Set this if the cross-compile toolchain being used for the build
supports GNU Extensions.
4 changes: 4 additions & 0 deletions cmake/toolchain/gnuarmemb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ config TOOLCHAIN_GNUARMEMB
def_bool y
select HAS_NEWLIB_LIBC_NANO
select NEWLIB_LIBC_SUPPORTED

config TOOLCHAIN_GNUARMEMB_SUPPORTS_GNU_EXTENSIONS
def_bool y
select TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
6 changes: 6 additions & 0 deletions cmake/toolchain/host/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) 2024 Basalte bv
# SPDX-License-Identifier: Apache-2.0

config TOOLCHAIN_HOST_SUPPORTS_GNU_EXTENSIONS
def_bool y
select TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
4 changes: 4 additions & 0 deletions cmake/toolchain/llvm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ config TOOLCHAIN_LLVM_SUPPORTS_THREAD_LOCAL_STORAGE
depends on RISCV
def_bool y
select TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE

config TOOLCHAIN_LLVM_SUPPORTS_GNU_EXTENSIONS
def_bool y
select TOOLCHAIN_SUPPORTS_GNU_EXTENSIONS
6 changes: 6 additions & 0 deletions doc/releases/release-notes-3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ Build system and Infrastructure

* CI-enabled blackbox tests were added in order to verify correctness of the vast majority of Twister flags.

* Compiler

* Deprecated the global CSTD cmake property in favor of the :kconfig:option:`CONFIG_STD_C`
choice to select the C Standard version. Additionally subsystems can select a minimum
required C Standard version, with for example :kconfig:option:`CONFIG_REQUIRES_STD_C11`.

Drivers and Sensors
*******************

Expand Down
21 changes: 15 additions & 6 deletions tests/subsys/bindesc/definition/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,23 @@ tests:
- qemu_riscv32e
- qemu_riscv64
bindesc.define.c99:
extra_args: CSTD="c99"
extra_configs:
- CONFIG_STD_C99=y
bindesc.define.c11:
extra_args: CSTD="c11"
extra_configs:
- CONFIG_STD_C11=y
bindesc.define.c17:
extra_args: CSTD="c17"
extra_configs:
- CONFIG_STD_C17=y
bindesc.define.gnu99:
extra_args: CSTD="gnu99"
extra_configs:
- CONFIG_STD_C99=y
- CONFIG_GNU_C_EXTENSIONS=y
bindesc.define.gnu11:
extra_args: CSTD="gnu11"
extra_configs:
- CONFIG_STD_C11=y
- CONFIG_GNU_C_EXTENSIONS=y
bindesc.define.gnu17:
extra_args: CSTD="gnu17"
extra_configs:
- CONFIG_STD_C17=y
- CONFIG_GNU_C_EXTENSIONS=y