CMakeTestSwiftCompiler.cmake 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. if(CMAKE_Swift_COMPILER_FORCED)
  4. # The compiler configuration was forced by the user.
  5. # Assume the user has configured all compiler information.
  6. set(CMAKE_Swift_COMPILER_WORKS TRUE)
  7. return()
  8. endif()
  9. include(CMakeTestCompilerCommon)
  10. # Remove any cached result from an older CMake version.
  11. # We now store this in CMakeSwiftCompiler.cmake.
  12. unset(CMAKE_Swift_COMPILER_WORKS CACHE)
  13. # This file is used by EnableLanguage in cmGlobalGenerator to
  14. # determine that the selected C++ compiler can actually compile
  15. # and link the most basic of programs. If not, a fatal error
  16. # is set and cmake stops processing commands and will not generate
  17. # any makefiles or projects.
  18. if(NOT CMAKE_Swift_COMPILER_WORKS)
  19. PrintTestCompilerStatus("Swift")
  20. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.swift
  21. "print(\"CMake\")\n")
  22. # Clear result from normal variable.
  23. unset(CMAKE_Swift_COMPILER_WORKS)
  24. # Puts test result in cache variable.
  25. try_compile(CMAKE_Swift_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  26. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.swift
  27. OUTPUT_VARIABLE __CMAKE_Swift_COMPILER_OUTPUT)
  28. # Move result from cache to normal variable.
  29. set(CMAKE_Swift_COMPILER_WORKS ${CMAKE_Swift_COMPILER_WORKS})
  30. unset(CMAKE_Swift_COMPILER_WORKS CACHE)
  31. set(Swift_TEST_WAS_RUN 1)
  32. endif()
  33. if(NOT CMAKE_Swift_COMPILER_WORKS)
  34. PrintTestCompilerResult(CHECK_FAIL "broken")
  35. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  36. "Determining if the Swift compiler works failed with "
  37. "the following output:\n${__CMAKE_Swift_COMPILER_OUTPUT}\n\n")
  38. string(REPLACE "\n" "\n " _output "${__CMAKE_Swift_COMPILER_OUTPUT}")
  39. message(FATAL_ERROR "The Swift compiler\n \"${CMAKE_Swift_COMPILER}\"\n"
  40. "is not able to compile a simple test program.\nIt fails "
  41. "with the following output:\n ${_output}\n\n"
  42. "CMake will not be able to correctly generate this project.")
  43. else()
  44. if(Swift_TEST_WAS_RUN)
  45. PrintTestCompilerResult(CHECK_PASS "works")
  46. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  47. "Determining if the Swift compiler works passed with "
  48. "the following output:\n${__CMAKE_Swift_COMPILER_OUTPUT}\n\n")
  49. endif()
  50. # Unlike C and CXX we do not yet detect any information about the Swift ABI.
  51. # However, one of the steps done for C and CXX as part of that detection is
  52. # to initialize the implicit include directories. That is relevant here.
  53. set(CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES "${_CMAKE_Swift_IMPLICIT_INCLUDE_DIRECTORIES_INIT}")
  54. # Re-configure to save learned information.
  55. configure_file(${CMAKE_ROOT}/Modules/CMakeSwiftCompiler.cmake.in
  56. ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake @ONLY)
  57. include(${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake)
  58. endif()
  59. unset(__CMAKE_Swift_COMPILER_OUTPUT)