Skip to content

Fix more regressions in legacy implicit include directories

Brad King requested to merge brad.king/cmake:fix-legacy-implicit-includes into master
  • Prefix only hard-coded implicit include directories with the sysroot

    Since commit 7cd65c97 we have prefixed the value of CMAKE_SYSROOT to implicit include directories. This was done because we hard-coded /usr/include as an implicit include directory by without accounting for the sysroot. Likely that original commit should have updated the hard-coded paths in the UnixPaths module to use CMAKE_SYSROOT on construction.

    Since !2716 (merged) the values of the CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES variables are computed from a real compiler invocation so they already account for the sysroot prefix. In !2957 (merged) we attempted to apply the prefix conditionally, but that is incorrect because the compiler's real implicit include directories are not all under the sysroot. Instead we will have to simply assume that all implicit include directories in CMAKE_<LANG>_IMPLICIT_INCLUDE_DIRECTORIES already have the sysroot prefix if needed. Code that constructs the value must be responsible for that because it is the only place that knows.

    Update our current hard-coded addition of /usr/include to the implicit include directories to account for CMAKE_SYSROOT as we argue above should have been done originally in UnixPaths.

  • Restore unconditional use of "standard" include directories

    CMAKE_<LANG>_STANDARD_INCLUDE_DIRECTORIES is meant to unconditionally add explicitly specified include directories to compile lines. In commit !2864 (merged) a condition was accidentally added to exclude implicit include directories. Drop that condition.

  • Do not explicitly report "standard" include directories as implicit

    In !2716 (merged) we did not account for CMAKE_<LANG>_STANDARD_INCLUDE_DIRECTORIES. This variable lets platform modules or toolchain files specify directories that are to be explicitly passed as standard include directories. These include directories are used by the test project from which we extract implicit include directories so they appear in the parsed results whether or not the compiler really considers them implicit. Exclude these entries from the computed implicit include directories since they are not actually implied by the compiler when we invoke it with "standard" include directories passed explicitly.

    Instead teach the build system generators to treat the "standard" directories as implicit for purposes of excluding them from appearing earlier in the compiler command line due to include_directories and target_include_directories calls.

Fixes: #18936 (closed)
Issue: #18944 (closed)

Edited by Brad King

Merge request reports