Skip to content

Commit 146e22f

Browse files
dcpleungdkalowsk
authored andcommitted
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>
1 parent f7b3143 commit 146e22f

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

cmake/compiler/xcc/target.cmake

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,22 @@ foreach(file_name include/stddef.h include-fixed/limits.h)
3737
get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY)
3838
string(REGEX REPLACE "\n" "" _OUTPUT "${_OUTPUT}")
3939

40-
list(APPEND NOSTDINC ${_OUTPUT})
40+
# Need to make sure the path exists before we add it to ${NOSTDINC}.
41+
# For example, include-fixed is in xcc but not xt-clang.
42+
if(EXISTS "${_OUTPUT}")
43+
list(APPEND NOSTDINC ${_OUTPUT})
44+
45+
if("${ZEPHYR_TOOLCHAIN_VARIANT}" STREQUAL "xt-clang")
46+
# This forcibly adds -isystem so that the xt-clang system
47+
# include paths are before the xcc include paths.
48+
# For some reason, xt-clang places xcc include paths before
49+
# xt-clang ones so we need to force it.
50+
#
51+
# Some modules ignores the compiler property nostdinc_include
52+
# so we need to make sure -isystem is used there.
53+
add_compile_options(-isystem ${_OUTPUT})
54+
endif()
55+
endif()
4156
endforeach()
4257

4358
# This libgcc code is partially duplicated in compiler/*/target.cmake

cmake/compiler/xt-clang/compiler_flags.cmake

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,10 @@
22

33
include(${ZEPHYR_BASE}/cmake/compiler/clang/compiler_flags.cmake)
44

5-
# nostdinc_include contains path to llvm headers and also relative
6-
# path of "include-fixed".
7-
# Clear "nostdinc" and nostdinc_include
5+
# nostdinc needs to be cleared as it is needed for xtensa/config/core.h.
6+
# nostdinc_include contains path to llvm headers.
87
set_compiler_property(PROPERTY nostdinc)
9-
set_compiler_property(PROPERTY nostdinc_include)
10-
11-
# For C++ code, re-add the standard includes directory which was
12-
# cleared up from nostdinc_inlcude in above lines with no
13-
# "include-fixed" this time"
14-
if(CONFIG_CPP)
15-
execute_process(
16-
COMMAND ${CMAKE_C_COMPILER} --print-file-name=include/stddef.h
17-
OUTPUT_VARIABLE _OUTPUT
18-
COMMAND_ERROR_IS_FATAL ANY
19-
)
20-
get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY)
21-
string(REGEX REPLACE "\n" "" _OUTPUT "${_OUTPUT}")
22-
set_compiler_property(PROPERTY nostdinc_include "${_OUTPUT}")
23-
endif()
8+
set_compiler_property(APPEND PROPERTY nostdinc_include ${NOSTDINC})
249

2510
if($ENV{XCC_NO_G_FLAG})
2611
# Older xcc/clang cannot use "-g" due to this bug:

0 commit comments

Comments
 (0)