Skip to content

Commit 7135460

Browse files
committed
[CMake] Fix creation of swiftmodule directories on Apple platforms
The way it was set up before worked for Ninja but not for Xcode, due to me not listing the swiftmodule directories as actual outputs of the create-directories target. The resulting fix here is actually simpler and involves fewer processes anyway, so good for us. https://bugs.swift.org/browse/SR-10029
1 parent 7d0438b commit 7135460

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,10 @@ function(_compile_swift_files
283283

284284
list(APPEND swift_flags ${SWIFTFILE_FLAGS})
285285

286-
set(obj_dirs)
286+
set(dirs_to_create)
287287
foreach(output ${SWIFTFILE_OUTPUT})
288288
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}")
289+
list(APPEND dirs_to_create "${objdir}")
297290
endforeach()
298291

299292
set(module_file)
@@ -333,11 +326,9 @@ function(_compile_swift_files
333326
endif()
334327

335328
if(SWIFTFILE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
336-
list(APPEND command_create_dirs
337-
COMMAND "${CMAKE_COMMAND}" -E make_directory "${specific_module_dir}")
329+
list(APPEND dirs_to_create "${specific_module_dir}")
338330
else()
339-
list(APPEND command_create_dirs
340-
COMMAND "${CMAKE_COMMAND}" -E make_directory "${module_dir}")
331+
list(APPEND dirs_to_create "${module_dir}")
341332
endif()
342333

343334
# If we have extra regexp flags, check if we match any of the regexps. If so
@@ -398,7 +389,7 @@ function(_compile_swift_files
398389
endif()
399390

400391
if (SWIFT_REPORT_STATISTICS)
401-
list(GET obj_dirs 0 first_obj_dir)
392+
list(GET dirs_to_create 0 first_obj_dir)
402393
list(APPEND swift_flags "-stats-output-dir" ${first_obj_dir})
403394
endif()
404395

@@ -433,12 +424,12 @@ function(_compile_swift_files
433424
endif()
434425

435426
# First generate the obj dirs
427+
list(REMOVE_DUPLICATES dirs_to_create)
436428
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}")
429+
create_dirs_dependency_target
430+
COMMAND "${CMAKE_COMMAND}" -E make_directory ${dirs_to_create}
431+
OUTPUT ${dirs_to_create}
432+
COMMENT "Generating dirs for ${first_output}")
442433

443434
# Then we can compile both the object files and the swiftmodule files
444435
# in parallel in this target for the object file, and ...
@@ -478,7 +469,7 @@ function(_compile_swift_files
478469
${swift_compiler_tool_dep}
479470
${file_path} ${source_files} ${SWIFTFILE_DEPENDS}
480471
${swift_ide_test_dependency}
481-
${obj_dirs_dependency_target}
472+
${create_dirs_dependency_target}
482473
${copy_legacy_layouts_dep}
483474
COMMENT "Compiling ${first_output}")
484475
set("${dependency_target_out_var_name}" "${dependency_target}" PARENT_SCOPE)
@@ -513,7 +504,7 @@ function(_compile_swift_files
513504
${swift_compiler_tool_dep}
514505
${source_files} ${SWIFTFILE_DEPENDS}
515506
${swift_ide_test_dependency}
516-
${obj_dirs_dependency_target}
507+
${create_dirs_dependency_target}
517508
COMMENT "Generating ${module_file}")
518509
set("${dependency_module_target_out_var_name}" "${module_dependency_target}" PARENT_SCOPE)
519510

@@ -529,7 +520,7 @@ function(_compile_swift_files
529520
DEPENDS
530521
${swift_compiler_tool_dep}
531522
${source_files} ${SWIFTFILE_DEPENDS}
532-
${obj_dirs_dependency_target}
523+
${create_dirs_dependency_target}
533524
COMMENT "Generating ${sib_file}"
534525
EXCLUDE_FROM_ALL)
535526
set("${dependency_sib_target_out_var_name}" "${sib_dependency_target}" PARENT_SCOPE)
@@ -545,7 +536,7 @@ function(_compile_swift_files
545536
DEPENDS
546537
${swift_compiler_tool_dep}
547538
${source_files} ${SWIFTFILE_DEPENDS}
548-
${obj_dirs_dependency_target}
539+
${create_dirs_dependency_target}
549540
COMMENT "Generating ${sibopt_file}"
550541
EXCLUDE_FROM_ALL)
551542
set("${dependency_sibopt_target_out_var_name}" "${sibopt_dependency_target}" PARENT_SCOPE)
@@ -562,7 +553,7 @@ function(_compile_swift_files
562553
DEPENDS
563554
${swift_compiler_tool_dep}
564555
${source_files} ${SWIFTFILE_DEPENDS}
565-
${obj_dirs_dependency_target}
556+
${create_dirs_dependency_target}
566557
COMMENT "Generating ${sibgen_file}"
567558
EXCLUDE_FROM_ALL)
568559
set("${dependency_sibgen_target_out_var_name}" "${sibgen_dependency_target}" PARENT_SCOPE)

0 commit comments

Comments
 (0)