Implicit include path detection drops relative paths
When CMake parses implicit include paths from the compiler (new in 3.14.0, I believe), the paths from the compiler may not be normalized. This can cause implicit include paths to not be filtered.
In my particular situation, I am using an ARM cross-compile toolchain in buildroot. When the test compile is run to determine the Compiler ABI and parse the Implicit Include Directories, I get the following output:
Detecting CXX compiler ABI info compiled with the following output:
Change Dir: /mnt/work/output/build/<pkg>/CMakeFiles/CMakeTmp
Run Build Command(s):/usr/bin/gmake cmTC_a30a1/fast
gmake[2]: Entering directory '/mnt/work/output/build/<pkg>/CMakeFiles/CMakeTmp'
/usr/bin/gmake -f CMakeFiles/cmTC_a30a1.dir/build.make CMakeFiles/cmTC_a30a1.dir/build
gmake[3]: Entering directory '/mnt/work/output/build/<pkg>/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_a30a1.dir/CMakeCXXCompilerABI.cpp.o
/mnt/work/output/host/bin/arm-linux-gnueabihf-g++ --sysroot=/mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -DNDEBUG -v -o CMakeFiles/cmTC_a30a1.dir/CMakeCXXCompilerABI.cpp.o -c /usr/share/cmake/Modules/CMakeCXXCompilerABI.cpp
Using built-in specs.
COLLECT_GCC=/mnt/work/output/host/opt/ext-toolchain/bin/arm-linux-gnueabihf-g++
Target: arm-linux-gnueabihf
Configured with: /tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/src/gcc/configure --target=arm-linux-gnueabihf --prefix= --with-sysroot=/arm-linux-gnueabihf/libc --with-build-sysroot=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/install//arm-linux-gnueabihf/libc --enable-gnu-indirect-function --enable-shared --disable-libssp --disable-libmudflap --disable-libsanitizer --enable-checking=release --enable-languages=c,c++,fortran --with-gmp=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-mpfr=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-mpc=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-isl=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-arch=armv7-a --with-fpu=neon --with-float=hard --with-arch=armv7-a --with-pkgversion='GNU Toolchain for the A-profile Architecture 8.2-2018.11 (arm-rel-8.26)'
Thread model: posix
gcc version 8.2.1 20180802 (GNU Toolchain for the A-profile Architecture 8.2-2018.11 (arm-rel-8.26))
COLLECT_GCC_OPTIONS='-mabi=aapcs-linux' '-mfpu=neon-vfpv4' '-marm' '-fstack-protector-strong' '-mfloat-abi=hard' '-mcpu=cortex-a7' '-O3' '-v' '-D' '_LARGEFILE_SOURCE' '-D' '_LARGEFILE64_SOURCE' '-D' '_FILE_OFFSET_BITS=64' '-D' 'NDEBUG' '-c' '-o' 'CMakeFiles/cmTC_c42db.dir/CMakeCXXCompilerABI.cpp.o' '-shared-libgcc' '-mtls-dialect=gnu' '-march=armv7ve+simd'
/mnt/work/output/host/opt/ext-toolchain/bin/../libexec/gcc/arm-linux-gnueabihf/8.2.1/cc1plus -quiet -v -iprefix /mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/ -isysroot ../../../../host/arm-buildroot-linux-gnueabihf/sysroot -D_GNU_SOURCE -D _LARGEFILE_SOURCE -D _LARGEFILE64_SOURCE -D _FILE_OFFSET_BITS=64 -D NDEBUG /usr/share/cmake/Modules/CMakeCXXCompilerABI.cpp -quiet -dumpbase CMakeCXXCompilerABI.cpp -mabi=aapcs-linux -mfpu=neon-vfpv4 -marm -mfloat-abi=hard -mcpu=cortex-a7 -mtls-dialect=gnu -march=armv7ve+simd -auxbase-strip CMakeFiles/cmTC_c42db.dir/CMakeCXXCompilerABI.cpp.o -O3 -version -fstack-protector-strong -o /tmp/cc8PMNJM.s
GNU C++14 (GNU Toolchain for the A-profile Architecture 8.2-2018.11 (arm-rel-8.26)) version 8.2.1 20180802 (arm-linux-gnueabihf)
compiled by GNU C version 4.8.1, GMP version 4.3.2, MPFR version 3.1.6, MPC version 0.8.2, isl version isl-0.15-1-g835ea3a-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1"
ignoring duplicate directory "/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1/arm-linux-gnueabihf"
ignoring duplicate directory "/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1/backward"
ignoring duplicate directory "/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-gnueabihf/8.2.1/include"
ignoring nonexistent directory "../../../../host/arm-buildroot-linux-gnueabihf/sysroot/usr/local/include"
ignoring duplicate directory "/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-gnueabihf/8.2.1/include-fixed"
ignoring duplicate directory "/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include"
#include "..." search starts here:
#include <...> search starts here:
/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1
/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1/arm-linux-gnueabihf
/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1/backward
/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/include
/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/include-fixed
/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include
../../../../host/arm-buildroot-linux-gnueabihf/sysroot/usr/include
End of search list.
GNU C++14 (GNU Toolchain for the A-profile Architecture 8.2-2018.11 (arm-rel-8.26)) version 8.2.1 20180802 (arm-linux-gnueabihf)
compiled by GNU C version 4.8.1, GMP version 4.3.2, MPFR version 3.1.6, MPC version 0.8.2, isl version isl-0.15-1-g835ea3a-GMP
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5520551326996cbb8e9e97fb757a79b9
COLLECT_GCC_OPTIONS='-mabi=aapcs-linux' '-mfpu=neon-vfpv4' '-marm' '-fstack-protector-strong' '-mfloat-abi=hard' '-mcpu=cortex-a7' '-O3' '-v' '-D' '_LARGEFILE_SOURCE' '-D' '_LARGEFILE64_SOURCE' '-D' '_FILE_OFFSET_BITS=64' '-D' 'NDEBUG' '-c' '-o' 'CMakeFiles/cmTC_c42db.dir/CMakeCXXCompilerABI.cpp.o' '-shared-libgcc' '-mtls-dialect=gnu' '-march=armv7ve+simd'
/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/bin/as -v -march=armv7ve -mfloat-abi=hard -mfpu=neon-vfpv4 -meabi=5 -o CMakeFiles/cmTC_c42db.dir/CMakeCXXCompilerABI.cpp.o /tmp/cc8PMNJM.s
GNU assembler version 2.30.0 (arm-linux-gnueabihf) using BFD version (GNU Toolchain for the A-profile Architecture 8.2-2018.11 (arm-rel-8.26)) 2.30.0.20180625
COMPILER_PATH=/mnt/work/output/host/opt/ext-toolchain/bin/../libexec/gcc/arm-linux-gnueabihf/8.2.1/:/mnt/work/output/host/opt/ext-toolchain/bin/../libexec/gcc/:/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/bin/
LIBRARY_PATH=/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/:/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/:/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/lib/:../../../../host/arm-buildroot-linux-gnueabihf/sysroot/lib/:../../../../host/arm-buildroot-linux-gnueabihf/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-mabi=aapcs-linux' '-mfpu=neon-vfpv4' '-marm' '-fstack-protector-strong' '-mfloat-abi=hard' '-mcpu=cortex-a7' '-O3' '-v' '-D' '_LARGEFILE_SOURCE' '-D' '_LARGEFILE64_SOURCE' '-D' '_FILE_OFFSET_BITS=64' '-D' 'NDEBUG' '-c' '-o' 'CMakeFiles/cmTC_c42db.dir/CMakeCXXCompilerABI.cpp.o' '-shared-libgcc' '-mtls-dialect=gnu' '-march=armv7ve+simd'
Linking CXX executable cmTC_a30a1
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a30a1.dir/link.txt --verbose=1
/mnt/work/output/host/bin/arm-linux-gnueabihf-g++ --sysroot=/mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -O3 -DNDEBUG -v CMakeFiles/cmTC_a30a1.dir/CMakeCXXCompilerABI.cpp.o -o cmTC_a30a1
Using built-in specs.
COLLECT_GCC=/mnt/work/output/host/opt/ext-toolchain/bin/arm-linux-gnueabihf-g++
COLLECT_LTO_WRAPPER=/mnt/work/output/host/opt/ext-toolchain/bin/../libexec/gcc/arm-linux-gnueabihf/8.2.1/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/src/gcc/configure --target=arm-linux-gnueabihf --prefix= --with-sysroot=/arm-linux-gnueabihf/libc --with-build-sysroot=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/install//arm-linux-gnueabihf/libc --enable-gnu-indirect-function --enable-shared --disable-libssp --disable-libmudflap --disable-libsanitizer --enable-checking=release --enable-languages=c,c++,fortran --with-gmp=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-mpfr=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-mpc=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-isl=/tmp/dgboter/bbs/rhev-vm2--rhe6x86_64/buildbot/rhe6x86_64--arm-linux-gnueabihf/build/build-arm-linux-gnueabihf/host-tools --with-arch=armv7-a --with-fpu=neon --with-float=hard --with-arch=armv7-a --with-pkgversion='GNU Toolchain for the A-profile Architecture 8.2-2018.11 (arm-rel-8.26)'
Thread model: posix
gcc version 8.2.1 20180802 (GNU Toolchain for the A-profile Architecture 8.2-2018.11 (arm-rel-8.26))
COMPILER_PATH=/mnt/work/output/host/opt/ext-toolchain/bin/../libexec/gcc/arm-linux-gnueabihf/8.2.1/:/mnt/work/output/host/opt/ext-toolchain/bin/../libexec/gcc/:/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/bin/
LIBRARY_PATH=/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/:/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/:/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/lib/:/mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot/lib/:/mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-mabi=aapcs-linux' '-mfpu=neon-vfpv4' '-marm' '-fstack-protector-strong' '-mfloat-abi=hard' '-mcpu=cortex-a7' '-D' '_LARGEFILE_SOURCE' '-D' '_LARGEFILE64_SOURCE' '-D' '_FILE_OFFSET_BITS=64' '-O3' '-D' 'NDEBUG' '-v' '-o' 'cmTC_a30a1' '-shared-libgcc' '-mtls-dialect=gnu' '-march=armv7ve+simd'
/mnt/work/output/host/opt/ext-toolchain/bin/../libexec/gcc/arm-linux-gnueabihf/8.2.1/collect2 -plugin /mnt/work/output/host/opt/ext-toolchain/bin/../libexec/gcc/arm-linux-gnueabihf/8.2.1/liblto_plugin.so -plugin-opt=/mnt/work/output/host/opt/ext-toolchain/bin/../libexec/gcc/arm-linux-gnueabihf/8.2.1/lto-wrapper -plugin-opt=-fresolution=/tmp/ccA0P0Lq.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --sysroot=/mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot --eh-frame-hdr -dynamic-linker /lib/ld-linux-armhf.so.3 -X -m armelf_linux_eabi -o cmTC_a30a1 /mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot/lib/crt1.o /mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot/lib/crti.o /mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/crtbegin.o -L/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1 -L/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc -L/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/lib -L/mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot/lib -L/mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot/usr/lib CMakeFiles/cmTC_a30a1.dir/CMakeCXXCompilerABI.cpp.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/crtend.o /mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot/lib/crtn.o
COLLECT_GCC_OPTIONS='-mabi=aapcs-linux' '-mfpu=neon-vfpv4' '-marm' '-fstack-protector-strong' '-mfloat-abi=hard' '-mcpu=cortex-a7' '-D' '_LARGEFILE_SOURCE' '-D' '_LARGEFILE64_SOURCE' '-D' '_FILE_OFFSET_BITS=64' '-O3' '-D' 'NDEBUG' '-v' '-o' 'cmTC_a30a1' '-shared-libgcc' '-mtls-dialect=gnu' '-march=armv7ve+simd'
gmake[3]: Leaving directory '/mnt/work/output/build/<pkg>/CMakeFiles/CMakeTmp'
gmake[2]: Leaving directory '/mnt/work/output/build/<pkg>/CMakeFiles/CMakeTmp'
Parsed CXX implicit include dir info from above output: rv=done
found start of include info
found start of implicit include info
add: [/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1]
add: [/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1/arm-linux-gnueabihf]
add: [/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1/backward]
add: [/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/include]
add: [/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/include-fixed]
add: [/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include]
add: [../../../../host/arm-buildroot-linux-gnueabihf/sysroot/usr/include]
end of search list found
implicit include dirs: [/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1;/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1/arm-linux-gnueabihf;/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include/c++/8.2.1/backward;/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/include;/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/include-fixed;/mnt/work/output/host/opt/ext-toolchain/bin/../lib/gcc/arm-linux-gnueabihf/8.2.1/../../../../arm-linux-gnueabihf/include;../../../../host/arm-buildroot-linux-gnueabihf/sysroot/usr/include]
Above, GCC converts the sysroot path from an absolute path to a relative path. This seems like a perfectly legit thing for GCC to do. However, it means that CMake adds ../../../../host/arm-buildroot-linux-gnueabihf/sysroot/usr/include
to CMAKE_CXX_IMPLICIT_INCLUDE_DIRS
instead of adding /mnt/work/output/host/arm-buildroot-linux-gnueabihf/sysroot
As a result, absolute sysroot path includes are not properly filtered in my build. I end up with calls to GCC which look like g++ --sysroot=<sysroot> -isystem <sysroot> file.cxx
, which breaks standard library headers per https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129.
It seems like there are two problems here:
- Include paths are not normalized, so
/usr/include/../include
is not treated the same as/usr/include
- Relative and absolute paths are not filtered consistently