diff --git a/cmake/compiler/xcc/target.cmake b/cmake/compiler/xcc/target.cmake index f9e9c721a15..56d15451d3d 100644 --- a/cmake/compiler/xcc/target.cmake +++ b/cmake/compiler/xcc/target.cmake @@ -37,7 +37,22 @@ foreach(file_name include/stddef.h include-fixed/limits.h) get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY) string(REGEX REPLACE "\n" "" _OUTPUT "${_OUTPUT}") - list(APPEND NOSTDINC ${_OUTPUT}) + # Need to make sure the path exists before we add it to ${NOSTDINC}. + # For example, include-fixed is in xcc but not xt-clang. + if(EXISTS "${_OUTPUT}") + list(APPEND NOSTDINC ${_OUTPUT}) + + if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "xt-clang") + # This forcibly adds -isystem so that the xt-clang system + # include paths are before the xcc include paths. + # For some reason, xt-clang places xcc include paths before + # xt-clang ones so we need to force it. + # + # Some modules ignores the compiler property nostdinc_include + # so we need to make sure -isystem is used there. + add_compile_options(-isystem ${_OUTPUT}) + endif() + endif() endforeach() # This libgcc code is partially duplicated in compiler/*/target.cmake diff --git a/cmake/compiler/xt-clang/compiler_flags.cmake b/cmake/compiler/xt-clang/compiler_flags.cmake index c70832ebc0f..54451194c6d 100644 --- a/cmake/compiler/xt-clang/compiler_flags.cmake +++ b/cmake/compiler/xt-clang/compiler_flags.cmake @@ -2,25 +2,10 @@ include(${ZEPHYR_BASE}/cmake/compiler/clang/compiler_flags.cmake) -# nostdinc_include contains path to llvm headers and also relative -# path of "include-fixed". -# Clear "nostdinc" and nostdinc_include +# nostdinc needs to be cleared as it is needed for xtensa/config/core.h. +# nostdinc_include contains path to llvm headers. set_compiler_property(PROPERTY nostdinc) -set_compiler_property(PROPERTY nostdinc_include) - -# For C++ code, re-add the standard includes directory which was -# cleared up from nostdinc_inlcude in above lines with no -# "include-fixed" this time" -if(CONFIG_CPP) - execute_process( - COMMAND ${CMAKE_C_COMPILER} --print-file-name=include/stddef.h - OUTPUT_VARIABLE _OUTPUT - COMMAND_ERROR_IS_FATAL ANY - ) - get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY) - string(REGEX REPLACE "\n" "" _OUTPUT "${_OUTPUT}") - set_compiler_property(PROPERTY nostdinc_include "${_OUTPUT}") -endif() +set_compiler_property(APPEND PROPERTY nostdinc_include ${NOSTDINC}) if($ENV{XCC_NO_G_FLAG}) # Older xcc/clang cannot use "-g" due to this bug: