From 9299156727af2e41b1e0ac5113cf9c9b967f720a Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Thu, 11 May 2023 08:19:37 -0700 Subject: [PATCH] CMake: Use toolchain info for system includes CMake already provides `CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES`, so there's no need to invoke the compiler to determine system include directories. For the Clang tool based header generator, adding the includes from the current toolchain is strictly more correct than having it try and figure them out itself (which will favor files from any installed libc++ and/or Clang). PiperOrigin-RevId: 531207747 Change-Id: Icfcf7b495a0a5782c21a665984d9039d365db898 --- cmake/SapiBuildDefs.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmake/SapiBuildDefs.cmake b/cmake/SapiBuildDefs.cmake index f2f455d..0362673 100644 --- a/cmake/SapiBuildDefs.cmake +++ b/cmake/SapiBuildDefs.cmake @@ -153,10 +153,13 @@ function(add_sapi_library) "--sapi_ns=${_sapi_NAMESPACE}" ) if(SAPI_ENABLE_CLANG_TOOL) + set(_sapi_isystem_args ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}) + list(TRANSFORM _sapi_isystem_args PREPEND --extra-arg-before=-isystem) list(APPEND _sapi_generator_command sapi_generator_tool -p "${CMAKE_CURRENT_BINARY_DIR}" ${_sapi_generator_args} + ${_sapi_isystem_args} ${_sapi_full_inputs} ) add_custom_command( @@ -179,9 +182,8 @@ function(add_sapi_library) add_custom_command( OUTPUT "${_sapi_gen_header}" "${_sapi_isystem}" COMMAND sh -c - "${CMAKE_CXX_COMPILER} -E -x c++ -v /dev/null 2>&1 | \ - awk '/> search starts here:/{f=1;next}/^End of search/{f=0}f{print $1}' \ - > \"${_sapi_isystem}\"" + "printf '${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES}' | \ + sed \"s/;/\\n/g\" > \"${_sapi_isystem}\"" COMMAND ${_sapi_generator_command} COMMENT "Generating interface" DEPENDS ${_sapi_INPUTS}