diff --git a/Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake b/Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake index a5332ccb5074c..b8d75ed487909 100644 --- a/Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake +++ b/Runtimes/Core/cmake/modules/EmitSwiftInterface.cmake @@ -18,7 +18,13 @@ function(emit_swift_interface target) if(NOT module_name) set(module_name ${target}) endif() - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + # Account for an existing swiftmodule file + # generated with the previous logic + if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule" + AND NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + message(STATUS "Removing regular file ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule to support nested swiftmodule generation") + file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + endif() target_compile_options(${target} PRIVATE "$<$:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftCore_MODULE_TRIPLE}.swiftmodule>") if(SwiftCore_VARIANT_MODULE_TRIPLE) diff --git a/Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake b/Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake index c915793ca8769..b52560448df68 100644 --- a/Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake +++ b/Runtimes/Overlay/cmake/modules/EmitSwiftInterface.cmake @@ -18,7 +18,13 @@ function(emit_swift_interface target) if(NOT module_name) set(module_name ${target}) endif() - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + # Account for an existing swiftmodule file + # generated with the previous logic + if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule" + AND NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + message(STATUS "Removing regular file ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule to support nested swiftmodule generation") + file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + endif() target_compile_options(${target} PRIVATE "$<$:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${SwiftOverlay_MODULE_TRIPLE}.swiftmodule>") if(SwiftOverlay_VARIANT_MODULE_TRIPLE) diff --git a/Runtimes/Supplemental/cmake/modules/EmitSwiftInterface.cmake b/Runtimes/Supplemental/cmake/modules/EmitSwiftInterface.cmake index 9d56da0816b64..8a3540dd55e07 100644 --- a/Runtimes/Supplemental/cmake/modules/EmitSwiftInterface.cmake +++ b/Runtimes/Supplemental/cmake/modules/EmitSwiftInterface.cmake @@ -18,7 +18,13 @@ function(emit_swift_interface target) if(NOT module_name) set(module_name ${target}) endif() - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + # Account for an existing swiftmodule file + # generated with the previous logic + if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule" + AND NOT IS_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + message(STATUS "Removing regular file ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule to support nested swiftmodule generation") + file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule") + endif() target_compile_options(${target} PRIVATE "$<$:SHELL:-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/${module_name}.swiftmodule/${${PROJECT_NAME}_MODULE_TRIPLE}.swiftmodule>") if(${PROJECT_NAME}_VARIANT_MODULE_TRIPLE)