@@ -29,7 +29,7 @@ function(handle_swift_sources
2929 dependency_sibgen_target_out_var_name
3030 sourcesvar externalvar name )
3131 cmake_parse_arguments (SWIFTSOURCES
32- "IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE"
32+ "IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC "
3333 "SDK;ARCHITECTURE;INSTALL_IN_COMPONENT;MACCATALYST_BUILD_FLAVOR"
3434 "DEPENDS;COMPILE_FLAGS;MODULE_NAME"
3535 ${ARGN} )
@@ -41,6 +41,8 @@ function(handle_swift_sources
4141 IS_SDK_OVERLAY_arg)
4242 translate_flag(${SWIFTSOURCES_EMBED_BITCODE} "EMBED_BITCODE"
4343 EMBED_BITCODE_arg)
44+ translate_flag(${SWIFTSOURCES_STATIC} "STATIC"
45+ STATIC_arg)
4446
4547 if (SWIFTSOURCES_IS_MAIN)
4648 set (SWIFTSOURCES_INSTALL_IN_COMPONENT never_install)
@@ -278,13 +280,15 @@ endfunction()
278280# [MODULE_NAME] # The module name.
279281# [INSTALL_IN_COMPONENT] # Install produced files.
280282# [EMBED_BITCODE] # Embed LLVM bitcode into the .o files
283+ # [STATIC] # Also write .swiftmodule etc. to static
284+ # # resource folder
281285# )
282286function (_compile_swift_files
283287 dependency_target_out_var_name dependency_module_target_out_var_name
284288 dependency_sib_target_out_var_name dependency_sibopt_target_out_var_name
285289 dependency_sibgen_target_out_var_name)
286290 cmake_parse_arguments (SWIFTFILE
287- "IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE"
291+ "IS_MAIN;IS_STDLIB;IS_STDLIB_CORE;IS_SDK_OVERLAY;EMBED_BITCODE;STATIC "
288292 "OUTPUT;MODULE_NAME;INSTALL_IN_COMPONENT;MACCATALYST_BUILD_FLAVOR"
289293 "SOURCES;FLAGS;DEPENDS;SDK;ARCHITECTURE;OPT_FLAGS;MODULE_DIR"
290294 ${ARGN} )
@@ -448,8 +452,11 @@ function(_compile_swift_files
448452 endforeach ()
449453
450454 set (module_file)
455+ set (module_file_static)
451456 set (module_doc_file)
457+ set (module_doc_file_static)
452458 set (interface_file)
459+ set (interface_file_static)
453460
454461 if (NOT SWIFTFILE_IS_MAIN)
455462 # Determine the directory where the module file should be placed.
@@ -464,17 +471,28 @@ function(_compile_swift_files
464471 list (APPEND swift_flags "-parse-as-library" )
465472
466473 set (module_base "${module_dir} /${SWIFTFILE_MODULE_NAME} " )
474+
475+ set (module_dir_static "${SWIFTSTATICLIB_DIR} /${library_subdir} " )
476+ set (module_base_static "${module_dir_static} /${SWIFTFILE_MODULE_NAME} " )
477+
467478 set (module_triple ${SWIFT_SDK_${library_subdir_sdk} _ARCH_${SWIFTFILE_ARCHITECTURE} _MODULE})
468479 if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS OR
469480 SWIFTFILE_SDK STREQUAL "MACCATALYST" )
470481 set (specific_module_dir "${module_base} .swiftmodule" )
471482 set (module_base "${module_base} .swiftmodule/${module_triple} " )
483+
484+ set (specific_module_dir_static "${module_base_static} .swiftmodule" )
485+ set (module_base_static "${module_base_static} .swiftmodule/${module_triple} " )
472486 else ()
473487 set (specific_module_dir)
488+ set (specific_module_dir_static)
474489 endif ()
475490 set (module_file "${module_base} .swiftmodule" )
476491 set (module_doc_file "${module_base} .swiftdoc" )
477492
493+ set (module_file_static "${module_base_static} .swiftmodule" )
494+ set (module_doc_file_static "${module_base_static} .swiftdoc" )
495+
478496 # FIXME: These don't really belong inside the swiftmodule, but there's not
479497 # an obvious alternate place to put them.
480498 set (sib_file "${module_base} .Onone.sib" )
@@ -483,6 +501,7 @@ function(_compile_swift_files
483501
484502 if (SWIFT_ENABLE_MODULE_INTERFACES)
485503 set (interface_file "${module_base} .swiftinterface" )
504+ set (interface_file_static "${module_base_static} .swiftinterface" )
486505 list (APPEND swift_module_flags
487506 "-emit-module-interface-path" "${interface_file} " )
488507 endif ()
@@ -510,10 +529,20 @@ function(_compile_swift_files
510529 swift_install_in_component(DIRECTORY "${specific_module_dir} "
511530 DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift/${library_subdir} "
512531 COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} " )
532+ if (SWIFTFILE_STATIC)
533+ swift_install_in_component(DIRECTORY "${specific_module_dir_static} "
534+ DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift_static/${library_subdir} "
535+ COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} " )
536+ endif ()
513537 else ()
514538 swift_install_in_component(FILES ${module_outputs}
515539 DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift/${library_subdir} "
516540 COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} " )
541+ if (SWIFTFILE_STATIC)
542+ swift_install_in_component(FILES ${module_outputs}
543+ DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift_static/${library_subdir} "
544+ COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} " )
545+ endif ()
517546 endif ()
518547
519548 # macCatalyst zippered module setup
@@ -563,8 +592,10 @@ function(_compile_swift_files
563592 endif ()
564593
565594 set (module_outputs "${module_file} " "${module_doc_file} " )
595+ set (module_outputs_static "${module_file_static} " "${module_doc_file_static} " )
566596 if (interface_file)
567597 list (APPEND module_outputs "${interface_file} " )
598+ list (APPEND module_outputs_static "${interface_file_static} " )
568599 endif ()
569600
570601 if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
@@ -573,10 +604,23 @@ function(_compile_swift_files
573604 COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} "
574605 OPTIONAL
575606 PATTERN "Project" EXCLUDE )
607+
608+ if (SWIFTFILE_STATIC)
609+ swift_install_in_component(DIRECTORY "${specific_module_dir_static} "
610+ DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift_static/${library_subdir} "
611+ COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} "
612+ OPTIONAL
613+ PATTERN "Project" EXCLUDE )
614+ endif ()
576615 else ()
577616 swift_install_in_component(FILES ${module_outputs}
578617 DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift/${library_subdir} "
579618 COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} " )
619+ if (SWIFTFILE_STATIC)
620+ swift_install_in_component(FILES ${module_outputs}
621+ DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift_static/${library_subdir} "
622+ COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} " )
623+ endif ()
580624 endif ()
581625
582626 set (line_directive_tool "${SWIFT_SOURCE_DIR} /utils/line-directive" )
@@ -758,7 +802,27 @@ function(_compile_swift_files
758802 ${swift_ide_test_dependency}
759803 ${create_dirs_dependency_target}
760804 COMMENT "Generating ${module_file} " )
761- set ("${dependency_module_target_out_var_name} " "${module_dependency_target} " PARENT_SCOPE)
805+
806+ if (SWIFTFILE_STATIC)
807+ add_custom_command_target(
808+ module_dependency_target_static
809+ COMMAND
810+ "${CMAKE_COMMAND} " "-E" "make_directory" ${module_dir_static}
811+ ${specific_module_dir_static}
812+ COMMAND
813+ "${CMAKE_COMMAND} " "-E" "copy" ${module_file} ${module_file_static}
814+ COMMAND
815+ "${CMAKE_COMMAND} " "-E" "copy" ${module_doc_file} ${module_doc_file_static}
816+ COMMAND
817+ "${CMAKE_COMMAND} " "-E" "copy" ${interface_file} ${interface_file_static}
818+ OUTPUT ${module_outputs_static}
819+ DEPENDS
820+ "${module_dependency_target} "
821+ COMMENT "Generating ${module_file} " )
822+ set ("${dependency_module_target_out_var_name} " "${module_dependency_target_static} " PARENT_SCOPE)
823+ else ()
824+ set ("${dependency_module_target_out_var_name} " "${module_dependency_target} " PARENT_SCOPE)
825+ endif ()
762826
763827 # macCatalyst zippered swiftmodule
764828 if (maccatalyst_build_flavor STREQUAL "zippered" )
0 commit comments