diff options
author | Evan Wilde <etceterawilde@gmail.com> | 2024-05-13 22:37:20 (GMT) |
---|---|---|
committer | Evan Wilde <etceterawilde@gmail.com> | 2024-05-15 22:10:15 (GMT) |
commit | c6e52ef7f2ce5a91f23e500faab64c6a632401d0 (patch) | |
tree | cf934f28980297c8a735ac4e1df2082571e140ae | |
parent | 40513f6a90c0ede0cce54da7f345f6c22b26e8ab (diff) | |
download | CMake-c6e52ef7f2ce5a91f23e500faab64c6a632401d0.zip CMake-c6e52ef7f2ce5a91f23e500faab64c6a632401d0.tar.gz CMake-c6e52ef7f2ce5a91f23e500faab64c6a632401d0.tar.bz2 |
Swift: Support static-library try-compile type
Top-level code only works as part of executables, which breaks when
`CMAKE_TRY_COMPILE_TARGET_TYPE` is set to `STATIC_LIBRARY`. This patch
fixes the test to something agnostic between executables and libraries
while still verifying that we can import types from the standard
library.
Fixes: #25984
-rw-r--r-- | Modules/CMakeTestSwiftCompiler.cmake | 5 | ||||
-rw-r--r-- | Tests/RunCMake/Swift/EnableSwift.cmake | 1 | ||||
-rw-r--r-- | Tests/RunCMake/Swift/RunCMakeTest.cmake | 14 |
3 files changed, 19 insertions, 1 deletions
diff --git a/Modules/CMakeTestSwiftCompiler.cmake b/Modules/CMakeTestSwiftCompiler.cmake index c7df912..d89e606 100644 --- a/Modules/CMakeTestSwiftCompiler.cmake +++ b/Modules/CMakeTestSwiftCompiler.cmake @@ -24,7 +24,10 @@ if(NOT CMAKE_Swift_COMPILER_WORKS) # Clear result from normal variable. unset(CMAKE_Swift_COMPILER_WORKS) # Puts test result in cache variable. - set(__CMAKE_Swift_TEST_SOURCE "print(\"CMake\")\n") + string(CONCAT __CMAKE_Swift_TEST_SOURCE + "public struct CMakeStruct {" + " let x: Int" + "}") try_compile(CMAKE_Swift_COMPILER_WORKS SOURCE_FROM_VAR main.swift __CMAKE_Swift_TEST_SOURCE OUTPUT_VARIABLE __CMAKE_Swift_COMPILER_OUTPUT) diff --git a/Tests/RunCMake/Swift/EnableSwift.cmake b/Tests/RunCMake/Swift/EnableSwift.cmake new file mode 100644 index 0000000..19f297a --- /dev/null +++ b/Tests/RunCMake/Swift/EnableSwift.cmake @@ -0,0 +1 @@ +enable_language(Swift) diff --git a/Tests/RunCMake/Swift/RunCMakeTest.cmake b/Tests/RunCMake/Swift/RunCMakeTest.cmake index 3711efb..e8a1dab 100644 --- a/Tests/RunCMake/Swift/RunCMakeTest.cmake +++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake @@ -70,6 +70,20 @@ elseif(RunCMake_GENERATOR STREQUAL Ninja) endblock() block() + # Try enabling Swift with a static-library try-compile + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/StaticLibTryCompile-build) + set(RunCMake_TEST_OPTIONS -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY) + run_cmake(EnableSwift) + endblock() + + block() + # Try enabling Swift with an executable try-compile + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExecutableTryCompile-build) + set(RunCMake_TEST_OPTIONS -DCMAKE_TRY_COMPILE_TARGET_TYPE=EXECUTABLE) + run_cmake(EnableSwift) + endblock() + + block() set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ForceResponseFile-build) run_cmake(ForceResponseFile) set(RunCMake_TEST_NO_CLEAN 1) |