Skip to content

Commit 8e78915

Browse files
committedJan 30, 2019
[CMake] Use correct visibility for linked libraries in CMake
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
1 parent 1f7eda5 commit 8e78915

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed
 

‎libcxx/benchmarks/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function(add_benchmark_test name source_file)
137137
add_executable(${libcxx_target} EXCLUDE_FROM_ALL ${source_file})
138138
add_dependencies(${libcxx_target} cxx cxx-headers google-benchmark-libcxx)
139139
add_dependencies(cxx-benchmarks ${libcxx_target})
140+
target_link_libraries(${libcxx_target} ${LIBCXX_LIBRARIES})
140141
if (LIBCXX_ENABLE_SHARED)
141142
target_link_libraries(${libcxx_target} cxx_shared)
142143
else()

‎libcxx/lib/CMakeLists.txt

+7-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ if (LIBCXX_ENABLE_SHARED)
241241
if(COMMAND llvm_setup_rpath)
242242
llvm_setup_rpath(cxx_shared)
243243
endif()
244-
target_link_libraries(cxx_shared ${LIBCXX_LIBRARIES})
244+
target_link_libraries(cxx_shared PRIVATE ${LIBCXX_LIBRARIES})
245245
set_target_properties(cxx_shared
246246
PROPERTIES
247247
LINK_FLAGS "${LIBCXX_LINK_FLAGS}"
@@ -265,7 +265,7 @@ endif()
265265
# Build the static library.
266266
if (LIBCXX_ENABLE_STATIC)
267267
add_library(cxx_static STATIC ${cxx_static_sources})
268-
target_link_libraries(cxx_static ${LIBCXX_LIBRARIES})
268+
target_link_libraries(cxx_static PRIVATE ${LIBCXX_LIBRARIES})
269269
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")
270270
set_target_properties(cxx_static
271271
PROPERTIES
@@ -461,3 +461,8 @@ if (NOT CMAKE_CONFIGURATION_TYPES AND (LIBCXX_INSTALL_LIBRARY OR
461461
-P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
462462
add_custom_target(install-libcxx DEPENDS install-cxx)
463463
endif()
464+
465+
# TODO: This is needed by cxx-benchmarks but this variable isn't
466+
# available outside of the scope of this file so we need to export
467+
# it. This is not necessarily the cleanest solution.
468+
set(LIBCXX_LIBRARIES ${LIBCXX_LIBRARIES} PARENT_SCOPE)

‎libcxxabi/src/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ if (LIBCXXABI_ENABLE_SHARED)
189189
if(COMMAND llvm_setup_rpath)
190190
llvm_setup_rpath(cxxabi_shared)
191191
endif()
192-
target_link_libraries(cxxabi_shared ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_SHARED_LIBRARIES})
192+
target_link_libraries(cxxabi_shared PRIVATE ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_SHARED_LIBRARIES})
193193
set_target_properties(cxxabi_shared
194194
PROPERTIES
195195
CXX_EXTENSIONS
@@ -226,7 +226,7 @@ if (LIBCXXABI_ENABLE_STATIC)
226226
endif()
227227
endif()
228228
add_library(cxxabi_static STATIC ${cxxabi_static_sources})
229-
target_link_libraries(cxxabi_static ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_STATIC_LIBRARIES})
229+
target_link_libraries(cxxabi_static PRIVATE ${LIBCXXABI_LIBRARIES} ${LIBCXXABI_STATIC_LIBRARIES})
230230
set_target_properties(cxxabi_static
231231
PROPERTIES
232232
CXX_EXTENSIONS

‎libunwind/src/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ if (LIBUNWIND_ENABLE_SHARED)
146146
if(COMMAND llvm_setup_rpath)
147147
llvm_setup_rpath(unwind_shared)
148148
endif()
149-
target_link_libraries(unwind_shared ${libraries})
149+
target_link_libraries(unwind_shared PRIVATE ${libraries})
150150
set_target_properties(unwind_shared
151151
PROPERTIES
152152
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
@@ -162,7 +162,7 @@ endif()
162162
# Build the static library.
163163
if (LIBUNWIND_ENABLE_STATIC)
164164
add_library(unwind_static STATIC ${unwind_static_sources})
165-
target_link_libraries(unwind_static ${libraries})
165+
target_link_libraries(unwind_static PRIVATE ${libraries})
166166
set_target_properties(unwind_static
167167
PROPERTIES
168168
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"

0 commit comments

Comments
 (0)