Skip to content

Commit 71121a4

Browse files
authored
Merge pull request #72284 from tshortli/cmake-no-warn-duplicate-libraries
CMake: Pass `-no_warn_duplicate_libraries` to the linker when supported
2 parents a245391 + 347a140 commit 71121a4

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,18 @@ endif()
979979
set(SWIFT_USE_LINKER ${SWIFT_USE_LINKER_default} CACHE STRING
980980
"Build Swift with a non-default linker")
981981

982+
include(CheckLinkerFlag)
983+
984+
# Apple's linker complains about duplicate libraries, which CMake likes to do
985+
# to support ELF platforms. To silence that warning, we can use
986+
# -no_warn_duplicate_libraries, but only in versions of the linker that
987+
# support that flag.
988+
if(NOT LLVM_USE_LINKER AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
989+
check_linker_flag(C "-Wl,-no_warn_duplicate_libraries" SWIFT_LINKER_SUPPORTS_NO_WARN_DUPLICATE_LIBRARIES)
990+
else()
991+
set(SWIFT_LINKER_SUPPORTS_NO_WARN_DUPLICATE_LIBRARIES OFF CACHE INTERNAL "")
992+
endif()
993+
982994
#
983995
# Enable additional warnings.
984996
#

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,12 @@ function(_add_host_variant_link_flags target)
441441
"SHELL:-Xlinker -dead_strip")
442442
endif()
443443
endif()
444+
445+
if(SWIFT_LINKER_SUPPORTS_NO_WARN_DUPLICATE_LIBRARIES)
446+
target_link_options(${target} PRIVATE
447+
"SHELL:-Xlinker -no_warn_duplicate_libraries")
448+
endif()
449+
444450
endfunction()
445451
446452
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)

0 commit comments

Comments
 (0)