diff --git a/Modules/CMakeTestSwiftCompiler.cmake b/Modules/CMakeTestSwiftCompiler.cmake index c7df912e4e..d89e6064d2 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 0000000000..19f297a87f --- /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 3711efb1c9..e8a1daba8e 100644 --- a/Tests/RunCMake/Swift/RunCMakeTest.cmake +++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake @@ -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)