xref: /aosp_15_r20/external/llvm/cmake/modules/HandleLLVMStdlib.cmake (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker# This CMake module is responsible for setting the standard library to libc++
2*9880d681SAndroid Build Coastguard Worker# if the user has requested it.
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Workerinclude(DetermineGCCCompatible)
5*9880d681SAndroid Build Coastguard Worker
6*9880d681SAndroid Build Coastguard Workerif(NOT DEFINED LLVM_STDLIB_HANDLED)
7*9880d681SAndroid Build Coastguard Worker  set(LLVM_STDLIB_HANDLED ON)
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker  function(append value)
10*9880d681SAndroid Build Coastguard Worker    foreach(variable ${ARGN})
11*9880d681SAndroid Build Coastguard Worker      set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
12*9880d681SAndroid Build Coastguard Worker    endforeach(variable)
13*9880d681SAndroid Build Coastguard Worker  endfunction()
14*9880d681SAndroid Build Coastguard Worker
15*9880d681SAndroid Build Coastguard Worker  include(CheckCXXCompilerFlag)
16*9880d681SAndroid Build Coastguard Worker  if(LLVM_ENABLE_LIBCXX)
17*9880d681SAndroid Build Coastguard Worker    if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
18*9880d681SAndroid Build Coastguard Worker      check_cxx_compiler_flag("-stdlib=libc++" CXX_SUPPORTS_STDLIB)
19*9880d681SAndroid Build Coastguard Worker      if(CXX_SUPPORTS_STDLIB)
20*9880d681SAndroid Build Coastguard Worker        append("-stdlib=libc++"
21*9880d681SAndroid Build Coastguard Worker          CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
22*9880d681SAndroid Build Coastguard Worker          CMAKE_MODULE_LINKER_FLAGS)
23*9880d681SAndroid Build Coastguard Worker        if(LLVM_ENABLE_LIBCXXABI)
24*9880d681SAndroid Build Coastguard Worker          append("-lc++abi"
25*9880d681SAndroid Build Coastguard Worker            CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
26*9880d681SAndroid Build Coastguard Worker            CMAKE_MODULE_LINKER_FLAGS)
27*9880d681SAndroid Build Coastguard Worker        endif()
28*9880d681SAndroid Build Coastguard Worker      else()
29*9880d681SAndroid Build Coastguard Worker        message(WARNING "Can't specify libc++ with '-stdlib='")
30*9880d681SAndroid Build Coastguard Worker      endif()
31*9880d681SAndroid Build Coastguard Worker    else()
32*9880d681SAndroid Build Coastguard Worker      message(WARNING "Not sure how to specify libc++ for this compiler")
33*9880d681SAndroid Build Coastguard Worker    endif()
34*9880d681SAndroid Build Coastguard Worker  endif()
35*9880d681SAndroid Build Coastguard Workerendif()
36