llvm.org GIT mirror llvm / 89ae907
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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368907 91177308-0d34-0410-b5e6-96231b3b80d8 Erich Keane 2 months ago
3 changed file(s) with 26 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
389389 option(LLVM_ENABLE_LOCAL_SUBMODULE_VISIBILITY "Compile with -fmodules-local-submodule-visibility." ON)
390390 endif()
391391 option(LLVM_ENABLE_LIBCXX "Use libc++ if available." OFF)
392 option(LLVM_STATIC_LINK_CXX_STDLIB "Statically link the standard library." OFF)
392393 option(LLVM_ENABLE_LLD "Use lld as C and C++ linker." OFF)
393394 option(LLVM_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
394395 option(LLVM_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
3030 message(WARNING "Not sure how to specify libc++ for this compiler")
3131 endif()
3232 endif()
33
34 if(LLVM_STATIC_LINK_CXX_STDLIB)
35 if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
36 check_cxx_compiler_flag("-static-libstdc++"
37 CXX_COMPILER_SUPPORTS_STATIC_STDLIB)
38 check_linker_flag("-static-libstdc++" CXX_LINKER_SUPPORTS_STATIC_STDLIB)
39 if(CXX_COMPILER_SUPPORTS_STATIC_STDLIB AND
40 CXX_LINKER_SUPPORTS_STATIC_STDLIB)
41 append("-static-libstdc++"
42 CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
43 CMAKE_MODULE_LINKER_FLAGS)
44 else()
45 message(WARNING
46 "Can't specify static linking for the C++ standard library")
47 endif()
48 else()
49 message(WARNING "Not sure how to specify static linking of C++ standard "
50 "library for this compiler")
51 endif()
52 endif()
3353 endif()
430430 passed to invocations of both so that the project is built using libc++
431431 instead of stdlibc++. Defaults to OFF.
432432
433 **LLVM_STATIC_LINK_CXX_STDLIB**:BOOL
434 Statically link to the C++ standard library if possible. This uses the flag
435 "-static-libstdc++", but a Clang host compiler will statically link to libc++
436 if used in conjuction with the **LLVM_ENABLE_LIBCXX** flag. Defaults to OFF.
437
433438 **LLVM_ENABLE_LLD**:BOOL
434439 This option is equivalent to `-DLLVM_USE_LINKER=lld`, except during a 2-stage
435440 build where a dependency is added from the first stage to the second ensuring