@@ -29,7 +29,7 @@ function(handle_swift_sources
29
29
dependency_sibgen_target_out_var_name
30
30
sourcesvar externalvar name )
31
31
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 "
33
33
"SDK;ARCHITECTURE;INSTALL_IN_COMPONENT;MACCATALYST_BUILD_FLAVOR"
34
34
"DEPENDS;COMPILE_FLAGS;MODULE_NAME"
35
35
${ARGN} )
@@ -41,6 +41,8 @@ function(handle_swift_sources
41
41
IS_SDK_OVERLAY_arg)
42
42
translate_flag(${SWIFTSOURCES_EMBED_BITCODE} "EMBED_BITCODE"
43
43
EMBED_BITCODE_arg)
44
+ translate_flag(${SWIFTSOURCES_STATIC} "STATIC"
45
+ STATIC_arg)
44
46
45
47
if (SWIFTSOURCES_IS_MAIN)
46
48
set (SWIFTSOURCES_INSTALL_IN_COMPONENT never_install)
@@ -278,13 +280,15 @@ endfunction()
278
280
# [MODULE_NAME] # The module name.
279
281
# [INSTALL_IN_COMPONENT] # Install produced files.
280
282
# [EMBED_BITCODE] # Embed LLVM bitcode into the .o files
283
+ # [STATIC] # Also write .swiftmodule etc. to static
284
+ # # resource folder
281
285
# )
282
286
function (_compile_swift_files
283
287
dependency_target_out_var_name dependency_module_target_out_var_name
284
288
dependency_sib_target_out_var_name dependency_sibopt_target_out_var_name
285
289
dependency_sibgen_target_out_var_name)
286
290
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 "
288
292
"OUTPUT;MODULE_NAME;INSTALL_IN_COMPONENT;MACCATALYST_BUILD_FLAVOR"
289
293
"SOURCES;FLAGS;DEPENDS;SDK;ARCHITECTURE;OPT_FLAGS;MODULE_DIR"
290
294
${ARGN} )
@@ -448,8 +452,11 @@ function(_compile_swift_files
448
452
endforeach ()
449
453
450
454
set (module_file)
455
+ set (module_file_static)
451
456
set (module_doc_file)
457
+ set (module_doc_file_static)
452
458
set (interface_file)
459
+ set (interface_file_static)
453
460
454
461
if (NOT SWIFTFILE_IS_MAIN)
455
462
# Determine the directory where the module file should be placed.
@@ -464,17 +471,28 @@ function(_compile_swift_files
464
471
list (APPEND swift_flags "-parse-as-library" )
465
472
466
473
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
+
467
478
set (module_triple ${SWIFT_SDK_${library_subdir_sdk} _ARCH_${SWIFTFILE_ARCHITECTURE} _MODULE})
468
479
if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS OR
469
480
SWIFTFILE_SDK STREQUAL "MACCATALYST" )
470
481
set (specific_module_dir "${module_base} .swiftmodule" )
471
482
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} " )
472
486
else ()
473
487
set (specific_module_dir)
488
+ set (specific_module_dir_static)
474
489
endif ()
475
490
set (module_file "${module_base} .swiftmodule" )
476
491
set (module_doc_file "${module_base} .swiftdoc" )
477
492
493
+ set (module_file_static "${module_base_static} .swiftmodule" )
494
+ set (module_doc_file_static "${module_base_static} .swiftdoc" )
495
+
478
496
# FIXME: These don't really belong inside the swiftmodule, but there's not
479
497
# an obvious alternate place to put them.
480
498
set (sib_file "${module_base} .Onone.sib" )
@@ -483,6 +501,7 @@ function(_compile_swift_files
483
501
484
502
if (SWIFT_ENABLE_MODULE_INTERFACES)
485
503
set (interface_file "${module_base} .swiftinterface" )
504
+ set (interface_file_static "${module_base_static} .swiftinterface" )
486
505
list (APPEND swift_module_flags
487
506
"-emit-module-interface-path" "${interface_file} " )
488
507
endif ()
@@ -510,10 +529,20 @@ function(_compile_swift_files
510
529
swift_install_in_component(DIRECTORY "${specific_module_dir} "
511
530
DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift/${library_subdir} "
512
531
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 ()
513
537
else ()
514
538
swift_install_in_component(FILES ${module_outputs}
515
539
DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift/${library_subdir} "
516
540
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 ()
517
546
endif ()
518
547
519
548
# macCatalyst zippered module setup
@@ -563,8 +592,10 @@ function(_compile_swift_files
563
592
endif ()
564
593
565
594
set (module_outputs "${module_file} " "${module_doc_file} " )
595
+ set (module_outputs_static "${module_file_static} " "${module_doc_file_static} " )
566
596
if (interface_file)
567
597
list (APPEND module_outputs "${interface_file} " )
598
+ list (APPEND module_outputs_static "${interface_file_static} " )
568
599
endif ()
569
600
570
601
if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
@@ -573,10 +604,23 @@ function(_compile_swift_files
573
604
COMPONENT "${SWIFTFILE_INSTALL_IN_COMPONENT} "
574
605
OPTIONAL
575
606
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 ()
576
615
else ()
577
616
swift_install_in_component(FILES ${module_outputs}
578
617
DESTINATION "lib${LLVM_LIBDIR_SUFFIX} /swift/${library_subdir} "
579
618
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 ()
580
624
endif ()
581
625
582
626
set (line_directive_tool "${SWIFT_SOURCE_DIR} /utils/line-directive" )
@@ -758,7 +802,27 @@ function(_compile_swift_files
758
802
${swift_ide_test_dependency}
759
803
${create_dirs_dependency_target}
760
804
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 ()
762
826
763
827
# macCatalyst zippered swiftmodule
764
828
if (maccatalyst_build_flavor STREQUAL "zippered" )
0 commit comments