diff --git a/CMakeLists.txt b/CMakeLists.txt index 2170567d3df51..c5c9739ccd878 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,8 +348,6 @@ endif() zephyr_cc_option_ifdef(CONFIG_STACK_USAGE -fstack-usage) -zephyr_system_include_directories(${NOSTDINC}) - # Force an error when things like SYS_INIT(foo, ...) occur with a missing header. zephyr_cc_option(-Werror=implicit-int) diff --git a/cmake/compiler/gcc/target_baremetal.cmake b/cmake/compiler/gcc/target_baremetal.cmake index dcd8c852f12a0..0ed28e6f89530 100644 --- a/cmake/compiler/gcc/target_baremetal.cmake +++ b/cmake/compiler/gcc/target_baremetal.cmake @@ -5,6 +5,7 @@ macro(toolchain_cc_nostdinc) NOT COMPILER STREQUAL "xcc" AND NOT CONFIG_NATIVE_APPLICATION) zephyr_compile_options( -nostdinc) + zephyr_system_include_directories(${NOSTDINC}) endif() endmacro() diff --git a/lib/libc/newlib/CMakeLists.txt b/lib/libc/newlib/CMakeLists.txt index fd13e7ebc018f..d97e3a38f96b5 100644 --- a/lib/libc/newlib/CMakeLists.txt +++ b/lib/libc/newlib/CMakeLists.txt @@ -7,8 +7,12 @@ zephyr_library_sources(libc-hooks.c) # unable to, it will be up to the user to specify LIBC_*_DIR vars to # point to a newlib implementation. +# We need to make sure this is included before the standard system +# header include path's since we build with -ffreestanding and need +# our libc headers to be picked instead of the toolchain's ffreestanding +# headers. if(LIBC_INCLUDE_DIR) - zephyr_include_directories(${LIBC_INCLUDE_DIR}) + zephyr_system_include_directories(${LIBC_INCLUDE_DIR}) endif() if(LIBC_LIBRARY_DIR)