CMakeDetermineSwiftCompiler.cmake 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake)
  4. # Local system-specific compiler preferences for this language.
  5. include(Platform/${CMAKE_SYSTEM_NAME}-Determine-Swift OPTIONAL)
  6. include(Platform/${CMAKE_SYSTEM_NAME}-Swift OPTIONAL)
  7. if(NOT CMAKE_Swift_COMPILER_NAMES)
  8. set(CMAKE_Swift_COMPILER_NAMES swiftc)
  9. endif()
  10. if("${CMAKE_GENERATOR}" STREQUAL "Xcode")
  11. if(XCODE_VERSION VERSION_LESS 6.1)
  12. message(FATAL_ERROR "Swift language not supported by Xcode ${XCODE_VERSION}")
  13. endif()
  14. set(CMAKE_Swift_COMPILER_XCODE_TYPE sourcecode.swift)
  15. _cmake_find_compiler_path(Swift)
  16. elseif("${CMAKE_GENERATOR}" STREQUAL "Ninja")
  17. if(CMAKE_Swift_COMPILER)
  18. _cmake_find_compiler_path(Swift)
  19. else()
  20. set(CMAKE_Swift_COMPILER_INIT NOTFOUND)
  21. if(NOT $ENV{SWIFTC} STREQUAL "")
  22. get_filename_component(CMAKE_Swift_COMPILER_INIT $ENV{SWIFTC} PROGRAM
  23. PROGRAM_ARGS CMAKE_Swift_FLAGS_ENV_INIT)
  24. if(CMAKE_Swift_FLAGS_ENV_INIT)
  25. set(CMAKE_Swift_COMPILER_ARG1 "${CMAKE_Swift_FLAGS_ENV_INIT}" CACHE
  26. STRING "First argument to the Swift compiler")
  27. endif()
  28. if(NOT EXISTS ${CMAKE_Swift_COMPILER_INIT})
  29. message(FATAL_ERROR "Could not find compiler set in environment variable SWIFTC\n$ENV{SWIFTC}.\n${CMAKE_Swift_COMPILER_INIT}")
  30. endif()
  31. endif()
  32. if(NOT CMAKE_Swift_COMPILER_INIT)
  33. set(CMAKE_Swift_COMPILER_LIST swiftc ${_CMAKE_TOOLCHAIN_PREFIX}swiftc)
  34. endif()
  35. _cmake_find_compiler(Swift)
  36. endif()
  37. mark_as_advanced(CMAKE_Swift_COMPILER)
  38. else()
  39. message(FATAL_ERROR "Swift language not supported by \"${CMAKE_GENERATOR}\" generator")
  40. endif()
  41. # Build a small source file to identify the compiler.
  42. if(NOT CMAKE_Swift_COMPILER_ID_RUN)
  43. set(CMAKE_Swift_COMPILER_ID_RUN 1)
  44. if("${CMAKE_GENERATOR}" STREQUAL "Xcode")
  45. list(APPEND CMAKE_Swift_COMPILER_ID_MATCH_VENDORS Apple)
  46. set(CMAKE_Swift_COMPILER_ID_MATCH_VENDOR_REGEX_Apple "com.apple.xcode.tools.swift.compiler")
  47. set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_REGEX "\nCompileSwift[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]* -c[^\r\n]*CompilerIdSwift/CompilerId/main.swift")
  48. set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_INDEX 2)
  49. endif()
  50. # Try to identify the compiler.
  51. set(CMAKE_Swift_COMPILER_ID)
  52. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
  53. CMAKE_DETERMINE_COMPILER_ID(Swift "" CompilerId/main.swift)
  54. endif()
  55. if (NOT _CMAKE_TOOLCHAIN_LOCATION)
  56. get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Swift_COMPILER}" PATH)
  57. endif ()
  58. set(_CMAKE_PROCESSING_LANGUAGE "Swift")
  59. include(CMakeFindBinUtils)
  60. unset(_CMAKE_PROCESSING_LANGUAGE)
  61. # configure variables set in this file for fast reload later on
  62. configure_file(${CMAKE_ROOT}/Modules/CMakeSwiftCompiler.cmake.in
  63. ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake @ONLY)
  64. set(CMAKE_Swift_COMPILER_ENV_VAR "SWIFTC")