Skip to content

Commit

Permalink
[CMake] Use correct visibility for linked libraries in CMake
Browse files Browse the repository at this point in the history
When linking library dependencies, we shouldn't need to export linked
libraries to dependents. We should be explicit about this in
target_link_libraries, otherwise other targets that depend on these such
as sanitizers get repeated (and possibly even conflicting) dependencies.

Differential Revision: https://reviews.llvm.org/D57456

llvm-svn: 352688
  • Loading branch information
petrhosek committed Jan 30, 2019
1 parent 1f7eda5 commit 8e78915
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions libcxx/benchmarks/CMakeLists.txt
Expand Up @@ -137,6 +137,7 @@ function(add_benchmark_test name source_file)
add_executable(${libcxx_target} EXCLUDE_FROM_ALL ${source_file})
add_dependencies(${libcxx_target} cxx cxx-headers google-benchmark-libcxx)
add_dependencies(cxx-benchmarks ${libcxx_target})
target_link_libraries(${libcxx_target} ${LIBCXX_LIBRARIES})
if (LIBCXX_ENABLE_SHARED)
target_link_libraries(${libcxx_target} cxx_shared)
else()
Expand Down
9 changes: 7 additions & 2 deletions libcxx/lib/CMakeLists.txt
Expand Up @@ -241,7 +241,7 @@ if (LIBCXX_ENABLE_SHARED)
if(COMMAND llvm_setup_rpath)
llvm_setup_rpath(cxx_shared)
endif()
target_link_libraries(cxx_shared ${LIBCXX_LIBRARIES})
target_link_libraries(cxx_shared PRIVATE ${LIBCXX_LIBRARIES})
set_target_properties(cxx_shared
PROPERTIES
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
Expand All @@ -265,7 +265,7 @@ endif()
# Build the static library.
if (LIBCXX_ENABLE_STATIC)
add_library(cxx_static STATIC ${cxx_static_sources})
target_link_libraries(cxx_static ${LIBCXX_LIBRARIES})
target_link_libraries(cxx_static PRIVATE ${LIBCXX_LIBRARIES})
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
set_target_properties(cxx_static
PROPERTIES
Expand Down Expand Up @@ -461,3 +461,8 @@ if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
add_custom_target(install-libcxx DEPENDS install-cxx)
endif()

# TODO: This is needed by cxx-benchmarks but this variable isn't
# available outside of the scope of this file so we need to export
# it. This is not necessarily the cleanest solution.
set(LIBCXX_LIBRARIES ${LIBCXX_LIBRARIES} PARENT_SCOPE)
4 changes: 2 additions & 2 deletions libcxxabi/src/CMakeLists.txt
Expand Up @@ -189,7 +189,7 @@ if (LIBCXXABI_ENABLE_SHARED)
if(COMMAND llvm_setup_rpath)
llvm_setup_rpath(cxxabi_shared)
endif()
target_link_libraries(cxxabi_shared ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_SHARED_LIBRARIES})
target_link_libraries(cxxabi_shared PRIVATE ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_SHARED_LIBRARIES})
set_target_properties(cxxabi_shared
PROPERTIES
CXX_EXTENSIONS
Expand Down Expand Up @@ -226,7 +226,7 @@ if (LIBCXXABI_ENABLE_STATIC)
endif()
endif()
add_library(cxxabi_static STATIC ${cxxabi_static_sources})
target_link_libraries(cxxabi_static ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_STATIC_LIBRARIES})
target_link_libraries(cxxabi_static PRIVATE ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_STATIC_LIBRARIES})
set_target_properties(cxxabi_static
PROPERTIES
CXX_EXTENSIONS
Expand Down
4 changes: 2 additions & 2 deletions libunwind/src/CMakeLists.txt
Expand Up @@ -146,7 +146,7 @@ if (LIBUNWIND_ENABLE_SHARED)
if(COMMAND llvm_setup_rpath)
llvm_setup_rpath(unwind_shared)
endif()
target_link_libraries(unwind_shared ${libraries})
target_link_libraries(unwind_shared PRIVATE ${libraries})
set_target_properties(unwind_shared
PROPERTIES
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
Expand All @@ -162,7 +162,7 @@ endif()
# Build the static library.
if (LIBUNWIND_ENABLE_STATIC)
add_library(unwind_static STATIC ${unwind_static_sources})
target_link_libraries(unwind_static ${libraries})
target_link_libraries(unwind_static PRIVATE ${libraries})
set_target_properties(unwind_static
PROPERTIES
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
Expand Down

0 comments on commit 8e78915

Please sign in to comment.