diff options
author | Petr Hosek <phosek@chromium.org> | 2018-05-18 01:10:09 +0000 |
---|---|---|
committer | Petr Hosek <phosek@chromium.org> | 2018-05-18 01:10:09 +0000 |
commit | 2dd07cd53a1eee60554f58ab232ce9e546d0e45d (patch) | |
tree | c82797a4dc719caf290307d2f43e0fb7e647875c /CMakeLists.txt | |
parent | 458805f19b875ba108f5e6e1f342ecf498fb297f (diff) | |
download | compiler-rt-2dd07cd53a1eee60554f58ab232ce9e546d0e45d.tar.gz |
[CMake] Detect the compiler runtime and standard library
Rather then requiring the user to specify runtime the compiler
runtime and C++ standard library, or trying to guess them which is
error-prone, use auto-detection by parsing the compiler link output.
Differential Revision: https://reviews.llvm.org/D46857
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@332683 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 84a7dcd81..b7bd46107 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,9 +112,6 @@ option(COMPILER_RT_EXTERNALIZE_DEBUGINFO # COMPILER_RT_DEBUG_PYBOOL is used by lit.common.configured.in. pythonize_bool(COMPILER_RT_DEBUG) -include(HandleCompilerRT) -include(config-ix) - if(APPLE AND SANITIZER_MIN_OSX_VERSION AND SANITIZER_MIN_OSX_VERSION VERSION_LESS "10.9") # Mac OS X prior to 10.9 had problems with exporting symbols from # libc++/libc++abi. @@ -123,7 +120,7 @@ else() set(cxxabi_supported ON) endif() -option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in ubsan" ON) +option(SANITIZER_ALLOW_CXXABI "Allow use of C++ ABI details in sanitizers" ON) set(SANITIZE_CAN_USE_CXXABI OFF) if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI) @@ -131,48 +128,51 @@ if (cxxabi_supported AND SANITIZER_ALLOW_CXXABI) endif() pythonize_bool(SANITIZER_CAN_USE_CXXABI) +check_link_libraries(cxx_link_libraries) + set(SANITIZER_CXX_ABI "default" CACHE STRING "Specify C++ ABI library to use.") -set(CXXABIS none default libcxxabi libstdc++ libc++) +set(CXXABIS none default libc++ libstdc++) set_property(CACHE SANITIZER_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) if (SANITIZER_CXX_ABI STREQUAL "default") - if (HAVE_LIBCXXABI AND COMPILER_RT_DEFAULT_TARGET_ONLY) - set(SANITIZER_CXX_ABI_LIBNAME "libcxxabi") - set(SANITIZER_CXX_ABI_INTREE 1) - elseif (APPLE) - set(SANITIZER_CXX_ABI_LIBNAME "libcxxabi") + if(APPLE) + set(SANITIZER_CXX_ABI_LIBNAME "libc++") set(SANITIZER_CXX_ABI_SYSTEM 1) - else() + elseif("stdc++" IN_LIST cxx_link_libraries) set(SANITIZER_CXX_ABI_LIBNAME "libstdc++") set(SANITIZER_CXX_ABI_SYSTEM 1) + elseif("c++" IN_LIST cxx_link_libraries) + set(SANITIZER_CXX_ABI_LIBNAME "libc++") endif() else() set(SANITIZER_CXX_ABI_LIBNAME "${SANITIZER_CXX_ABI}") endif() -if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libcxxabi") - if (SANITIZER_CXX_ABI_INTREE) - if (NOT LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_shared OR HAVE_LIBUNWIND)) - list(APPEND SANITIZER_CXX_ABI_LIBRARY unwind_shared) - elseif (LIBCXXABI_ENABLE_STATIC_UNWINDER AND (TARGET unwind_static OR HAVE_LIBUNWIND)) - list(APPEND SANITIZER_CXX_ABI_LIBRARY unwind_static) - endif() - if (NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND (TARGET cxxabi_shared OR HAVE_LIBCXXABI)) +if (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libc++") + if(SANITIZER_CXX_ABI_SYSTEM) + list(APPEND SANITIZER_CXX_ABI_LIBRARY "c++") + else() + if(TARGET cxxabi_shared OR (HAVE_LIBCXXABI AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY)) list(APPEND SANITIZER_CXX_ABI_LIBRARY cxxabi_shared) - elseif (LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND (TARGET cxxabi_static OR HAVE_LIBCXXABI)) + elseif(TARGET cxxabi_shared OR (HAVE_LIBCXXABI AND LIBCXX_ENABLE_STATIC_ABI_LIBRARY)) list(APPEND SANITIZER_CXX_ABI_LIBRARY cxxabi_static) + else() + list(APPEND SANITIZER_CXX_ABI_LIBRARY "c++") endif() - else() - list(APPEND SANITIZER_CXX_ABI_LIBRARY "c++abi") endif() -elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libc++") - list(APPEND SANITIZER_CXX_ABI_LIBRARY "c++") elseif (SANITIZER_CXX_ABI_LIBNAME STREQUAL "libstdc++") - append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_CXX_ABI_LIBRARY) + list(APPEND SANITIZER_CXX_ABI_LIBRARY "stdc++") endif() -option(SANITIZER_USE_COMPILER_RT "Use compiler-rt builtins instead of libgcc" OFF) +check_runtime_library(runtime_library) +if(runtime_library MATCHES ".*libgcc.*") + set(COMPILER_RT_RUNTIME_LIBRARY "libgcc") +elseif(runtime_library MATCHES ".*libclang_rt.builtins.*") + set(COMPILER_RT_RUNTIME_LIBRARY "compiler-rt") +endif() + +include(config-ix) #================================ # Setup Compiler Flags @@ -320,9 +320,7 @@ append_list_if(COMPILER_RT_HAS_WD4800_FLAG /wd4800 SANITIZER_COMMON_CFLAGS) # Set common link flags. append_list_if(COMPILER_RT_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS) -if (SANITIZER_USE_COMPILER_RT) - list(APPEND SANITIZER_COMMON_LINK_FLAGS -rtlib=compiler-rt) - find_compiler_rt_library(builtins COMPILER_RT_BUILTINS_LIBRARY) +if (COMPILER_RT_RUNTIME_LIBRARY STREQUAL "compiler-rt") list(APPEND SANITIZER_COMMON_LINK_LIBS ${COMPILER_RT_BUILTINS_LIBRARY}) else() if (ANDROID) |