@@ -698,7 +698,7 @@ function(_add_swift_lipo_target)
698698 DEPENDS ${source_targets} )
699699 endif ()
700700endfunction ()
701-
701+
702702# Add a single variant of a new Swift library.
703703#
704704# Usage:
@@ -1317,38 +1317,46 @@ function(add_swift_target_library_single target name)
13171317 # Set compile and link flags for the non-static target.
13181318 # Do these LAST.
13191319 set (target_static)
1320- if (SWIFTLIB_SINGLE_IS_STDLIB AND SWIFTLIB_SINGLE_STATIC AND NOT SWIFTLIB_SINGLE_INSTALL_WITH_SHARED )
1320+ if (SWIFTLIB_SINGLE_IS_STDLIB AND SWIFTLIB_SINGLE_STATIC)
13211321 set (target_static "${target} -static" )
13221322
1323- # We have already compiled Swift sources. Link everything into a static
1324- # library.
1325- add_library (${target_static} STATIC
1323+ if (SWIFTLIB_SINGLE_INSTALL_WITH_SHARED)
1324+ # Create an interface library for the static version, and explicitly
1325+ # add the output path for the non-static version to its libraries.
1326+ add_library (${target_static} INTERFACE )
1327+ add_dependencies (${target_static} ${target} )
1328+ target_link_libraries (${target_static} INTERFACE $<TARGET_FILE:${target} >)
1329+ else ()
1330+ # We have already compiled Swift sources. Link everything into a static
1331+ # library.
1332+ add_library (${target_static} STATIC
13261333 ${SWIFTLIB_SINGLE_SOURCES}
13271334 ${SWIFTLIB_INCORPORATED_OBJECT_LIBRARIES_EXPRESSIONS}
13281335 ${SWIFTLIB_SINGLE_XCODE_WORKAROUND_SOURCES} )
13291336
1330- set_output_directory(${target_static}
1337+ set_output_directory(${target_static}
13311338 BINARY_DIR ${out_bin_dir}
13321339 LIBRARY_DIR ${out_lib_dir} )
13331340
1334- if (SWIFTLIB_INSTALL_WITH_SHARED)
1335- set (swift_lib_dir ${lib_dir} )
1336- else ()
1337- set (swift_lib_dir ${static_lib_dir} )
1338- endif ()
1341+ if (SWIFTLIB_INSTALL_WITH_SHARED)
1342+ set (swift_lib_dir ${lib_dir} )
1343+ else ()
1344+ set (swift_lib_dir ${static_lib_dir} )
1345+ endif ()
13391346
1340- foreach (config ${CMAKE_CONFIGURATION_TYPES} )
1341- string (TOUPPER ${config} config_upper)
1342- escape_path_for_xcode(
1347+ foreach (config ${CMAKE_CONFIGURATION_TYPES} )
1348+ string (TOUPPER ${config} config_upper)
1349+ escape_path_for_xcode(
13431350 "${config} " "${swift_lib_dir} " config_lib_dir)
1344- set_target_properties (${target_static} PROPERTIES
1345- LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir} /${output_sub_dir}
1346- ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir} /${output_sub_dir} )
1347- endforeach ()
1351+ set_target_properties (${target_static} PROPERTIES
1352+ LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir} /${output_sub_dir}
1353+ ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir} /${output_sub_dir} )
1354+ endforeach ()
13481355
1349- set_target_properties (${target_static} PROPERTIES
1350- LIBRARY_OUTPUT_DIRECTORY ${swift_lib_dir} /${output_sub_dir}
1351- ARCHIVE_OUTPUT_DIRECTORY ${swift_lib_dir} /${output_sub_dir} )
1356+ set_target_properties (${target_static} PROPERTIES
1357+ LIBRARY_OUTPUT_DIRECTORY ${swift_lib_dir} /${output_sub_dir}
1358+ ARCHIVE_OUTPUT_DIRECTORY ${swift_lib_dir} /${output_sub_dir} )
1359+ endif ()
13521360 endif ()
13531361
13541362 set_target_properties (${target}
@@ -1644,9 +1652,10 @@ function(add_swift_target_library_single target name)
16441652 LINKER_LANGUAGE "CXX" )
16451653 endif ()
16461654
1647- if (target_static)
1655+ if (target_static AND NOT SWIFTLIB_SINGLE_INSTALL_WITH_SHARED )
16481656 target_compile_options (${target_static} PRIVATE
16491657 ${c_compile_flags} )
1658+
16501659 # FIXME: The fallback paths here are going to be dynamic libraries.
16511660
16521661 if (SWIFTLIB_INSTALL_WITH_SHARED)
0 commit comments