@@ -708,14 +708,6 @@ function(_add_swift_lipo_target)
708
708
endif ()
709
709
endfunction ()
710
710
711
- function (swift_target_link_search_directories target directories)
712
- set (STLD_FLAGS "" )
713
- foreach (directory ${directories} )
714
- set (STLD_FLAGS "${STLD_FLAGS} \" ${CMAKE_LIBRARY_PATH_FLAG}${directory} \" " )
715
- endforeach ()
716
- set_property (TARGET ${target} APPEND_STRING PROPERTY LINK_FLAGS ${STLD_FLAGS} )
717
- endfunction ()
718
-
719
711
# Add a single variant of a new Swift library.
720
712
#
721
713
# Usage:
@@ -892,22 +884,10 @@ function(_add_swift_library_single target name)
892
884
if (SWIFT_EMBED_BITCODE_SECTION AND NOT SWIFTLIB_SINGLE_DONT_EMBED_BITCODE)
893
885
if ("${SWIFTLIB_SINGLE_SDK} " STREQUAL "IOS" OR "${SWIFTLIB_SINGLE_SDK} " STREQUAL "TVOS" OR "${SWIFTLIB_SINGLE_SDK} " STREQUAL "WATCHOS" )
894
886
list (APPEND SWIFTLIB_SINGLE_C_COMPILE_FLAGS "-fembed-bitcode" )
895
- list (APPEND SWIFTLIB_SINGLE_LINK_FLAGS "-Xlinker" "-bitcode_bundle" "-Xlinker" "-lto_library" "-Xlinker" "${LLVM_LIBRARY_DIR} /libLTO.dylib" )
896
- # If we are asked to hide symbols, pass the obfuscation flag to libLTO.
897
- if (SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS)
898
- list (APPEND SWIFTLIB_SINGLE_LINK_FLAGS "-Xlinker" "-bitcode_hide_symbols" )
899
- endif ()
900
887
set (embed_bitcode_arg EMBED_BITCODE)
901
888
endif ()
902
889
endif ()
903
890
904
- if (${SWIFTLIB_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
905
- list (APPEND SWIFTLIB_SINGLE_LINK_FLAGS "-Xlinker" "-compatibility_version" "-Xlinker" "1" )
906
- if (SWIFT_COMPILER_VERSION)
907
- list (APPEND SWIFTLIB_SINGLE_LINK_FLAGS "-Xlinker" "-current_version" "-Xlinker" "${SWIFT_COMPILER_VERSION} " )
908
- endif ()
909
- endif ()
910
-
911
891
if (XCODE)
912
892
string (REGEX MATCHALL "/[^/]+" split_path ${CMAKE_CURRENT_SOURCE_DIR} )
913
893
list (GET split_path -1 dir)
@@ -1281,23 +1261,6 @@ function(_add_swift_library_single target name)
1281
1261
"${swift_module_dependency_target} "
1282
1262
${LLVM_COMMON_DEPENDS} )
1283
1263
1284
- # HACK: On some systems or build directory setups, CMake will not find static
1285
- # archives of Clang libraries in the Clang build directory, and it will pass
1286
- # them as '-lclangFoo'. Some other logic in CMake would reorder libraries
1287
- # specified with this syntax, which breaks linking.
1288
- set (prefixed_link_libraries)
1289
- foreach (dep ${SWIFTLIB_SINGLE_LINK_LIBRARIES} )
1290
- if ("${dep} " MATCHES "^clang" )
1291
- if ("${SWIFT_HOST_VARIANT_SDK} " STREQUAL "WINDOWS" )
1292
- set (dep "${LLVM_LIBRARY_OUTPUT_INTDIR} /${dep} .lib" )
1293
- else ()
1294
- set (dep "${LLVM_LIBRARY_OUTPUT_INTDIR} /lib${dep} .a" )
1295
- endif ()
1296
- endif ()
1297
- list (APPEND prefixed_link_libraries "${dep} " )
1298
- endforeach ()
1299
- set (SWIFTLIB_SINGLE_LINK_LIBRARIES "${prefixed_link_libraries} " )
1300
-
1301
1264
if ("${libkind} " STREQUAL "SHARED" )
1302
1265
target_link_libraries ("${target} " PRIVATE ${SWIFTLIB_SINGLE_LINK_LIBRARIES} )
1303
1266
elseif ("${libkind} " STREQUAL "OBJECT" )
@@ -1463,17 +1426,32 @@ function(_add_swift_library_single target name)
1463
1426
set (PLIST_INFO_BUILD_VERSION)
1464
1427
endif ()
1465
1428
1466
- # Convert variables to space-separated strings.
1467
- _list_escape_for_shell("${c_compile_flags} " c_compile_flags)
1468
- _list_escape_for_shell("${link_flags} " link_flags )
1469
-
1470
1429
# Set compilation and link flags.
1471
- set_property (TARGET "${target} " APPEND_STRING PROPERTY
1472
- COMPILE_FLAGS " ${c_compile_flags} " )
1473
- set_property (TARGET "${target} " APPEND_STRING PROPERTY
1474
- LINK_FLAGS " ${link_flags} " )
1475
- set_property (TARGET "${target} " APPEND PROPERTY LINK_LIBRARIES ${link_libraries} )
1476
- swift_target_link_search_directories("${target} " "${library_search_directories} " )
1430
+ target_compile_options (${target} PRIVATE
1431
+ ${c_compile_flags} )
1432
+ target_link_options (${target} PRIVATE
1433
+ ${link_flags} )
1434
+ if (${SWIFTLIB_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS)
1435
+ target_link_options (${target} PRIVATE
1436
+ "LINKER:-compatibility_version,1" )
1437
+ if (SWIFT_COMPILER_VERSION)
1438
+ target_link_options (${target} PRIVATE
1439
+ "LINKER:-current_version,${SWIFT_COMPILER_VERSION} " )
1440
+ endif ()
1441
+ # Include LLVM Bitcode slices for iOS, Watch OS, and Apple TV OS device libraries.
1442
+ if (SWIFT_EMBED_BITCODE_SECTION AND NOT SWIFTLIB_SINGLE_DONT_EMBED_BITCODE)
1443
+ if (${SWIFTLIB_SINGLE_SDK} MATCHES "(I|TV|WATCH)OS" )
1444
+ target_link_options (${target} PRIVATE
1445
+ "LINKER:-bitcode_bundle"
1446
+ $<$<BOOL :SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS>:"LINKER:-bitcode_hide_symbols" >
1447
+ "LINKER:-lto_library,${LLVM_LIBRARY_DIR} /libLTO.dylib" )
1448
+ endif ()
1449
+ endif ()
1450
+ endif ()
1451
+ target_link_libraries (${target} PRIVATE
1452
+ ${link_libraries} )
1453
+ target_link_directories (${target} PRIVATE
1454
+ ${library_search_directories} )
1477
1455
1478
1456
# Adjust the linked libraries for windows targets. On Windows, the link is
1479
1457
# performed against the import library, and the runtime uses the dll. Not
@@ -1523,8 +1501,8 @@ function(_add_swift_library_single target name)
1523
1501
endif ()
1524
1502
1525
1503
if (target_static)
1526
- set_property ( TARGET " ${target_static} " APPEND_STRING PROPERTY
1527
- COMPILE_FLAGS " ${c_compile_flags} " )
1504
+ target_link_options ( ${target_static} PRIVATE
1505
+ ${c_compile_flags} )
1528
1506
# FIXME: The fallback paths here are going to be dynamic libraries.
1529
1507
1530
1508
if (SWIFTLIB_INSTALL_WITH_SHARED)
@@ -1536,7 +1514,8 @@ function(_add_swift_library_single target name)
1536
1514
"${search_base_dir} /${SWIFTLIB_SINGLE_SUBDIR} "
1537
1515
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFTLIB_SINGLE_SUBDIR} "
1538
1516
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK} _LIB_SUBDIR}" )
1539
- swift_target_link_search_directories("${target_static} " "${library_search_directories} " )
1517
+ target_link_directories (${target_static} PRIVATE
1518
+ ${library_search_directories} )
1540
1519
target_link_libraries ("${target_static} " PRIVATE
1541
1520
${SWIFTLIB_SINGLE_PRIVATE_LINK_LIBRARIES} )
1542
1521
endif ()
@@ -2637,16 +2616,14 @@ function(_add_swift_executable_single name)
2637
2616
${SWIFTEXE_SINGLE_DEPENDS} )
2638
2617
llvm_update_compile_flags("${name} " )
2639
2618
2640
- # Convert variables to space-separated strings.
2641
- _list_escape_for_shell("${c_compile_flags} " c_compile_flags)
2642
- _list_escape_for_shell("${link_flags} " link_flags )
2643
-
2644
- set_property (TARGET ${name} APPEND_STRING PROPERTY
2645
- COMPILE_FLAGS " ${c_compile_flags} " )
2646
- swift_target_link_search_directories("${name} " "${library_search_directories} " )
2647
- set_property (TARGET ${name} APPEND_STRING PROPERTY
2648
- LINK_FLAGS " ${link_flags} " )
2649
- set_property (TARGET ${name} APPEND PROPERTY LINK_LIBRARIES ${link_libraries} )
2619
+ target_compile_options (${name} PRIVATE
2620
+ ${c_compile_flags} )
2621
+ target_link_directories (${name} PRIVATE
2622
+ ${library_search_directories} )
2623
+ target_link_options (${name} PRIVATE
2624
+ ${link_flags} )
2625
+ target_link_libraries (${name} PRIVATE
2626
+ ${link_libraries} )
2650
2627
if (SWIFT_PARALLEL_LINK_JOBS)
2651
2628
set_property (TARGET ${name} PROPERTY JOB_POOL_LINK swift_link_job_pool)
2652
2629
endif ()
0 commit comments