diff --git a/cmake/macros/BuildMetalib.cmake b/cmake/macros/BuildMetalib.cmake index 16a64d5947..1277ec0820 100644 --- a/cmake/macros/BuildMetalib.cmake +++ b/cmake/macros/BuildMetalib.cmake @@ -31,6 +31,12 @@ if(CMAKE_VERSION VERSION_LESS "3.12") set_property(TARGET "${target}" APPEND PROPERTY INCLUDE_DIRECTORIES "${include_directories}") set_property(TARGET "${target}" APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${include_directories}") + # SYSTEM include directories should still be reported as SYSTEM, so + # that warnings from those includes are suppressed + set(sys_include_directories + "$") + target_include_directories("${target}" SYSTEM PUBLIC "${sys_include_directories}") + # And for INTERFACE_COMPILE_DEFINITIONS as well set(compile_definitions "$") set_property(TARGET "${target}" APPEND PROPERTY COMPILE_DEFINITIONS "${compile_definitions}") diff --git a/cmake/macros/PackageConfig.cmake b/cmake/macros/PackageConfig.cmake index b35b5e5bb9..df81deb621 100644 --- a/cmake/macros/PackageConfig.cmake +++ b/cmake/macros/PackageConfig.cmake @@ -158,6 +158,18 @@ function(package_option name) # Create the INTERFACE library used to depend on this package. add_library(PKG::${name} INTERFACE IMPORTED GLOBAL) + # Explicitly record the package's include directories as system include + # directories. CMake does do this automatically for INTERFACE libraries, but + # it does it by discovering all transitive links first, then reading + # INTERFACE_INCLUDE_DIRECTORIES for those which are INTERFACE libraries. So, + # this would be broken for the metalib system (pre CMake 3.12) which doesn't + # "link" the object libraries. + if(CMAKE_VERSION VERSION_LESS "3.12") + set_target_properties(PKG::${name} PROPERTIES + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES + "$") + endif() + # Create the option, and if it actually is enabled, populate the INTERFACE # library created above option("HAVE_${name}" "${cache_string}" "${default}")