CMakeTestSwiftCompiler.cmake 2.5 KB

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