diff options
author | Brad King <brad.king@kitware.com> | 2019-05-20 14:55:11 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-05-20 14:55:27 (GMT) |
commit | a9fb9a8774a7b1dd411542d1d14fb537968e32f1 (patch) | |
tree | 2d74dc351b298a5317d05634170c91a8b43bc07e /Modules | |
parent | 28ee31149030c75c32ebbf134502a9d020dbd54b (diff) | |
parent | a9180ccf9a9e845658ba455e2dbc2447b18d2654 (diff) | |
download | CMake-a9fb9a8774a7b1dd411542d1d14fb537968e32f1.zip CMake-a9fb9a8774a7b1dd411542d1d14fb537968e32f1.tar.gz CMake-a9fb9a8774a7b1dd411542d1d14fb537968e32f1.tar.bz2 |
Merge topic 'ninja-swift'
a9180ccf9a Tests: add a check for the Swift compiler
d745551fb6 Help: add some initial documentation for Swift support
9a182c9e5b Auxiliary: update vim syntax highlighting
e9b0063e8e Modules: add build rules for Swift Ninja support
b6412e3e38 Ninja: add placeholders to support Swift build
7d7f31161d Ninja: add support for Swift's output-file-map.json
d688c4c19d Swift: remove unnecessary unreleased Ninja infrastructure
0723582208 Swift: Detect compiler version
...
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3297
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CMakeDetermineCompilerId.cmake | 39 | ||||
-rw-r--r-- | Modules/CMakeDetermineSwiftCompiler.cmake | 49 | ||||
-rw-r--r-- | Modules/CMakeSwiftCompiler.cmake.in | 9 | ||||
-rw-r--r-- | Modules/CMakeSwiftInformation.cmake | 57 | ||||
-rw-r--r-- | Modules/CMakeTestSwiftCompiler.cmake | 7 |
5 files changed, 130 insertions, 31 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 1cd919a..7036b93 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -46,6 +46,14 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) endif() endforeach() + # Check if compiler id detection gave us the compiler tool. + if(CMAKE_${lang}_COMPILER_ID_TOOL) + set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_ID_TOOL}") + set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_ID_TOOL}" PARENT_SCOPE) + elseif(NOT CMAKE_${lang}_COMPILER) + set(CMAKE_${lang}_COMPILER "CMAKE_${lang}_COMPILER-NOTFOUND" PARENT_SCOPE) + endif() + # If the compiler is still unknown, try to query its vendor. if(CMAKE_${lang}_COMPILER AND NOT CMAKE_${lang}_COMPILER_ID) foreach(userflags "${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}" "") @@ -76,6 +84,30 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) endif() endif() + # For Swift we need to explicitly query the version. + if(lang STREQUAL "Swift" + AND CMAKE_${lang}_COMPILER + AND NOT CMAKE_${lang}_COMPILER_VERSION) + execute_process( + COMMAND "${CMAKE_${lang}_COMPILER}" + -version + OUTPUT_VARIABLE output ERROR_VARIABLE output + RESULT_VARIABLE result + TIMEOUT 10 + ) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Running the ${lang} compiler: \"${CMAKE_${lang}_COMPILER}\" -version\n" + "${output}\n" + ) + + if(output MATCHES [[Swift version ([0-9]+\.[0-9]+(\.[0-9]+)?)]]) + set(CMAKE_${lang}_COMPILER_VERSION "${CMAKE_MATCH_1}") + if(NOT CMAKE_${lang}_COMPILER_ID) + set(CMAKE_Swift_COMPILER_ID "Apple") + endif() + endif() + endif() + if (COMPILER_QNXNTO AND CMAKE_${lang}_COMPILER_ID STREQUAL "GNU") execute_process( COMMAND "${CMAKE_${lang}_COMPILER}" @@ -124,13 +156,6 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) message(STATUS "The ${lang} compiler identification is unknown") endif() - # Check if compiler id detection gave us the compiler tool. - if(CMAKE_${lang}_COMPILER_ID_TOOL) - set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_ID_TOOL}" PARENT_SCOPE) - elseif(NOT CMAKE_${lang}_COMPILER) - set(CMAKE_${lang}_COMPILER "CMAKE_${lang}_COMPILER-NOTFOUND" PARENT_SCOPE) - endif() - set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE) set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE) set(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID "${CMAKE_${lang}_COMPILER_ARCHITECTURE_ID}" PARENT_SCOPE) diff --git a/Modules/CMakeDetermineSwiftCompiler.cmake b/Modules/CMakeDetermineSwiftCompiler.cmake index dd02d54..2fcf7b0 100644 --- a/Modules/CMakeDetermineSwiftCompiler.cmake +++ b/Modules/CMakeDetermineSwiftCompiler.cmake @@ -1,15 +1,46 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. - include(${CMAKE_ROOT}/Modules/CMakeDetermineCompiler.cmake) +# Local system-specific compiler preferences for this language. +include(Platform/${CMAKE_SYSTEM_NAME}-Determine-Swift OPTIONAL) +include(Platform/${CMAKE_SYSTEM_NAME}-Swift OPTIONAL) +if(NOT CMAKE_Swift_COMPILER_NAMES) + set(CMAKE_Swift_COMPILER_NAMES swiftc) +endif() + if("${CMAKE_GENERATOR}" STREQUAL "Xcode") if(XCODE_VERSION VERSION_LESS 6.1) message(FATAL_ERROR "Swift language not supported by Xcode ${XCODE_VERSION}") endif() set(CMAKE_Swift_COMPILER_XCODE_TYPE sourcecode.swift) _cmake_find_compiler_path(Swift) +elseif("${CMAKE_GENERATOR}" STREQUAL "Ninja") + if(CMAKE_Swift_COMPILER) + _cmake_find_compiler_path(Swift) + else() + set(CMAKE_Swift_COMPILER_INIT NOTFOUND) + + if(NOT $ENV{SWIFTC} STREQUAL "") + get_filename_component(CMAKE_Swift_COMPILER_INIT $ENV{SWIFTC} PROGRAM + PROGRAM_ARGS CMAKE_Swift_FLAGS_ENV_INIT) + if(CMAKE_Swift_FLAGS_ENV_INIT) + set(CMAKE_Swift_COMPILER_ARG1 "${CMAKE_Swift_FLAGS_ENV_INIT}" CACHE + STRING "First argument to the Swift compiler") + endif() + if(NOT EXISTS ${CMAKE_Swift_COMPILER_INIT}) + message(FATAL_ERROR "Could not find compiler set in environment variable SWIFTC\n$ENV{SWIFTC}.\n${CMAKE_Swift_COMPILER_INIT}") + endif() + endif() + + if(NOT CMAKE_Swift_COMPILER_INIT) + set(CMAKE_Swift_COMPILER_LIST swiftc ${_CMAKE_TOOLCHAIN_PREFIX}swiftc) + endif() + + _cmake_find_compiler(Swift) + endif() + mark_as_advanced(CMAKE_Swift_COMPILER) else() message(FATAL_ERROR "Swift language not supported by \"${CMAKE_GENERATOR}\" generator") endif() @@ -18,11 +49,13 @@ endif() if(NOT CMAKE_Swift_COMPILER_ID_RUN) set(CMAKE_Swift_COMPILER_ID_RUN 1) - list(APPEND CMAKE_Swift_COMPILER_ID_MATCH_VENDORS Apple) - set(CMAKE_Swift_COMPILER_ID_MATCH_VENDOR_REGEX_Apple "com.apple.xcode.tools.swift.compiler") + if("${CMAKE_GENERATOR}" STREQUAL "Xcode") + list(APPEND CMAKE_Swift_COMPILER_ID_MATCH_VENDORS Apple) + set(CMAKE_Swift_COMPILER_ID_MATCH_VENDOR_REGEX_Apple "com.apple.xcode.tools.swift.compiler") - 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") - set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_INDEX 2) + 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") + set(CMAKE_Swift_COMPILER_ID_TOOL_MATCH_INDEX 2) + endif() # Try to identify the compiler. set(CMAKE_Swift_COMPILER_ID) @@ -40,6 +73,6 @@ unset(_CMAKE_PROCESSING_LANGUAGE) # configure variables set in this file for fast reload later on configure_file(${CMAKE_ROOT}/Modules/CMakeSwiftCompiler.cmake.in - ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake - @ONLY - ) + ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake @ONLY) + +set(CMAKE_Swift_COMPILER_ENV_VAR "SWIFTC") diff --git a/Modules/CMakeSwiftCompiler.cmake.in b/Modules/CMakeSwiftCompiler.cmake.in index 45f0a31..7c8d1c1 100644 --- a/Modules/CMakeSwiftCompiler.cmake.in +++ b/Modules/CMakeSwiftCompiler.cmake.in @@ -1,5 +1,14 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + set(CMAKE_Swift_COMPILER "@CMAKE_Swift_COMPILER@") set(CMAKE_Swift_COMPILER_ID "@CMAKE_Swift_COMPILER_ID@") +set(CMAKE_Swift_COMPILER_VERSION "@CMAKE_Swift_COMPILER_VERSION@") + +set(CMAKE_Swift_COMPILER_LOADED 1) +set(CMAKE_Swift_COMPILER_WORKS "@CMAKE_Swift_COMPILER_WORKS@") + +set(CMAKE_Swift_COMPILER_ENV_VAR "SWIFTC") set(CMAKE_Swift_COMPILER_ID_RUN 1) set(CMAKE_Swift_SOURCE_FILE_EXTENSIONS swift) diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index 07ba6d0..64e7f99 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -1,32 +1,61 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. - -set(CMAKE_Swift_OUTPUT_EXTENSION .o) -set(CMAKE_INCLUDE_FLAG_Swift "-I") +if(UNIX) + set(CMAKE_Swift_OUTPUT_EXTENSION .o) +else() + set(CMAKE_Swift_OUTPUT_EXTENSION .obj) +endif() # Load compiler-specific information. if(CMAKE_Swift_COMPILER_ID) include(Compiler/${CMAKE_Swift_COMPILER_ID}-Swift OPTIONAL) -endif() -# load the system- and compiler specific files -if(CMAKE_Swift_COMPILER_ID) - # load a hardware specific file, mostly useful for embedded compilers if(CMAKE_SYSTEM_PROCESSOR) include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_Swift_COMPILER_ID}-Swift-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL) endif() include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_Swift_COMPILER_ID}-Swift OPTIONAL) endif() -# for most systems a module is the same as a shared library -# so unless the variable CMAKE_MODULE_EXISTS is set just -# copy the values from the LIBRARY variables -if(NOT CMAKE_MODULE_EXISTS) - set(CMAKE_SHARED_MODULE_Swift_FLAGS ${CMAKE_SHARED_LIBRARY_Swift_FLAGS}) - set(CMAKE_SHARED_MODULE_CREATE_Swift_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_Swift_FLAGS}) +set(CMAKE_INCLUDE_FLAG_Swift "-I") +set(CMAKE_INCLUDE_FLAG_SEP_Swift " ") +set(CMAKE_Swift_DEFINE_FLAG -D) +set(CMAKE_Swift_COMPILE_OPTIONS_TARGET "-target ") +set(CMAKE_Swift_COMPILER_ARG1 -frontend) + +set(CMAKE_Swift_FLAGS_DEBUG_INIT "-g") +set(CMAKE_Swift_FLAGS_RELEASE_INIT "-O") +set(CMAKE_Swift_FLAGS_RELWITHDEBINFO_INIT "-O -g") +set(CMAKE_Swift_FLAGS_MINSIZEREL_INIT "-Osize") + +# NOTE(compnerd) we do not have an object compile rule since we build the objects as part of the link step +if(NOT CMAKE_Swift_COMPILE_OBJECT) + set(CMAKE_Swift_COMPILE_OBJECT ":") endif() -include(CMakeCommonLanguageInclude) +if(NOT CMAKE_Swift_CREATE_SHARED_LIBRARY) + if(CMAKE_Swift_COMPILER_TARGET) + set(CMAKE_Swift_CREATE_SHARED_LIBRARY "${CMAKE_Swift_COMPILER} -target <CMAKE_Swift_COMPILER_TARGET> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <FLAGS> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") + else() + set(CMAKE_Swift_CREATE_SHARED_LIBRARY "${CMAKE_Swift_COMPILER} -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <FLAGS> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") + endif() +endif() + +if(NOT CMAKE_Swift_CREATE_SHARED_MODULE) + set(CMAKE_Swift_CREATE_SHARED_MODULE ${CMAKE_Swift_CREATE_SHARED_LIBRARY}) +endif() + +if(NOT CMAKE_Swift_LINK_EXECUTABLE) + if(CMAKE_Swift_COMPILER_TARGET) + set(CMAKE_Swift_LINK_EXECUTABLE "${CMAKE_Swift_COMPILER} -target <CMAKE_Swift_COMPILER_TARGET> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -emit-executable -o <TARGET> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <FLAGS> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") + else() + set(CMAKE_Swift_LINK_EXECUTABLE "${CMAKE_Swift_COMPILER} -output-file-map <SWIFT_OUTPUT_FILE_MAP> -incremental -emit-executable -o <TARGET> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <FLAGS> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") + endif() +endif() + +if(NOT CMAKE_Swift_CREATE_STATIC_LIBRARY) + set(CMAKE_Swift_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <OBJECTS>") + set(CMAKE_Swift_ARCHIVE_FINISH "") +endif() set(CMAKE_Swift_INFORMATION_LOADED 1) diff --git a/Modules/CMakeTestSwiftCompiler.cmake b/Modules/CMakeTestSwiftCompiler.cmake index 858c1be..841aee6 100644 --- a/Modules/CMakeTestSwiftCompiler.cmake +++ b/Modules/CMakeTestSwiftCompiler.cmake @@ -1,7 +1,6 @@ # Distributed under the OSI-approved BSD 3-Clause License. See accompanying # file Copyright.txt or https://cmake.org/licensing for details. - if(CMAKE_Swift_COMPILER_FORCED) # The compiler configuration was forced by the user. # Assume the user has configured all compiler information. @@ -23,7 +22,6 @@ unset(CMAKE_Swift_COMPILER_WORKS CACHE) if(NOT CMAKE_Swift_COMPILER_WORKS) PrintTestCompilerStatus("Swift" "") file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.swift - "import Foundation\n" "print(\"CMake\")\n") try_compile(CMAKE_Swift_COMPILER_WORKS ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/main.swift @@ -51,6 +49,11 @@ else() "Determining if the Swift compiler works passed with " "the following output:\n${__CMAKE_Swift_COMPILER_OUTPUT}\n\n") endif() + + # Re-configure to save learned information. + configure_file(${CMAKE_ROOT}/Modules/CMakeSwiftCompiler.cmake.in + ${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake @ONLY) + include(${CMAKE_PLATFORM_INFO_DIR}/CMakeSwiftCompiler.cmake) endif() unset(__CMAKE_Swift_COMPILER_OUTPUT) |