CheckSourceCompiles: Add support for Swift

Plumb through swift `check_source_compiles` support.  Add tests to check
that valid swift sources compile and invalid sources don't.
This commit is contained in:
Evan Wilde
2022-09-27 15:30:46 -07:00
committed by Brad King
parent 4451a1f54f
commit 2345139ab5
4 changed files with 24 additions and 1 deletions

View File

@@ -34,6 +34,9 @@ function(CMAKE_CHECK_SOURCE_COMPILES _lang _source _var)
elseif(_lang STREQUAL "OBJCXX")
set(_lang_textual "Objective-C++")
set(_lang_ext "mm")
elseif(_lang STREQUAL "Swift")
set(_lang_textual "Swift")
set(_lang_ext "swift")
else()
message (SEND_ERROR "check_source_compiles: ${_lang}: unknown language.")
return()

View File

@@ -752,7 +752,8 @@ add_RunCMake_test(CheckCompilerFlag -DCMake_TEST_CUDA=${CMake_TEST_CUDA}
add_RunCMake_test(CheckSourceCompiles -DCMake_TEST_CUDA=${CMake_TEST_CUDA}
-DCMake_TEST_ISPC=${CMake_TEST_ISPC}
-DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}
-DCMake_TEST_HIP=${CMake_TEST_HIP})
-DCMake_TEST_HIP=${CMake_TEST_HIP}
-DCMake_TEST_Swift=${CMake_TEST_Swift})
add_RunCMake_test(CheckSourceRuns -DCMake_TEST_CUDA=${CMake_TEST_CUDA}
-DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}
-DCMake_TEST_HIP=${CMake_TEST_HIP})

View File

@@ -0,0 +1,15 @@
enable_language(Swift)
include(CheckSourceCompiles)
set(Swift 1) # test that this is tolerated
check_source_compiles(Swift "baz()" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "invalid Swift source didn't fail.")
endif()
check_source_compiles(Swift "print(\"Hello, CMake\")" SHOULD_BUILD)
if(NOT SHOULD_BUILD)
message(SEND_ERROR "Test failed for valid Swift source.")
endif()

View File

@@ -31,3 +31,7 @@ endif()
if(CMake_TEST_HIP)
run_cmake(CheckSourceCompilesHIP)
endif()
if(CMake_TEST_Swift)
run_cmake(CheckSourceCompilesSwift)
endif()