@@ -376,7 +376,7 @@ endfunction()
376
376
function (_add_variant_link_flags )
377
377
set (oneValueArgs SDK ARCH BUILD_TYPE ENABLE_ASSERTIONS ANALYZE_CODE_COVERAGE
378
378
DEPLOYMENT_VERSION_OSX DEPLOYMENT_VERSION_IOS DEPLOYMENT_VERSION_TVOS DEPLOYMENT_VERSION_WATCHOS
379
- RESULT_VAR_NAME ENABLE_LTO LTO_OBJECT_NAME LIBRARY_SEARCH_DIRECTORIES_VAR_NAME )
379
+ RESULT_VAR_NAME ENABLE_LTO LTO_OBJECT_NAME LINK_LIBRARIES_VAR_NAME LIBRARY_SEARCH_DIRECTORIES_VAR_NAME )
380
380
cmake_parse_arguments (LFLAGS
381
381
""
382
382
"${oneValueArgs} "
@@ -387,6 +387,7 @@ function(_add_variant_link_flags)
387
387
precondition (LFLAGS_ARCH MESSAGE "Should specify an architecture" )
388
388
389
389
set (result ${${LFLAGS_RESULT_VAR_NAME}} )
390
+ set (link_libraries ${${LFLAGS_LINK_LIBRARIES_VAR_NAME}} )
390
391
set (library_search_directories ${${LFLAGS_LIBRARY_SEARCH_DIRECTORIES_VAR_NAME}} )
391
392
392
393
_add_variant_c_compile_link_flags (
@@ -403,9 +404,9 @@ function(_add_variant_link_flags)
403
404
RESULT_VAR_NAME result )
404
405
405
406
if ("${LFLAGS_SDK} " STREQUAL "LINUX" )
406
- list (APPEND result "-lpthread " "-latomic " "-ldl " )
407
+ list (APPEND link_libraries "pthread " "atomic " "dl " )
407
408
elseif ("${LFLAGS_SDK} " STREQUAL "FREEBSD" )
408
- list (APPEND result "-lpthread " )
409
+ list (APPEND link_libraries "pthread " )
409
410
elseif ("${LFLAGS_SDK} " STREQUAL "CYGWIN" )
410
411
# No extra libraries required.
411
412
elseif ("${LFLAGS_SDK} " STREQUAL "WINDOWS" )
@@ -423,9 +424,10 @@ function(_add_variant_link_flags)
423
424
list (APPEND library_search_directories
424
425
${CMAKE_BINARY_DIR} /winsdk_lib_${LFLAGS_ARCH}_symlinks )
425
426
elseif ("${LFLAGS_SDK} " STREQUAL "HAIKU" )
426
- list (APPEND result "-lbsd" "-latomic" "-Wl,-Bsymbolic" )
427
+ list (APPEND link_libraries "bsd" "atomic" )
428
+ list (APPEND result "-Wl,-Bsymbolic" )
427
429
elseif ("${LFLAGS_SDK} " STREQUAL "ANDROID" )
428
- list (APPEND result "-ldl " "-llog " "-latomic " "-licudataswift " "-licui18nswift " "-licuucswift " )
430
+ list (APPEND link_libraries "dl " "log " "atomic " "icudataswift " "icui18nswift " "icuucswift " )
429
431
if ("${LFLAGS_ARCH} " MATCHES armv7 )
430
432
list (APPEND result "${SWIFT_ANDROID_NDK_PATH} /sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_shared.so" )
431
433
elseif ("${LFLAGS_ARCH} " MATCHES aarch64 )
@@ -435,7 +437,7 @@ function(_add_variant_link_flags)
435
437
endif ()
436
438
swift_android_lib_for_arch (${LFLAGS_ARCH} ${LFLAGS_ARCH} _LIB )
437
439
foreach (path IN LISTS ${LFLAGS_ARCH} _LIB )
438
- list (APPEND library_search_directories ${path} )
440
+ list (APPEND library_search_directories ${path} )
439
441
endforeach ()
440
442
else ()
441
443
# If lto is enabled, we need to add the object path flag so that the LTO code
@@ -475,6 +477,7 @@ function(_add_variant_link_flags)
475
477
endif ()
476
478
477
479
set ("${LFLAGS_RESULT_VAR_NAME} " "${result} " PARENT_SCOPE )
480
+ set ("${LFLAGS_LINK_LIBRARIES_VAR_NAME} " "${link_libraries} " PARENT_SCOPE )
478
481
set ("${LFLAGS_LIBRARY_SEARCH_DIRECTORIES_VAR_NAME} " "${library_search_directories} " PARENT_SCOPE )
479
482
endfunction ()
480
483
@@ -1207,6 +1210,7 @@ function(_add_swift_library_single target name)
1207
1210
DEPLOYMENT_VERSION_TVOS "${SWIFTLIB_DEPLOYMENT_VERSION_TVOS} "
1208
1211
DEPLOYMENT_VERSION_WATCHOS "${SWIFTLIB_DEPLOYMENT_VERSION_WATCHOS} "
1209
1212
RESULT_VAR_NAME link_flags
1213
+ LINK_LIBRARIES_VAR_NAME link_libraries
1210
1214
LIBRARY_SEARCH_DIRECTORIES_VAR_NAME library_search_directories
1211
1215
)
1212
1216
@@ -1251,6 +1255,7 @@ function(_add_swift_library_single target name)
1251
1255
COMPILE_FLAGS " ${c_compile_flags} " )
1252
1256
set_property (TARGET "${target} " APPEND_STRING PROPERTY
1253
1257
LINK_FLAGS " ${link_flags} " )
1258
+ set_property (TARGET "${target} " APPEND PROPERTY LINK_LIBRARIES ${link_libraries} )
1254
1259
swift_target_link_search_directories ("${target} " "${library_search_directories} " )
1255
1260
1256
1261
# Adjust the linked libraries for windows targets. On Windows, the link is
@@ -2119,6 +2124,7 @@ function(_add_swift_executable_single name)
2119
2124
LTO_OBJECT_NAME "${name} -${SWIFTEXE_SINGLE_SDK} -${SWIFTEXE_SINGLE_ARCHITECTURE} "
2120
2125
ANALYZE_CODE_COVERAGE "${SWIFT_ANALYZE_CODE_COVERAGE} "
2121
2126
RESULT_VAR_NAME link_flags
2127
+ LINK_LIBRARIES_VAR_NAME link_libraries
2122
2128
LIBRARY_SEARCH_DIRECTORIES_VAR_NAME library_search_directories )
2123
2129
2124
2130
if (${SWIFTEXE_SINGLE_SDK} IN_LIST SWIFT_APPLE_PLATFORMS )
@@ -2176,6 +2182,7 @@ function(_add_swift_executable_single name)
2176
2182
swift_target_link_search_directories ("${name} " "${library_search_directories} " )
2177
2183
set_property (TARGET ${name} APPEND_STRING PROPERTY
2178
2184
LINK_FLAGS " ${link_flags} " )
2185
+ set_property (TARGET ${name} APPEND PROPERTY LINK_LIBRARIES ${link_libraries} )
2179
2186
if (SWIFT_PARALLEL_LINK_JOBS )
2180
2187
set_property (TARGET ${name} PROPERTY JOB_POOL_LINK swift_link_job_pool )
2181
2188
endif ()
0 commit comments