Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | # This CMake module is responsible for setting the standard library to libc++ |
| 2 | # if the user has requested it. |
| 3 | |
| 4 | include(DetermineGCCCompatible) |
| 5 | |
| 6 | if(NOT DEFINED LLVM_STDLIB_HANDLED) |
| 7 | set(LLVM_STDLIB_HANDLED ON) |
| 8 | |
| 9 | function(append value) |
| 10 | foreach(variable ${ARGN}) |
| 11 | set(${variable} "${${variable}} ${value}" PARENT_SCOPE) |
| 12 | endforeach(variable) |
| 13 | endfunction() |
| 14 | |
| 15 | include(CheckCXXCompilerFlag) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 16 | include(CheckLinkerFlag) |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 17 | set(LLVM_LIBCXX_USED 0) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 18 | if(LLVM_ENABLE_LIBCXX) |
| 19 | if(LLVM_COMPILER_IS_GCC_COMPATIBLE) |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 20 | check_cxx_compiler_flag("-stdlib=libc++" CXX_COMPILER_SUPPORTS_STDLIB) |
| 21 | check_linker_flag("-stdlib=libc++" CXX_LINKER_SUPPORTS_STDLIB) |
| 22 | if(CXX_COMPILER_SUPPORTS_STDLIB AND CXX_LINKER_SUPPORTS_STDLIB) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 23 | append("-stdlib=libc++" |
| 24 | CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS |
| 25 | CMAKE_MODULE_LINKER_FLAGS) |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 26 | set(LLVM_LIBCXX_USED 1) |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 27 | else() |
| 28 | message(WARNING "Can't specify libc++ with '-stdlib='") |
| 29 | endif() |
| 30 | else() |
| 31 | message(WARNING "Not sure how to specify libc++ for this compiler") |
| 32 | endif() |
| 33 | endif() |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 34 | |
| 35 | if(LLVM_STATIC_LINK_CXX_STDLIB) |
| 36 | if(LLVM_COMPILER_IS_GCC_COMPATIBLE) |
| 37 | check_cxx_compiler_flag("-static-libstdc++" |
| 38 | CXX_COMPILER_SUPPORTS_STATIC_STDLIB) |
| 39 | check_linker_flag("-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB) |
| 40 | if(CXX_COMPILER_SUPPORTS_STATIC_STDLIB AND |
| 41 | CXX_LINKER_SUPPORTS_STATIC_STDLIB) |
| 42 | append("-static-libstdc++" |
| 43 | CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS |
| 44 | CMAKE_MODULE_LINKER_FLAGS) |
| 45 | else() |
| 46 | message(WARNING |
| 47 | "Can't specify static linking for the C++ standard library") |
| 48 | endif() |
| 49 | else() |
| 50 | message(WARNING "Not sure how to specify static linking of C++ standard " |
| 51 | "library for this compiler") |
| 52 | endif() |
| 53 | endif() |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 54 | endif() |