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
This commit is contained in:
parent
40513f6a90
commit
c6e52ef7f2
@ -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)
|
||||
|
1
Tests/RunCMake/Swift/EnableSwift.cmake
Normal file
1
Tests/RunCMake/Swift/EnableSwift.cmake
Normal file
@ -0,0 +1 @@
|
||||
enable_language(Swift)
|
@ -69,6 +69,20 @@ elseif(RunCMake_GENERATOR STREQUAL Ninja)
|
||||
run_cmake_command(CompileCommands-check ${CMAKE_COMMAND} --build .)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user