Skip to content

Commit

Permalink
kconfig: Add symbols for C standard
Browse files Browse the repository at this point in the history
Add symbols to select a C standard. Next to an option, hidden symbols
are available to select the minimum.
This allows subsystems or modules to select the least compliant C
standard supported.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
  • Loading branch information
pdgendt authored and fabiobaltieri committed Apr 25, 2024
1 parent 32c9614 commit 86b721c
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,24 @@ 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()
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
65 changes: 65 additions & 0 deletions Kconfig.zephyr
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,71 @@ 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 CODING_GUIDELINE_CHECK
bool "Enforce coding guideline rules"
help
Expand Down

0 comments on commit 86b721c

Please sign in to comment.