CMakeDetermineSwiftCompiler.cmake 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. if("${CMAKE_GENERATOR}" STREQUAL "Xcode")
  5. if(XCODE_VERSION VERSION_LESS 6.1)
  6. message(FATAL_ERROR "Swift language not supported by Xcode ${XCODE_VERSION}")
  7. endif()
  8. set(CMAKE_Swift_COMPILER_XCODE_TYPE sourcecode.swift)
  9. _cmake_find_compiler_path(Swift)
  10. else()
  11. message(FATAL_ERROR "Swift language not supported by \"${CMAKE_GENERATOR}\" generator")
  12. endif()
  13. # Build a small source file to identify the compiler.
  14. if(NOT CMAKE_Swift_COMPILER_ID_RUN)
  15. set(CMAKE_Swift_COMPILER_ID_RUN 1)
  16. list(APPEND CMAKE_Swift_COMPILER_ID_MATCH_VENDORS Apple)
  17. set(CMAKE_Swift_COMPILER_ID_MATCH_VENDOR_REGEX_Apple "com.apple.xcode.tools.swift.compiler")
  18. set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_REGEX "\nCompileSwiftSources[^\n]*(\n[ \t]+[^\n]*)*\n[ \t]+([^ \t\r\n]+)[^\r\n]* -c[^\r\n]*CompilerIdSwift/CompilerId/main.swift")
  19. set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_INDEX 2)
  20. # Try to identify the compiler.
  21. set(CMAKE_Swift_COMPILER_ID)
  22. include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
  23. CMAKE_DETERMINE_COMPILER_ID(Swift "" CompilerId/main.swift)
  24. endif()
  25. if (NOT _CMAKE_TOOLCHAIN_LOCATION)
  26. get_filename_component(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_Swift_COMPILER}" PATH)
  27. endif ()
  28. set(_CMAKE_PROCESSING_LANGUAGE "Swift")
  29. include(CMakeFindBinUtils)
  30. unset(_CMAKE_PROCESSING_LANGUAGE)
  31. # configure variables set in this file for fast reload later on
  32. configure_file(${CMAKE_ROOT}/Modules/CMakeSwiftCompiler.cmake.in
  33. ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake
  34. @ONLY
  35. )