@@ -195,6 +195,7 @@ function(_compile_swift_files
195
195
196
196
# Compute flags for the Swift compiler.
197
197
set (swift_flags )
198
+ set (swift_module_flags )
198
199
199
200
_add_variant_swift_compile_flags (
200
201
"${SWIFTFILE_SDK} "
@@ -283,17 +284,10 @@ function(_compile_swift_files
283
284
284
285
list (APPEND swift_flags ${SWIFTFILE_FLAGS} )
285
286
286
- set (obj_dirs )
287
+ set (dirs_to_create )
287
288
foreach (output ${SWIFTFILE_OUTPUT} )
288
289
get_filename_component (objdir "${output} " PATH )
289
- list (APPEND obj_dirs "${objdir} " )
290
- endforeach ()
291
- list (REMOVE_DUPLICATES obj_dirs )
292
-
293
- set (command_create_dirs )
294
- foreach (objdir ${obj_dirs} )
295
- list (APPEND command_create_dirs
296
- COMMAND "${CMAKE_COMMAND} " -E make_directory "${objdir} " )
290
+ list (APPEND dirs_to_create "${objdir} " )
297
291
endforeach ()
298
292
299
293
set (module_file )
@@ -316,6 +310,8 @@ function(_compile_swift_files
316
310
if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS )
317
311
set (specific_module_dir "${module_base} .swiftmodule" )
318
312
set (module_base "${module_base} .swiftmodule/${SWIFTFILE_ARCHITECTURE} " )
313
+ else ()
314
+ set (specific_module_dir )
319
315
endif ()
320
316
set (module_file "${module_base} .swiftmodule" )
321
317
set (module_doc_file "${module_base} .swiftdoc" )
@@ -328,16 +324,8 @@ function(_compile_swift_files
328
324
329
325
if (SWIFT_ENABLE_PARSEABLE_MODULE_INTERFACES )
330
326
set (interface_file "${module_base} .swiftinterface" )
331
- list (APPEND swift_flags
332
- "-emit-parseable-module-interface-path" "${interface_file} " )
333
- endif ()
334
-
335
- if (SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS )
336
- list (APPEND command_create_dirs
337
- COMMAND "${CMAKE_COMMAND} " -E make_directory "${specific_module_dir} " )
338
- else ()
339
- list (APPEND command_create_dirs
340
- COMMAND "${CMAKE_COMMAND} " -E make_directory "${module_dir} " )
327
+ list (APPEND swift_module_flags
328
+ "-emit-parseable-module-interface-path" "${interface_file} " )
341
329
endif ()
342
330
343
331
# If we have extra regexp flags, check if we match any of the regexps. If so
@@ -398,7 +386,7 @@ function(_compile_swift_files
398
386
endif ()
399
387
400
388
if (SWIFT_REPORT_STATISTICS )
401
- list (GET obj_dirs 0 first_obj_dir )
389
+ list (GET dirs_to_create 0 first_obj_dir )
402
390
list (APPEND swift_flags "-stats-output-dir" ${first_obj_dir} )
403
391
endif ()
404
392
@@ -433,12 +421,12 @@ function(_compile_swift_files
433
421
endif ()
434
422
435
423
# First generate the obj dirs
424
+ list (REMOVE_DUPLICATES dirs_to_create )
436
425
add_custom_command_target (
437
- obj_dirs_dependency_target
438
- ${command_create_dirs}
439
- COMMAND ""
440
- OUTPUT ${obj_dirs}
441
- COMMENT "Generating obj dirs for ${first_output} " )
426
+ create_dirs_dependency_target
427
+ COMMAND "${CMAKE_COMMAND} " -E make_directory ${dirs_to_create}
428
+ OUTPUT ${dirs_to_create}
429
+ COMMENT "Generating dirs for ${first_output} " )
442
430
443
431
# Then we can compile both the object files and the swiftmodule files
444
432
# in parallel in this target for the object file, and ...
@@ -478,7 +466,7 @@ function(_compile_swift_files
478
466
${swift_compiler_tool_dep}
479
467
${file_path} ${source_files} ${SWIFTFILE_DEPENDS}
480
468
${swift_ide_test_dependency}
481
- ${obj_dirs_dependency_target }
469
+ ${create_dirs_dependency_target }
482
470
${copy_legacy_layouts_dep}
483
471
COMMENT "Compiling ${first_output} " )
484
472
set ("${dependency_target_out_var_name} " "${dependency_target} " PARENT_SCOPE )
@@ -503,17 +491,20 @@ function(_compile_swift_files
503
491
module_dependency_target
504
492
COMMAND
505
493
"${CMAKE_COMMAND} " "-E" "remove" "-f" ${module_outputs}
494
+ COMMAND
495
+ "${CMAKE_COMMAND} " "-E" "make_directory" ${module_dir}
496
+ ${specific_module_dir}
506
497
COMMAND
507
498
"${PYTHON_EXECUTABLE} " "${line_directive_tool} " "@${file_path} " --
508
499
"${swift_compiler_tool} " "-emit-module" "-o" "${module_file} "
509
- ${swift_flags} "@${file_path} "
500
+ ${swift_flags} ${swift_module_flags} "@${file_path} "
510
501
${command_touch_module_outputs}
511
502
OUTPUT ${module_outputs}
512
503
DEPENDS
513
504
${swift_compiler_tool_dep}
514
505
${source_files} ${SWIFTFILE_DEPENDS}
515
506
${swift_ide_test_dependency}
516
- ${obj_dirs_dependency_target }
507
+ ${create_dirs_dependency_target }
517
508
COMMENT "Generating ${module_file} " )
518
509
set ("${dependency_module_target_out_var_name} " "${module_dependency_target} " PARENT_SCOPE )
519
510
@@ -529,7 +520,7 @@ function(_compile_swift_files
529
520
DEPENDS
530
521
${swift_compiler_tool_dep}
531
522
${source_files} ${SWIFTFILE_DEPENDS}
532
- ${obj_dirs_dependency_target }
523
+ ${create_dirs_dependency_target }
533
524
COMMENT "Generating ${sib_file} "
534
525
EXCLUDE_FROM_ALL )
535
526
set ("${dependency_sib_target_out_var_name} " "${sib_dependency_target} " PARENT_SCOPE )
@@ -545,7 +536,7 @@ function(_compile_swift_files
545
536
DEPENDS
546
537
${swift_compiler_tool_dep}
547
538
${source_files} ${SWIFTFILE_DEPENDS}
548
- ${obj_dirs_dependency_target }
539
+ ${create_dirs_dependency_target }
549
540
COMMENT "Generating ${sibopt_file} "
550
541
EXCLUDE_FROM_ALL )
551
542
set ("${dependency_sibopt_target_out_var_name} " "${sibopt_dependency_target} " PARENT_SCOPE )
@@ -562,7 +553,7 @@ function(_compile_swift_files
562
553
DEPENDS
563
554
${swift_compiler_tool_dep}
564
555
${source_files} ${SWIFTFILE_DEPENDS}
565
- ${obj_dirs_dependency_target }
556
+ ${create_dirs_dependency_target }
566
557
COMMENT "Generating ${sibgen_file} "
567
558
EXCLUDE_FROM_ALL )
568
559
set ("${dependency_sibgen_target_out_var_name} " "${sibgen_dependency_target} " PARENT_SCOPE )
0 commit comments