Add sysroot_include_flags to enable yocto sysroots
GCC and clang handle system paths and therefore sysroots very specifically. They include them strictly after any user provided includes.
We can see this for a simple compile test.
austin@localhost /tmp/compiletest $ ls a.out foo.cc stdio.h
austin@localhost /tmp/compiletest $ cat foo.cc
int main(int argc, const char *const * argv) { printf("Hello, World!\n"); return 0; }
When we then compile with -v, clang (and gcc) will report what they did.
austin[264996] aschuh-3950x /tmp/compiletest $ clang -v -isystem . foo.cc Debian clang version 14.0.6 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: .;@m64 Found CUDA installation: /usr/lib/cuda, version "/usr/lib/llvm-14/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name foo.cc -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/tmp/compiletest -resource-dir /usr/lib/llvm-14/lib/clang/14.0.6 -isystem . -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir=/tmp/compiletest -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/foo-38bead.o -x c++ foo.cc clang -cc1 version 14.0.6 based upon LLVM 14.0.6 default target x86_64-pc-linux-gnu ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include" ignoring nonexistent directory "/include" . /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward /usr/lib/llvm-14/lib/clang/14.0.6/include /usr/local/include /usr/include/x86_64-linux-gnu /usr/include End of search list. foo.cc:4:3: error: use of undeclared identifier 'printf' printf("Hello, World!\n"); ^ 1 error generated.
Which is correct and consistent with gcc. We can see that "-isystem ." gets included before the builtin directories. This is the same with --sysroot, when it works.
To enable distributions which don't match Clang and GCC's standard search path, we need to add the system includes after the "include_paths" feature.