CMakeTestSwiftCompiler.cmake 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #=============================================================================
  2. # Copyright 2003-2015 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distribute this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. if(CMAKE_Swift_COMPILER_FORCED)
  14. # The compiler configuration was forced by the user.
  15. # Assume the user has configured all compiler information.
  16. set(CMAKE_Swift_COMPILER_WORKS TRUE)
  17. return()
  18. endif()
  19. include(CMakeTestCompilerCommon)
  20. # Remove any cached result from an older CMake version.
  21. # We now store this in CMakeSwiftCompiler.cmake.
  22. unset(CMAKE_Swift_COMPILER_WORKS CACHE)
  23. # This file is used by EnableLanguage in cmGlobalGenerator to
  24. # determine that that selected C++ compiler can actually compile
  25. # and link the most basic of programs. If not, a fatal error
  26. # is set and cmake stops processing commands and will not generate
  27. # any makefiles or projects.
  28. if(NOT CMAKE_Swift_COMPILER_WORKS)
  29. PrintTestCompilerStatus("Swift" "")
  30. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.swift
  31. "import Foundation\n"
  32. "print(\"CMake\")\n")
  33. try_compile(CMAKE_Swift_COMPILER_WORKS ${CMAKE_BINARY_DIR}
  34. ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.swift
  35. OUTPUT_VARIABLE __CMAKE_Swift_COMPILER_OUTPUT)
  36. # Move result from cache to normal variable.
  37. set(CMAKE_Swift_COMPILER_WORKS ${CMAKE_Swift_COMPILER_WORKS})
  38. unset(CMAKE_Swift_COMPILER_WORKS CACHE)
  39. set(Swift_TEST_WAS_RUN 1)
  40. endif()
  41. if(NOT CMAKE_Swift_COMPILER_WORKS)
  42. PrintTestCompilerStatus("Swift" " -- broken")
  43. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  44. "Determining if the Swift compiler works failed with "
  45. "the following output:\n${__CMAKE_Swift_COMPILER_OUTPUT}\n\n")
  46. message(FATAL_ERROR "The Swift compiler \"${CMAKE_Swift_COMPILER}\" "
  47. "is not able to compile a simple test program.\nIt fails "
  48. "with the following output:\n ${__CMAKE_Swift_COMPILER_OUTPUT}\n\n"
  49. "CMake will not be able to correctly generate this project.")
  50. else()
  51. if(Swift_TEST_WAS_RUN)
  52. PrintTestCompilerStatus("Swift" " -- works")
  53. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  54. "Determining if the Swift compiler works passed with "
  55. "the following output:\n${__CMAKE_Swift_COMPILER_OUTPUT}\n\n")
  56. endif()
  57. endif()
  58. unset(__CMAKE_Swift_COMPILER_OUTPUT)