CheckCompilerFlag: Add Swift Support

Plumb through Swift `check_compiler_flag` support.
Add tests to check that valid flags work and invalid flags don't.
This commit is contained in:
Evan Wilde
2022-11-03 08:58:08 -07:00
parent 4fc3f7e88f
commit 2d5403ecaa
4 changed files with 29 additions and 1 deletions

View File

@@ -48,6 +48,8 @@ macro(CMAKE_CHECK_FLAG_COMMON_INIT _FUNC _LANG _SRC _PATTERNS)
FAIL_REGEX "argument unused during compilation: .*") # Clang
elseif("${_LANG}" STREQUAL "ISPC")
set(${_SRC} "float func(uniform int32, float a) { return a / 2.25; }")
elseif("${_LANG}" STREQUAL "Swift")
set(${_SRC} "func blarpy() { }")
else()
message (SEND_ERROR "${_FUNC}: ${_LANG}: unknown language.")
return()

View File

@@ -703,7 +703,8 @@ add_RunCMake_test(target_sources)
add_RunCMake_test(CheckCompilerFlag -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(CheckSourceCompiles -DCMake_TEST_CUDA=${CMake_TEST_CUDA}
-DCMake_TEST_ISPC=${CMake_TEST_ISPC}
-DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}

View File

@@ -0,0 +1,21 @@
enable_language (Swift)
include(CheckCompilerFlag)
set(Swift 1)
# test that the check uses an isolated locale
set(_env_LC_ALL "${LC_ALL}")
set(ENV{LC_ALL} "BAD")
check_compiler_flag(Swift "-foo-as-blarpy" SHOULD_FAIL)
if(SHOULD_FAIL)
message(SEND_ERROR "invalid Swift compile flag didn't fail.")
endif()
check_compiler_flag(Swift "-parseable-output" SHOULD_WORK)
if(NOT SHOULD_WORK)
message(SEND_ERROR "Swift compiler flag '-parseable-output' check failed")
endif()
# Reset locale
set(ENV{LC_ALL} ${_env_LC_ALL})

View File

@@ -32,3 +32,7 @@ endif()
if(APPLE)
run_cmake(HeaderpadWorkaround)
endif()
if(CMake_TEST_Swift)
run_cmake(CheckCompilerFlagSwift)
endif()