diff options
| author | Erich Keane <erich.keane@intel.com> | 2019-08-14 19:55:59 +0000 |
|---|---|---|
| committer | Erich Keane <erich.keane@intel.com> | 2019-08-14 19:55:59 +0000 |
| commit | 0e85f18ded9c03b8b41931cec7ad16d104ec4c14 (patch) | |
| tree | c21fbb260cb6a4e462b56b57f10e52c5be737a32 /llvm/cmake | |
| parent | da0435a6900731a9a31330fdb55c4f46f4949060 (diff) | |
| download | bcm5719-llvm-0e85f18ded9c03b8b41931cec7ad16d104ec4c14.tar.gz bcm5719-llvm-0e85f18ded9c03b8b41931cec7ad16d104ec4c14.zip | |
Add support in CMake to statically link the C++ standard library.
It is sometimes useful to have the C++ standard library linked into the
assembly when compiling clang, particularly when distributing a compiler
onto systems that don't have a copy of stdlibc++ or libc++ installed.
This functionality should work with either GCC or Clang as the host
compiler, though statically linking libc++ (as may be required for
licensing purposes) is only possible if the host compiler is Clang with
a copy of libc++ available.
Differential Revision: https://reviews.llvm.org/D65603
llvm-svn: 368907
Diffstat (limited to 'llvm/cmake')
| -rw-r--r-- | llvm/cmake/modules/HandleLLVMStdlib.cmake | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/cmake/modules/HandleLLVMStdlib.cmake b/llvm/cmake/modules/HandleLLVMStdlib.cmake index f0e22d1a5b3..b67d87d4300 100644 --- a/llvm/cmake/modules/HandleLLVMStdlib.cmake +++ b/llvm/cmake/modules/HandleLLVMStdlib.cmake @@ -31,4 +31,24 @@ if(NOT DEFINED LLVM_STDLIB_HANDLED) message(WARNING "Not sure how to specify libc++ for this compiler") endif() endif() + + if(LLVM_STATIC_LINK_CXX_STDLIB) + if(LLVM_COMPILER_IS_GCC_COMPATIBLE) + check_cxx_compiler_flag("-static-libstdc++" + CXX_COMPILER_SUPPORTS_STATIC_STDLIB) + check_linker_flag("-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB) + if(CXX_COMPILER_SUPPORTS_STATIC_STDLIB AND + CXX_LINKER_SUPPORTS_STATIC_STDLIB) + append("-static-libstdc++" + CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS + CMAKE_MODULE_LINKER_FLAGS) + else() + message(WARNING + "Can't specify static linking for the C++ standard library") + endif() + else() + message(WARNING "Not sure how to specify static linking of C++ standard " + "library for this compiler") + endif() + endif() endif() |

