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