Commit a9180ccf authored by Saleem Abdulrasool's avatar Saleem Abdulrasool Committed by Brad King

Tests: add a check for the Swift compiler

This ensures that the tests only run when the Swift compiler is present.
parent d745551f
......@@ -22,6 +22,7 @@ macro(ADD_TEST_MACRO NAME)
endmacro()
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckFortran.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/CheckSwift.cmake)
# Fake a user home directory to avoid polluting the real one.
if(DEFINED ENV{HOME} AND NOT CTEST_NO_TEST_HOME)
......@@ -365,11 +366,16 @@ if(BUILD_TESTING)
((NOT CMAKE_OSX_SDKPRODUCT STREQUAL "Mac OS X") OR
(NOT CMAKE_OSX_SDKVERSION VERSION_LESS 10.10)))
if(CMAKE_GENERATOR STREQUAL "Xcode")
ADD_TEST_MACRO(SwiftMix SwiftMix)
ADD_TEST_MACRO(SwiftOnly SwiftOnly)
set(CMake_TEST_XCODE_SWIFT 1)
endif()
endif()
endif()
if(CMAKE_Swift_COMPILER OR CMake_TEST_XCODE_SWIFT)
ADD_TEST_MACRO(SwiftOnly SwiftOnly)
if(CMake_TEST_XCODE_SWIFT)
ADD_TEST_MACRO(SwiftMix SwiftMix)
endif()
endif()
if(CMAKE_Fortran_COMPILER)
ADD_TEST_MACRO(FortranOnly FortranOnly)
endif()
......
if(NOT CMAKE_GENERATOR MATCHES "Xcode|Ninja")
set(CMAKE_Swift_COMPILER "")
return()
endif()
if(NOT DEFINED CMAKE_Swift_COMPILER)
set(_desc "Looking for a Swift compiler")
message(STATUS ${_desc})
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckSwift)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckSwift/CMakeLists.txt"
"cmake_minimum_required(VERSION 3.14)
project(CheckSwift Swift)
file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
\"set(CMAKE_Swift_COMPILER \\\"\${CMAKE_Swift_COMPILER}\\\")\\n\"
\"set(CMAKE_Swift_FLAGS \\\"\${CMAKE_Swift_FLAGS}\\\")\\n\")
")
if(CMAKE_GENERATOR_INSTANCE)
set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE:INTERNAL=${CMAKE_GENERATOR_INSTANCE}")
else()
set(_D_CMAKE_GENERATOR_INSTANCE "")
endif()
execute_process(WORKING_DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckSwift
COMMAND
${CMAKE_COMMAND} . -G ${CMAKE_GENERATOR}
-A "${CMAKE_GENERATOR_PLATFORM}"
-T "${CMAKE_GENERATOR_TOOLSET}"
${_D_CMAKE_GENERATOR_INSTANCE}
TIMEOUT
60
OUTPUT_VARIABLE
output
ERROR_VARIABLE
output
RESULT_VARIABLE
result)
include(${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/CheckSwift/result.cmake
OPTIONAL)
if(CMAKE_Swift_COMPILER AND "${result}" STREQUAL "0")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"${_desc} passed with the following output:\n"
"${output}\n")
else()
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"${_desc} failed with the following output:\n"
"${output}\n")
endif()
message(STATUS "${_desc} - ${CMAKE_Swift_COMPILER}")
set(CMAKE_Swift_COMPILER "${CMAKE_Swift_COMPILER}" CACHE FILEPATH "Swift compiler")
set(CMAKE_Swift_FLAGS "${CMAKE_Swift_FLAGS}" CACHE STRING "Swift flags")
mark_as_advanced(CMAKE_Swift_COMPILER)
mark_as_advanced(CMAKE_Swift_FLAGS)
endif()
......@@ -205,7 +205,7 @@ if(UNIX AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG AND CMAKE_EXECUTABLE_FORMAT STRE
add_RunCMake_test(RuntimePath)
endif()
add_RunCMake_test(ScriptMode)
add_RunCMake_test(Swift)
add_RunCMake_test(Swift -DCMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER})
add_RunCMake_test(TargetObjects)
add_RunCMake_test(TargetSources)
add_RunCMake_test(ToolchainFile)
......
......@@ -4,6 +4,10 @@ if(RunCMake_GENERATOR STREQUAL Xcode)
if(XCODE_BELOW_6_1)
run_cmake(XcodeTooOld)
endif()
elseif(RunCMake_GENERATOR STREQUAL Ninja)
if(CMAKE_Swift_COMPILER)
# Add Ninja-specific Swift tests here.
endif()
else()
run_cmake(NotSupported)
endif()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment