CMakeTestSwiftCompiler.cmake 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 that 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. "import Foundation\n"
  22. "print(\"CMake\")\n")
  23. try_compile(CMAKE_Swift_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  24. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.swift
  25. OUTPUT_VARIABLE __CMAKE_Swift_COMPILER_OUTPUT)
  26. # Move result from cache to normal variable.
  27. set(CMAKE_Swift_COMPILER_WORKS ${CMAKE_Swift_COMPILER_WORKS})
  28. unset(CMAKE_Swift_COMPILER_WORKS CACHE)
  29. set(Swift_TEST_WAS_RUN 1)
  30. endif()
  31. if(NOT CMAKE_Swift_COMPILER_WORKS)
  32. PrintTestCompilerStatus("Swift" " -- broken")
  33. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  34. "Determining if the Swift compiler works failed with "
  35. "the following output:\n${__CMAKE_Swift_COMPILER_OUTPUT}\n\n")
  36. string(REPLACE "\n" "\n " _output "${__CMAKE_Swift_COMPILER_OUTPUT}")
  37. message(FATAL_ERROR "The Swift compiler\n \"${CMAKE_Swift_COMPILER}\"\n"
  38. "is not able to compile a simple test program.\nIt fails "
  39. "with the following output:\n ${_output}\n\n"
  40. "CMake will not be able to correctly generate this project.")
  41. else()
  42. if(Swift_TEST_WAS_RUN)
  43. PrintTestCompilerStatus("Swift" " -- works")
  44. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  45. "Determining if the Swift compiler works passed with "
  46. "the following output:\n${__CMAKE_Swift_COMPILER_OUTPUT}\n\n")
  47. endif()
  48. endif()
  49. unset(__CMAKE_Swift_COMPILER_OUTPUT)