Skip to content

Commit 8a76358

Browse files
authored
[build] avoid use generator expression to add linker parameter (#29636)
* [build] use generator expression only on CMake > 3.15 In CMake < 3.16, Generator expressions seem not to allow the `LINKER:` prefix to be expanded correctly when used in `target_link_options`. To account for this, account for two code paths according to CMake version -- use the generator expression when detecting we are on 3.16 and resort to an if statement otherwise Addresses rdar://problem/59117166
1 parent 6c29541 commit 8a76358

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,27 @@ function(_add_swift_library_single target name)
14031403
# Include LLVM Bitcode slices for iOS, Watch OS, and Apple TV OS device libraries.
14041404
if(SWIFT_EMBED_BITCODE_SECTION AND NOT SWIFTLIB_SINGLE_DONT_EMBED_BITCODE)
14051405
if(${SWIFTLIB_SINGLE_SDK} MATCHES "(I|TV|WATCH)OS")
1406-
target_link_options(${target} PRIVATE
1407-
"LINKER:-bitcode_bundle"
1408-
$<$<BOOL:SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS>:"LINKER:-bitcode_hide_symbols">
1409-
"LINKER:-lto_library,${LLVM_LIBRARY_DIR}/libLTO.dylib")
1406+
# The two branches of this if statement accomplish the same end result
1407+
# We are simply accounting for the fact that on CMake < 3.16
1408+
# using a generator expression to
1409+
# specify a LINKER: argument does not work,
1410+
# since that seems not to allow the LINKER: prefix to be
1411+
# evaluated (i.e. it will be added as-is to the linker parameters)
1412+
if(CMAKE_VERSION VERSION_LESS 3.16)
1413+
target_link_options(${target} PRIVATE
1414+
"LINKER:-bitcode_bundle"
1415+
"LINKER:-lto_library,${LLVM_LIBRARY_DIR}/libLTO.dylib")
1416+
1417+
if(SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS)
1418+
target_link_options(${target} PRIVATE
1419+
"LINKER:-bitcode_hide_symbols")
1420+
endif()
1421+
else()
1422+
target_link_options(${target} PRIVATE
1423+
"LINKER:-bitcode_bundle"
1424+
$<$<BOOL:SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS>:"LINKER:-bitcode_hide_symbols">
1425+
"LINKER:-lto_library,${LLVM_LIBRARY_DIR}/libLTO.dylib")
1426+
endif()
14101427
endif()
14111428
endif()
14121429
endif()

0 commit comments

Comments
 (0)