[libcxx-commits] [libcxx] [libcxx] Fix include directory order (PR #65859)

Alex Brachet via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 11 05:53:03 PDT 2023


https://github.com/abrachet updated https://github.com/llvm/llvm-project/pull/65859:

>From e88e2a8eeca3283220411cae0265d83855aee7e9 Mon Sep 17 00:00:00 2001
From: Alex Brachet <abrachet at google.com>
Date: Sat, 9 Sep 2023 15:03:17 -0400
Subject: [PATCH] [libcxx] Fix include directory order

It's important that the arch directory be included first so that
its header files which interpose on the default include dir
be included instead of the default ones. The clang driver [1] does
this when not building with -nostdinc, the libcxx build should
do the same.

We found this after https://reviews.llvm.org/D154282 when cross
compiling from non Linux to Linux. If the host machine was not
Linux, _LIBCPP_HAS_NO_TIME_ZONE_DATABASE would be defined in
the default include dir __config_site, while it was undefined
in the arch specific one causing build failures.
---
 libcxx/include/CMakeLists.txt | 6 ++++--
 libcxx/modules/CMakeLists.txt | 4 +++-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libcxx/include/CMakeLists.txt b/libcxx/include/CMakeLists.txt
index d9f6311d9b48eb6..dd00636fcf0b7c5 100644
--- a/libcxx/include/CMakeLists.txt
+++ b/libcxx/include/CMakeLists.txt
@@ -1029,8 +1029,10 @@ add_custom_target(generate-cxx-headers ALL DEPENDS ${_all_includes})
 add_library(cxx-headers INTERFACE)
 target_link_libraries(cxx-headers INTERFACE libcxx-abi-headers)
 add_dependencies(cxx-headers generate-cxx-headers)
-target_include_directories(cxx-headers INTERFACE ${LIBCXX_GENERATED_INCLUDE_DIR}
-                                                 ${LIBCXX_GENERATED_INCLUDE_TARGET_DIR})
+# It's important that the arch directory be included first so that its header files
+# which interpose on the default include dir be included instead of the default ones.
+target_include_directories(cxx-headers INTERFACE ${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}
+                                                 ${LIBCXX_GENERATED_INCLUDE_DIR})
 
 if (LIBCXX_INSTALL_HEADERS)
   foreach(file ${files})
diff --git a/libcxx/modules/CMakeLists.txt b/libcxx/modules/CMakeLists.txt
index 338769d64fd40e3..395226fb3728700 100644
--- a/libcxx/modules/CMakeLists.txt
+++ b/libcxx/modules/CMakeLists.txt
@@ -128,8 +128,10 @@ if ("${LIBCXX_GENERATED_INCLUDE_DIR}" STREQUAL "${LIBCXX_GENERATED_INCLUDE_TARGE
   # This typically happens when the target is not installed.
   set(LIBCXX_CONFIGURED_INCLUDE_DIRS "${LIBCXX_GENERATED_INCLUDE_DIR}")
 else()
+  # It's important that the arch directory be included first so that its header files
+  # which interpose on the default include dir be included instead of the default ones.
   set(LIBCXX_CONFIGURED_INCLUDE_DIRS
-    "${LIBCXX_GENERATED_INCLUDE_DIR};${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}"
+    "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR};${LIBCXX_GENERATED_INCLUDE_DIR}"
   )
 endif()
 configure_file(



More information about the libcxx-commits mailing list