Skip to content

Commit 3c227a3

Browse files
authored
[cmake] Silence a duplicate libraries warning from Apple's linker (#85012)
ld: warning: ignoring duplicate libraries: This triggers quite frequently in llvm's build because CMake's library depends mechanism doesn't de-duplicate libraries on the link line. Duplication is necessary for ELF platforms, but means something subtly different on Darwin platforms, hence the warning. Since we don't have much control over that from CMake, just disable the warning wholesale whenever the linker is detected to support it.
1 parent f46f5a0 commit 3c227a3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,16 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
257257
message(STATUS "Linker detection: unknown")
258258
endif()
259259
endif()
260+
261+
# Apple's linker complains about duplicate libraries, which CMake likes to do
262+
# to support ELF platforms. To silence that warning, we can use
263+
# -no_warn_duplicate_libraries, but only in versions of the linker that
264+
# support that flag.
265+
if(NOT LLVM_USE_LINKER AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
266+
check_linker_flag(C "-Wl,-no_warn_duplicate_libraries" LLVM_LINKER_SUPPORTS_NO_WARN_DUPLICATE_LIBRARIES)
267+
else()
268+
set(LLVM_LINKER_SUPPORTS_NO_WARN_DUPLICATE_LIBRARIES OFF CACHE INTERNAL "")
269+
endif()
260270
endif()
261271

262272
function(add_link_opts target_name)
@@ -310,6 +320,11 @@ function(add_link_opts target_name)
310320
endif()
311321
endif()
312322

323+
if(LLVM_LINKER_SUPPORTS_NO_WARN_DUPLICATE_LIBRARIES)
324+
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
325+
LINK_FLAGS " -Wl,-no_warn_duplicate_libraries")
326+
endif()
327+
313328
if(ARG_SUPPORT_PLUGINS AND ${CMAKE_SYSTEM_NAME} MATCHES "AIX")
314329
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
315330
LINK_FLAGS " -Wl,-brtl")

0 commit comments

Comments
 (0)