Files
cmake/Tests/RunCMake/Swift/EmitModuleSeparatelyExistingModulePath.cmake
T
Roman Lavrov 899f1496f8 Swift/Ninja: Fix emit-module-path clobbering on separate emit-module edge
Since commit b6367f723b (Swift/Ninja: Emit modules separately from
compilation, 2026-04-10) the compile edge still appends
-emit-module -emit-module-path when emitModuleSeparately is active,
duplicating the emit-module edge.  For targets with directory-style
module paths (CMP0195=NEW), this causes a file/directory conflict
that fails the build.

Guard -emit-module -emit-module-path on both the compile and
emit-module edges so they are not appended when the flags already
contain -emit-module-path (e.g. from the target's compile options).

Discovered building swift-syntax on Windows where the directory-style
path was overwritten by the flat path from the compile edge.

Issue: #27748
2026-04-27 18:57:47 -04:00

23 lines
800 B
CMake

cmake_minimum_required(VERSION 4.0)
cmake_policy(SET CMP0157 NEW)
cmake_policy(SET CMP0195 NEW)
cmake_policy(SET CMP0215 NEW)
if(NOT CMAKE_GENERATOR MATCHES "Ninja")
message(SEND_ERROR "this test must use a Ninja generator, found ${CMAKE_GENERATOR}")
endif()
enable_language(Swift)
add_library(L STATIC L.swift)
add_library(LClient STATIC LClient.swift)
target_link_libraries(LClient PRIVATE L)
# Simulate a target whose flags already contain -emit-module-path with a
# directory-style path (as seen with swift-syntax's CMake config). Use the
# real module triple so the path matches GetSwiftModulePath() and the build
# would succeed outside of dry-run.
target_compile_options(L PRIVATE
-emit-module-path ${CMAKE_CURRENT_BINARY_DIR}/L.swiftmodule/${CMAKE_Swift_MODULE_TRIPLE}.swiftmodule)