Tests/RunCMake/Swift: Add CMP0195 behavior checks

Adding checks to ensure that CMP0195 has the desired effect. If the
Swift compiler is too old and does not include the module triple in the
emitted target info, we won't set `CMAKE_Swift_MODULE_TRIPLE` and end up
with the flat directory structure. In this case, these tests won't have
the expected layout.

Issue: #28021
This commit is contained in:
Evan Wilde
2026-08-13 10:18:16 -04:00
committed by Brad King
parent b7a78568c3
commit e4a37fbf15
5 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -455,6 +455,6 @@ Changes made since CMake 4.4.0 include the following.
.. 4.4.3
* Swift policy :poilcy:`CMP0215`'s ``NEW`` behavior has been updated
* Swift policy :policy:`CMP0215`'s ``NEW`` behavior has been updated
to require policies :policy:`CMP0157` and :policy:`CMP0195` to also
be set to ``NEW``.
@@ -1,3 +1,9 @@
# Older Swift compilers may not set CMAKE_Swift_MODULE_TRIPLE
# Check that we built something before verifying the output
if(EXISTS "${RunCMake_TEST_BINARY_DIR}/no-swift-module-triple")
return()
endif()
string(
REGEX MATCHALL
"swiftc(\\.exe)?\"? [^\n]* -emit-module-path [^\n]*L\\.swiftmodule[^ \n]*"
@@ -10,6 +10,13 @@ endif()
enable_language(Swift)
# Older Swift compilers may not set CMAKE_Swift_MODULE_TRIPLE
# Don't build anything if we can't do the nested module structure
if(NOT CMAKE_Swift_MODULE_TRIPLE)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/no-swift-module-triple" "")
return()
endif()
add_library(L STATIC L.swift)
add_library(LClient STATIC LClient.swift)
target_link_libraries(LClient PRIVATE L)
@@ -1,3 +1,9 @@
# Older Swift compilers may not set CMAKE_Swift_MODULE_TRIPLE
# Check that we built something before verifying the output
if(EXISTS "${RunCMake_TEST_BINARY_DIR}/no-swift-module-triple")
return()
endif()
if(NOT actual_stdout MATCHES
"swiftc(\\.exe)?\"? [^\n]* -c @CMakeFiles(/|\\\\)L\\.dir(/|\\\\)(Debug(/|\\\\))?L\\.o(bj)?\\.swift\\.rsp")
string(APPEND RunCMake_TEST_FAILED
@@ -10,6 +10,13 @@ set(CMAKE_NINJA_FORCE_RESPONSE_FILE TRUE)
enable_language(Swift)
# Older Swift compilers may not set CMAKE_Swift_MODULE_TRIPLE
# Don't build anything if we can't do the nested module structure
if(NOT CMAKE_Swift_MODULE_TRIPLE)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/no-swift-module-triple" "")
return()
endif()
add_library(L STATIC L.swift)
add_library(LClient STATIC LClient.swift)
target_link_libraries(LClient PRIVATE L)