Skip to content

Commit b3e8661

Browse files
authored
[build] set linker parameters in a single way (#30339)
After noticing that also in CMake 3.16 the LINKER: prefix is not expanded correctly when used in `target_link_options`, prefer to set the linker parameters in a more verbose way and leave a comment behind on when this behavior was observed in case we want to change the implementation later. Follow up to #29636. Addresses rdar://problem/59732421
1 parent fbdf729 commit b3e8661

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -732,26 +732,18 @@ function(_add_swift_host_library_single target)
732732
# Include LLVM Bitcode slices for iOS, Watch OS, and Apple TV OS device libraries.
733733
if(SWIFT_EMBED_BITCODE_SECTION)
734734
if(${SWIFT_HOST_VARIANT_SDK} MATCHES "(I|TV|WATCH)OS")
735-
# The two branches of this if statement accomplish the same end result
736-
# We are simply accounting for the fact that on CMake < 3.16
737-
# using a generator expression to
738-
# specify a LINKER: argument does not work,
735+
target_link_options(${target} PRIVATE
736+
"LINKER:-bitcode_bundle"
737+
"LINKER:-lto_library,${LLVM_LIBRARY_DIR}/libLTO.dylib")
738+
739+
# Please note that using a generator expression to fit
740+
# this in a single target_link_options does not work
741+
# (at least in CMake 3.15 and 3.16),
739742
# since that seems not to allow the LINKER: prefix to be
740743
# evaluated (i.e. it will be added as-is to the linker parameters)
741-
if(CMAKE_VERSION VERSION_LESS 3.16)
742-
target_link_options(${target} PRIVATE
743-
"LINKER:-bitcode_bundle"
744-
"LINKER:-lto_library,${LLVM_LIBRARY_DIR}/libLTO.dylib")
745-
746-
if(SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS)
747-
target_link_options(${target} PRIVATE
748-
"LINKER:-bitcode_hide_symbols")
749-
endif()
750-
else()
744+
if(SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS)
751745
target_link_options(${target} PRIVATE
752-
"LINKER:-bitcode_bundle"
753-
$<$<BOOL:SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS>:"LINKER:-bitcode_hide_symbols">
754-
"LINKER:-lto_library,${LLVM_LIBRARY_DIR}/libLTO.dylib")
746+
"LINKER:-bitcode_hide_symbols")
755747
endif()
756748
endif()
757749
endif()

0 commit comments

Comments
 (0)