diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt --- a/compiler-rt/CMakeLists.txt +++ b/compiler-rt/CMakeLists.txt @@ -532,16 +532,17 @@ if (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libc++") 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) + if (SANITIZER_USE_STATIC_TEST_CXX) + set(cxx_target cxx_static) + else() + set(cxx_target cxx_shared) endif() + list(APPEND SANITIZER_TEST_CXX_LIBRARIES "$<$>:$>") else() - append_list_if(COMPILER_RT_HAS_LIBCXX c++ SANITIZER_TEST_CXX_LIBRARIES) + append_list_if(COMPILER_RT_HAS_LIBCXX -lc++ SANITIZER_TEST_CXX_LIBRARIES) endif() elseif (SANITIZER_TEST_CXX_LIBNAME STREQUAL "libstdc++") - append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ SANITIZER_TEST_CXX_LIBRARIES) + append_list_if(COMPILER_RT_HAS_LIBSTDCXX -lstdc++ SANITIZER_TEST_CXX_LIBRARIES) endif() # TODO: There's a lot of duplication across lib/*/tests/CMakeLists.txt files, diff --git a/compiler-rt/lib/memprof/tests/CMakeLists.txt b/compiler-rt/lib/memprof/tests/CMakeLists.txt --- a/compiler-rt/lib/memprof/tests/CMakeLists.txt +++ b/compiler-rt/lib/memprof/tests/CMakeLists.txt @@ -36,9 +36,8 @@ list(APPEND MEMPROF_UNITTEST_LINK_FLAGS -pthread) endif() -foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) - list(APPEND MEMPROF_UNITTEST_LINK_FLAGS -l${lib}) -endforeach() +set(MEMPROF_UNITTEST_LINK_LIBRARIES ${SANITIZER_TEST_CXX_LIBRARIES}) +list(APPEND MEMPROF_UNITTEST_LINK_LIBRARIES "dl") if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST MEMPROF_SUPPORTED_ARCH) # MemProf unit tests are only run on the host machine. @@ -55,7 +54,7 @@ $) set_target_compile_flags(MemProfUnitTests ${MEMPROF_UNITTEST_CFLAGS}) set_target_link_flags(MemProfUnitTests ${MEMPROF_UNITTEST_LINK_FLAGS}) - target_link_libraries(MemProfUnitTests dl) + target_link_libraries(MemProfUnitTests ${MEMPROF_UNITTEST_LINK_LIBRARIES}) if (TARGET cxx-headers OR HAVE_LIBCXX) add_dependencies(MemProfUnitTests cxx-headers) diff --git a/compiler-rt/lib/orc/unittests/CMakeLists.txt b/compiler-rt/lib/orc/unittests/CMakeLists.txt --- a/compiler-rt/lib/orc/unittests/CMakeLists.txt +++ b/compiler-rt/lib/orc/unittests/CMakeLists.txt @@ -37,6 +37,7 @@ set(ORC_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS} ${CMAKE_THREAD_LIBS_INIT} + ${SANITIZER_TEST_CXX_LIBRARIES} ) if(APPLE) @@ -51,10 +52,6 @@ append_list_if(COMPILER_RT_HAS_LIBEXECINFO -lexecinfo ORC_UNITTEST_LINK_FLAGS) endif() -foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) - list(APPEND ORC_UNITTEST_LINK_FLAGS -l${lib}) -endforeach() - set(ORC_DEPS gtest orc) # ORC uses C++ standard library headers. if (TARGET cxx-headers OR HAVE_LIBCXX) diff --git a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt --- a/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt +++ b/compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt @@ -33,10 +33,10 @@ set(SCUDO_TEST_ARCH ${SCUDO_STANDALONE_SUPPORTED_ARCH}) # gtests requires c++ -set(LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS}) -foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) - list(APPEND LINK_FLAGS -l${lib}) -endforeach() +set(LINK_FLAGS + ${COMPILER_RT_UNITTEST_LINK_FLAGS} + ${SANITIZER_TEST_CXX_LIBRARIES} + ) list(APPEND LINK_FLAGS -pthread) # Linking against libatomic is required with some compilers check_library_exists(atomic __atomic_load_8 "" COMPILER_RT_HAS_LIBATOMIC) diff --git a/compiler-rt/lib/tsan/tests/CMakeLists.txt b/compiler-rt/lib/tsan/tests/CMakeLists.txt --- a/compiler-rt/lib/tsan/tests/CMakeLists.txt +++ b/compiler-rt/lib/tsan/tests/CMakeLists.txt @@ -24,10 +24,10 @@ set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH}) -set(LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS}) -foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) - list(APPEND LINK_FLAGS -l${lib}) -endforeach() +set(LINK_FLAGS + ${COMPILER_RT_UNITTEST_LINK_FLAGS} + ${SANITIZER_TEST_CXX_LIBRARIES} + ) if(APPLE) diff --git a/compiler-rt/lib/xray/tests/CMakeLists.txt b/compiler-rt/lib/xray/tests/CMakeLists.txt --- a/compiler-rt/lib/xray/tests/CMakeLists.txt +++ b/compiler-rt/lib/xray/tests/CMakeLists.txt @@ -50,6 +50,7 @@ set(XRAY_UNITTEST_LINK_FLAGS ${COMPILER_RT_UNITTEST_LINK_FLAGS} ${CMAKE_THREAD_LIBS_INIT} + ${SANITIZER_TEST_CXX_LIBRARIES} ) if (NOT APPLE) @@ -82,10 +83,6 @@ append_list_if(COMPILER_RT_HAS_LIBEXECINFO -lexecinfo XRAY_UNITTEST_LINK_FLAGS) endif() -foreach(lib ${SANITIZER_TEST_CXX_LIBRARIES}) - list(APPEND XRAY_UNITTEST_LINK_FLAGS -l${lib}) -endforeach() - macro(add_xray_unittest testname) cmake_parse_arguments(TEST "" "" "SOURCES;HEADERS" ${ARGN}) if(UNIX AND NOT APPLE)