Browse Source

cmake: xcc/xt-clang: fix for proper system include paths

Although xt-clang is based on clang, for some reason, it still
lists xcc system include path as the first search path (e.g.
for stddef.h), and the clang system include path as last. This
creates a big issue when the code starts to use any standards
past C89 (since xcc is based on GCC 4.2). We can use compiler
property nostdin_include to add -isystem to compiler options.
However, some modules (e.g. picolibcs) somehow ignore this.
So we also need to forcibly do add_compile_options() to make
sure the clang system include path is placed before the xcc
system include path.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
pull/91480/head
Daniel Leung 1 month ago committed by Dan Kalowsky
parent
commit
146e22fca4
  1. 17
      cmake/compiler/xcc/target.cmake
  2. 21
      cmake/compiler/xt-clang/compiler_flags.cmake

17
cmake/compiler/xcc/target.cmake

@ -37,7 +37,22 @@ foreach(file_name include/stddef.h include-fixed/limits.h) @@ -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

21
cmake/compiler/xt-clang/compiler_flags.cmake

@ -2,25 +2,10 @@ @@ -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:

Loading…
Cancel
Save