From 294939a31ed82d320cb534e86bd73194c2dd7bc7 Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Tue, 7 May 2024 15:44:30 +0200 Subject: [PATCH] cmake: Set C compile features early for modules If modules require C compiler features, these need to be set before calling add_subdirectory. Signed-off-by: Pieter De Gendt --- CMakeLists.txt | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad65b6a1d1f..b589ac43159 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,6 +219,26 @@ if(CONFIG_LTO) add_link_options($) endif() +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() + +list(APPEND CMAKE_C_COMPILE_FEATURES ${compile_features_${CSTD}}) + # @Intent: Obtain compiler specific flags related to C++ that are not influenced by kconfig zephyr_compile_options($<$:$>) @@ -956,35 +976,19 @@ if(CONFIG_USERSPACE) set(PROCESS_GPERF ${ZEPHYR_BASE}/scripts/build/process_gperf.py) endif() -get_property(CSTD GLOBAL PROPERTY CSTD) -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() +get_property(GLOBAL_CSTD GLOBAL PROPERTY CSTD) +if(DEFINED GLOBAL_CSTD) message(DEPRECATION "Global CSTD property is deprecated, see Kconfig.zephyr for C Standard options.") + set(CSTD ${GLOBAL_CSTD}) + list(APPEND CMAKE_C_COMPILE_FEATURES ${compile_features_${CSTD}}) endif() # @Intent: Obtain compiler specific flag for specifying the c standard zephyr_compile_options( $<$:$${CSTD}> ) -set(CMAKE_C_COMPILE_FEATURES ${compile_features_${CSTD}} PARENT_SCOPE) +set(CMAKE_C_COMPILE_FEATURES ${CMAKE_C_COMPILE_FEATURES} PARENT_SCOPE) # @Intent: Configure linker scripts, i.e. generate linker scripts with variables substituted toolchain_ld_configure_files()