[llvm] b010b7e - Remember LLVM_ENABLE_LIBCXX setting in installed configuration (#139712)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 13 05:53:02 PDT 2025


Author: Michael Kruse
Date: 2025-08-13T14:52:59+02:00
New Revision: b010b7ea89fdb870024b94913b2b784ce1f4f8d4

URL: https://github.com/llvm/llvm-project/commit/b010b7ea89fdb870024b94913b2b784ce1f4f8d4
DIFF: https://github.com/llvm/llvm-project/commit/b010b7ea89fdb870024b94913b2b784ce1f4f8d4.diff

LOG: Remember LLVM_ENABLE_LIBCXX setting in installed configuration (#139712)

Updated version of #134990 which was reverted because of the buildbot
[openmp-offload-amdgpu-runtime-2](https://lab.llvm.org/buildbot/#/builders/10)
failing. Its configuration has `LLVM_ENABLE_LIBCXX=ON` set although it
does not even have libc++ installed. In addition to #134990, this PR
adds a check whether C++ libraries are actually available. `#include
<chrono>` was chosen because this is the library that
[openmp-offload-amdgpu-runtime-2 failed
with](https://github.com/llvm/llvm-project/pull/134990#issuecomment-2792138162).

Original summary:

The buidbot
[flang-aarch64-libcxx](https://lab.llvm.org/buildbot/#/builders/89) is
currently failing with an ABI issue. The suspected reason is that
LLVMSupport.a is built using libc++, but the unittests are using the
default C++ standard library, libstdc++ in this case. This predefined
`llvm_gtest` target uses the LLVMSupport from `find_package(LLVM)`,
which finds the libc++-built LLVMSupport.

To fix, store the `LLVM_ENABLE_LIBCXX` setting in the LLVMConfig.cmake
such that everything that links to LLVM libraries use the same standard
library. In this case discussed in
https://github.com/llvm/llvm-zorg/pull/387 it was the flang-rt
unittests, but other runtimes with GTest unittests should have the same
issue (e.g. offload), and any external project that uses
`find_package(LLVM)`. This patch fixed the problem for me locally.

Added: 
    

Modified: 
    llvm/cmake/modules/HandleLLVMStdlib.cmake
    llvm/cmake/modules/LLVMConfig.cmake.in

Removed: 
    


################################################################################
diff  --git a/llvm/cmake/modules/HandleLLVMStdlib.cmake b/llvm/cmake/modules/HandleLLVMStdlib.cmake
index a7e138aa0789b..dda1caa846dcb 100644
--- a/llvm/cmake/modules/HandleLLVMStdlib.cmake
+++ b/llvm/cmake/modules/HandleLLVMStdlib.cmake
@@ -2,6 +2,7 @@
 # if the user has requested it.
 
 include(DetermineGCCCompatible)
+include(CheckIncludeFiles)
 
 if(NOT DEFINED LLVM_STDLIB_HANDLED)
   set(LLVM_STDLIB_HANDLED ON)
@@ -19,7 +20,17 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED)
     if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
       check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB)
       check_linker_flag(CXX "-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB)
-      if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB)
+
+      # Check whether C++ include files are available
+      # runtimes/CMakeLists.txt adds -nostdlib++ and -nostdinc++ to
+      # CMAKE_REQUIRED_FLAGS, which are incompatible with -stdlib=libc++; use
+      # a fresh CMAKE_REQUIRED_FLAGS environment.
+      cmake_push_check_state(RESET)
+      set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -stdlib=libc++")
+      check_include_files("chrono" CXX_COMPILER_SUPPORTS_STDLIB_CHRONO LANGUAGE CXX)
+      cmake_pop_check_state()
+
+      if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB AND CXX_COMPILER_SUPPORTS_STDLIB_CHRONO)
         append("-stdlib=libc++"
           CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
           CMAKE_MODULE_LINKER_FLAGS)

diff  --git a/llvm/cmake/modules/LLVMConfig.cmake.in b/llvm/cmake/modules/LLVMConfig.cmake.in
index c15b9576cd5d5..c39c33f0c7793 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -55,6 +55,8 @@ endif()
 
 set(LLVM_ENABLE_RTTI @LLVM_ENABLE_RTTI@)
 
+set(LLVM_ENABLE_LIBCXX @LLVM_ENABLE_LIBCXX@)
+
 set(LLVM_ENABLE_LIBEDIT @HAVE_LIBEDIT@)
 if(LLVM_ENABLE_LIBEDIT)
   find_package(LibEdit)


        


More information about the llvm-commits mailing list