Detect GCC system include paths at run-time and automatically add them to CMAKE_${LANG}_IMPLICIT_INCLUDE_DIRECTORIES
Hi,
GCC 6 has introduced a change that broke some C++ projects when the project uses system includes (-isystem) via passing the parameter SYSTEM to CMake's functions include_directories or target_include_directories.
This didn't broke the 99% of the standard builds because CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES and CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES already default to /usr/include. So CMake automatically filters /usr/include from the list of includes when calling the compiler.
But when cross-compiling or when using a non-default system include directory, the build breaks.
On the WebKit project we work-around'ed this by calling GCC at run-time to obtain the list of system includes, to automatically add this directories to the above variables.
Perhaps it makes sense to introduce this change in CMake itself, as I think it may be useful for everybody. It is also probably a good idea to avoid passing -I/-isystem for directories that the compiler already assumes as default include directories. It keeps thinga cleaner and simple.
-
The change we did is this one: https://trac.webkit.org/changeset/205672/trunk/Source/cmake/OptionsCommon.cmake
-
And here is the WebKit bug that contains details about this issue: https://bugs.webkit.org/show_bug.cgi?id=161697
-
The GCC bug report itself that got closed as wontfix is: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129