Skip to content

Commit

Permalink
[CMake] Use generator expression to get in-tree libc++ path
Browse files Browse the repository at this point in the history
When using the in-tree libc++, we should be using the full path to
ensure that we're using the right library and not accidentally pick up
the system library.

Differential Revision: https://reviews.llvm.org/D118200
  • Loading branch information
petrhosek committed Jan 26, 2022
1 parent f487a76 commit 48a3895
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
13 changes: 7 additions & 6 deletions compiler-rt/CMakeLists.txt
Expand Up @@ -532,16 +532,17 @@ endif()

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 "$<$<BOOL:$<TARGET_NAME_IF_EXISTS:${cxx_target}>>:$<TARGET_LINKER_FILE:${cxx_target}>>")
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,
Expand Down
7 changes: 3 additions & 4 deletions compiler-rt/lib/memprof/tests/CMakeLists.txt
Expand Up @@ -36,9 +36,8 @@ if(NOT WIN32)
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.
Expand All @@ -55,7 +54,7 @@ if(COMPILER_RT_DEFAULT_TARGET_ARCH IN_LIST MEMPROF_SUPPORTED_ARCH)
$<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>)
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)
Expand Down
5 changes: 1 addition & 4 deletions compiler-rt/lib/orc/unittests/CMakeLists.txt
Expand Up @@ -37,6 +37,7 @@ set(ORC_TEST_ARCH ${ORC_SUPPORTED_ARCH})
set(ORC_UNITTEST_LINK_FLAGS
${COMPILER_RT_UNITTEST_LINK_FLAGS}
${CMAKE_THREAD_LIBS_INIT}
${SANITIZER_TEST_CXX_LIBRARIES}
)

if(APPLE)
Expand All @@ -51,10 +52,6 @@ else()
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)
Expand Down
8 changes: 4 additions & 4 deletions compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt
Expand Up @@ -33,10 +33,10 @@ endif()
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)
Expand Down
8 changes: 4 additions & 4 deletions compiler-rt/lib/tsan/tests/CMakeLists.txt
Expand Up @@ -24,10 +24,10 @@ append_list_if(COMPILER_RT_HAS_MSSE4_2_FLAG -msse4.2 TSAN_UNITTEST_CFLAGS)

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)

Expand Down
5 changes: 1 addition & 4 deletions compiler-rt/lib/xray/tests/CMakeLists.txt
Expand Up @@ -50,6 +50,7 @@ set(XRAY_TEST_ARCH ${XRAY_SUPPORTED_ARCH})
set(XRAY_UNITTEST_LINK_FLAGS
${COMPILER_RT_UNITTEST_LINK_FLAGS}
${CMAKE_THREAD_LIBS_INIT}
${SANITIZER_TEST_CXX_LIBRARIES}
)

if (NOT APPLE)
Expand Down Expand Up @@ -82,10 +83,6 @@ if (NOT APPLE)
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)
Expand Down

0 comments on commit 48a3895

Please sign in to comment.