[CMake] Use -isystem flag to access libc++ headers

This is a partial revert of D62155. Rather than copying libc++ headers
into the build directory to be later overwritten by the final headers,
use -isystem flag to access libc++ headers during CMake checks. This
should address the occasional flake we've seen, especially on Windows
builders where CMake fails to overwrite __config with the final version.

Differential Revision: https://reviews.llvm.org/D88454

GitOrigin-RevId: 8d26760a95bae34aa5c1161a1c2ab8c1cdaa10a1
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index be8141c..7c97db4 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -202,14 +202,6 @@
 add_custom_target(cxx-generated-config ALL
   DEPENDS ${LIBCXX_BINARY_DIR}/__generated_config)
 
-# In some build configurations (like bootstrapping clang), we need to be able to
-# install the libcxx headers before the CMake configuration for libcxx runs. Making
-# the name of this target configurable allows LLVM/runtimes/CMakeLists.txt to
-# add this subdirectory to the LLVM build to put libcxx's headers in place
-# before libcxx's build configuration is run.
-if (NOT CXX_HEADER_TARGET)
-  set(CXX_HEADER_TARGET cxx-headers)
-endif()
 if(LIBCXX_HEADER_DIR)
   set(output_dir ${LIBCXX_HEADER_DIR}/include/c++/v1)
 
@@ -234,23 +226,23 @@
   list(APPEND out_files ${dst})
   add_custom_target(generate-cxx-headers DEPENDS ${out_files})
 
-  add_library(${CXX_HEADER_TARGET} INTERFACE)
-  add_dependencies(${CXX_HEADER_TARGET} generate-cxx-headers ${LIBCXX_CXX_ABI_HEADER_TARGET})
+  add_library(cxx-headers INTERFACE)
+  add_dependencies(cxx-headers generate-cxx-headers ${LIBCXX_CXX_ABI_HEADER_TARGET})
   # TODO: Use target_include_directories once we figure out why that breaks the runtimes build
   if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
-    target_compile_options(${CXX_HEADER_TARGET} INTERFACE /I "${output_dir}")
+    target_compile_options(cxx-headers INTERFACE /I "${output_dir}")
   else()
-    target_compile_options(${CXX_HEADER_TARGET} INTERFACE -I "${output_dir}")
+    target_compile_options(cxx-headers INTERFACE -I "${output_dir}")
   endif()
 
   # Make sure the generated __config_site header is included when we build the library.
   if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
-    target_compile_options(${CXX_HEADER_TARGET} INTERFACE /FI "${LIBCXX_BINARY_DIR}/__config_site")
+    target_compile_options(cxx-headers INTERFACE /FI "${LIBCXX_BINARY_DIR}/__config_site")
   else()
-    target_compile_options(${CXX_HEADER_TARGET} INTERFACE -include "${LIBCXX_BINARY_DIR}/__config_site")
+    target_compile_options(cxx-headers INTERFACE -include "${LIBCXX_BINARY_DIR}/__config_site")
   endif()
 else()
-  add_library(${CXX_HEADER_TARGET} INTERFACE)
+  add_library(cxx-headers INTERFACE)
 endif()
 
 if (LIBCXX_INSTALL_HEADERS)
@@ -258,7 +250,7 @@
     get_filename_component(dir ${file} DIRECTORY)
     install(FILES ${file}
       DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir}
-      COMPONENT ${CXX_HEADER_TARGET}
+      COMPONENT cxx-headers
       PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
     )
   endforeach()
@@ -268,15 +260,15 @@
     DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1
     PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
     RENAME __config
-    COMPONENT ${CXX_HEADER_TARGET})
+    COMPONENT cxx-headers)
 
   if (NOT CMAKE_CONFIGURATION_TYPES)
-    add_custom_target(install-${CXX_HEADER_TARGET}
-                      DEPENDS ${CXX_HEADER_TARGET} cxx-generated-config
+    add_custom_target(install-cxx-headers
+                      DEPENDS cxx-headers cxx-generated-config
                       COMMAND "${CMAKE_COMMAND}"
-                              -DCMAKE_INSTALL_COMPONENT=${CXX_HEADER_TARGET}
+                              -DCMAKE_INSTALL_COMPONENT=cxx-headers
                               -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
     # Stripping is a no-op for headers
-    add_custom_target(install-${CXX_HEADER_TARGET}-stripped DEPENDS install-${CXX_HEADER_TARGET})
+    add_custom_target(install-cxx-headers-stripped DEPENDS install-cxx-headers)
   endif()
 endif()