diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -231,6 +231,15 @@ "Use static libc++abi." ${DEFAULT_SANITIZER_USE_STATIC_CXX_ABI}) pythonize_bool(SANITIZER_USE_STATIC_CXX_ABI) +set(DEFAULT_SANITIZER_USE_STATIC_TEST_CXX OFF) +if (DEFINED LIBCXX_ENABLE_SHARED AND NOT LIBCXX_ENABLE_SHARED) + set(DEFAULT_SANITIZER_USE_STATIC_TEST_CXX ON) +endif() + +option(SANITIZER_USE_STATIC_TEST_CXX + "Use static libc++ for tests." ${DEFAULT_SANITIZER_USE_STATIC_TEST_CXX}) +pythonize_bool(SANITIZER_USE_STATIC_TEST_CXX) + set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY OFF) if (FUCHSIA) set(DEFAULT_COMPILER_RT_USE_BUILTINS_LIBRARY ON) @@ -522,7 +531,15 @@ endif() if (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libc++") - append_libcxx_libs(SANITIZER_TEST_CXX) + if (SANITIZER_TEST_CXX_INTREE) + if (SANITIZER_USE_STATIC_TEST_CXX AND (TARGET cxx_static OR HAVE_LIBCXX)) + list(APPEND SANITIZER_TEST_CXX_LIBRARIES cxx_static) + elseif (TARGET cxx_shared OR HAVE_LIBCXX) + list(APPEND SANITIZER_TEST_CXX_LIBRARIES cxx_shared) + endif() + else() + append_list_if(COMPILER_RT_HAS_LIBCXX c++ SANITIZER_TEST_CXX_LIBRARIES) + endif() elseif (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libstdc++") append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_TEST_CXX_LIBRARIES) endif()