@@ -1530,8 +1530,14 @@ function(add_swift_target_library_single target name)
1530
1530
"${SWIFT_NATIVE_SWIFT_TOOLS_PATH} /../lib/swift/${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK} _LIB_SUBDIR}" )
1531
1531
target_link_directories (${target_static} PRIVATE
1532
1532
${library_search_directories} )
1533
+
1534
+ _list_add_string_suffix(
1535
+ "${SWIFTLIB_SINGLE_PRIVATE_LINK_LIBRARIES} "
1536
+ "-static"
1537
+ target_private_libs)
1538
+
1533
1539
target_link_libraries ("${target_static} " PRIVATE
1534
- ${SWIFTLIB_SINGLE_PRIVATE_LINK_LIBRARIES } )
1540
+ ${target_private_libs } )
1535
1541
1536
1542
# Force executables linker language to be CXX so that we do not link using the
1537
1543
# host toolchain swiftc.
@@ -2551,7 +2557,8 @@ endfunction()
2551
2557
# The Swift installation component that this executable belongs to.
2552
2558
# Defaults to never_install.
2553
2559
function (_add_swift_target_executable_single name )
2554
- set (options )
2560
+ set (options
2561
+ NOSWIFTRT)
2555
2562
set (single_parameter_options
2556
2563
ARCHITECTURE
2557
2564
SDK
@@ -2629,6 +2636,15 @@ function(_add_swift_target_executable_single name)
2629
2636
${SWIFTEXE_SINGLE_SOURCES}
2630
2637
${SWIFTEXE_SINGLE_EXTERNAL_SOURCES} )
2631
2638
2639
+ # ELF and COFF need swiftrt
2640
+ if (("${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _OBJECT_FORMAT}" STREQUAL "ELF" OR
2641
+ "${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _OBJECT_FORMAT}" STREQUAL "COFF" )
2642
+ AND NOT SWIFTEXE_SINGLE_NOSWIFTRT)
2643
+ target_sources (${name}
2644
+ PRIVATE
2645
+ $<TARGET_OBJECTS:swiftImageRegistrationObject${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _OBJECT_FORMAT}-${SWIFT_SDK_${SWIFTEXE_SINGLE_SDK} _LIB_SUBDIR}-${SWIFTEXE_SINGLE_ARCHITECTURE} >)
2646
+ endif ()
2647
+
2632
2648
add_dependencies_multiple_targets(
2633
2649
TARGETS "${name} "
2634
2650
DEPENDS
@@ -2692,6 +2708,24 @@ function(_add_swift_target_executable_single name)
2692
2708
set_target_properties (${name} PROPERTIES FOLDER "Swift executables" )
2693
2709
endfunction ()
2694
2710
2711
+ # Conditionally append -static to a name, if that variant is a valid target
2712
+ function (append_static name result_var_name)
2713
+ cmake_parse_arguments (APPEND_TARGET
2714
+ "STATIC_SWIFT_STDLIB"
2715
+ ""
2716
+ ""
2717
+ ${ARGN} )
2718
+ if (STATIC_SWIFT_STDLIB)
2719
+ if (TARGET "${name} -static" )
2720
+ set ("${result_var_name} " "${name} -static" PARENT_SCOPE)
2721
+ else ()
2722
+ set ("${result_var_name} " "${name} " PARENT_SCOPE)
2723
+ endif ()
2724
+ else ()
2725
+ set ("${result_var_name} " "${name} " PARENT_SCOPE)
2726
+ endif ()
2727
+ endfunction ()
2728
+
2695
2729
# Add an executable for each target variant. Executables are given suffixes
2696
2730
# with the variant SDK and ARCH.
2697
2731
#
@@ -2700,7 +2734,9 @@ function(add_swift_target_executable name)
2700
2734
set (SWIFTEXE_options
2701
2735
EXCLUDE_FROM_ALL
2702
2736
BUILD_WITH_STDLIB
2703
- BUILD_WITH_LIBEXEC)
2737
+ BUILD_WITH_LIBEXEC
2738
+ PREFER_STATIC
2739
+ NOSWIFTRT)
2704
2740
set (SWIFTEXE_single_parameter_options
2705
2741
INSTALL_IN_COMPONENT)
2706
2742
set (SWIFTEXE_multiple_parameter_options
@@ -2886,8 +2922,12 @@ function(add_swift_target_executable name)
2886
2922
list (APPEND swiftexe_module_dependency_targets
2887
2923
"swift${mod}${MODULE_VARIANT_SUFFIX} " )
2888
2924
2889
- list (APPEND swiftexe_link_libraries_targets
2890
- "swift${mod}${VARIANT_SUFFIX} " )
2925
+ set (library_target "swift${mod}${VARIANT_SUFFIX} " )
2926
+ if (SWIFTEXE_TARGET_PREFER_STATIC AND TARGET "${library_target} -static" )
2927
+ set (library_target "${library_target} -static" )
2928
+ endif ()
2929
+
2930
+ list (APPEND swiftexe_link_libraries_targets "${library_target} " )
2891
2931
endforeach ()
2892
2932
2893
2933
# Don't add the ${arch} to the suffix. We want to link against fat
@@ -2899,6 +2939,7 @@ function(add_swift_target_executable name)
2899
2939
2900
2940
_add_swift_target_executable_single(
2901
2941
${VARIANT_NAME}
2942
+ ${SWIFTEXE_TARGET_NOSWIFTRT_keyword}
2902
2943
${SWIFTEXE_TARGET_SOURCES}
2903
2944
DEPENDS
2904
2945
${SWIFTEXE_TARGET_DEPENDS_with_suffix}
0 commit comments