501 lines
20 KiB
Diff
501 lines
20 KiB
Diff
From 9ee52eea768af39f4ccbc1939d1385d70bb0ef37
|
|
From: Ben Barham <ben_barham@apple.com>
|
|
Date: Tue, 16 May 2023 16:25:36 -0700
|
|
Subject: [PATCH 1/4] [CMake] Updates to allow inclusion using FetchContent
|
|
|
|
Various updates that allow swift-syntax to be included using
|
|
FetchContent.
|
|
|
|
Mostly this is just not replacing `target_link_libraries` since that is
|
|
a global replacement, but we also now use a couple of variables from the
|
|
swift if they're set (eg. `SWIFT_HOST_LIBRARIES_DEST_DIR` and
|
|
`SWIFT_HOST_MODULE_TRIPLE`).
|
|
|
|
diff --git a/swift-syntax/CMakeLists.txt b/swift-syntax/CMakeLists.txt
|
|
index aadf062ae5..c5a697ccc0 100644
|
|
--- a/swift-syntax/CMakeLists.txt
|
|
+++ b/swift-syntax/CMakeLists.txt
|
|
@@ -15,11 +15,28 @@ project(SwiftSyntax LANGUAGES C Swift)
|
|
set(SWIFT_VERSION 5)
|
|
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})
|
|
|
|
+if(CMAKE_VERSION VERSION_LESS 3.21)
|
|
+ get_property(parent_dir DIRECTORY PROPERTY PARENT_DIRECTORY)
|
|
+ if(NOT parent_dir)
|
|
+ set(PROJECT_IS_TOP_LEVEL TRUE)
|
|
+ endif()
|
|
+endif()
|
|
+
|
|
# The subdirectory into which host libraries will be installed.
|
|
set(SWIFT_HOST_LIBRARIES_SUBDIRECTORY "swift/host")
|
|
|
|
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
|
|
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
|
|
+if(SWIFT_HOST_LIBRARIES_DEST_DIR)
|
|
+ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}")
|
|
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}")
|
|
+else()
|
|
+ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
|
|
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
|
|
+endif()
|
|
+if(SWIFT_HOST_RUNTIME_DEST_DIR)
|
|
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${SWIFT_HOST_RUNTIME_DEST_DIR}")
|
|
+else()
|
|
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
|
+endif()
|
|
|
|
set(CMAKE_MACOSX_RPATH YES)
|
|
|
|
@@ -49,22 +65,25 @@ if (NOT SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT)
|
|
endif()
|
|
|
|
# Determine the module triple.
|
|
-# FIXME: This is a hack. It's all a hack. Windows isn't setting
|
|
-# CMAKE_Swift_COMPILER_TARGET.
|
|
-if(CMAKE_Swift_COMPILER_TARGET)
|
|
- string(REGEX REPLACE "macosx[0-9]+([.][0-9]+)?" "macos" SWIFT_MODULE_TRIPLE
|
|
- ${CMAKE_Swift_COMPILER_TARGET})
|
|
-elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
|
|
- if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
|
|
- set(SWIFT_MODULE_TRIPLE "x86_64-unknown-windows-msvc")
|
|
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
|
|
- set(SWIFT_MODULE_TRIPLE "aarch64-unknown-windows-msvc")
|
|
+if("${SWIFT_HOST_MODULE_TRIPLE}" STREQUAL "")
|
|
+ # FIXME: This is a hack. It's all a hack. Windows isn't setting
|
|
+ # CMAKE_Swift_COMPILER_TARGET.
|
|
+ if(CMAKE_Swift_COMPILER_TARGET)
|
|
+ string(REGEX REPLACE "macosx[0-9]+([.][0-9]+)?" "macos" SWIFT_HOST_MODULE_TRIPLE
|
|
+ ${CMAKE_Swift_COMPILER_TARGET})
|
|
+ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
|
|
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
|
|
+ set(SWIFT_HOST_MODULE_TRIPLE "x86_64-unknown-windows-msvc")
|
|
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
|
|
+ set(SWIFT_HOST_MODULE_TRIPLE "aarch64-unknown-windows-msvc")
|
|
+ else()
|
|
+ message(FATAL_ERROR "Unrecognized architecture for Windows host")
|
|
+ endif()
|
|
else()
|
|
- message(FATAL_ERROR "Unrecognized architecture for Windows host")
|
|
+ message(FATAL_ERROR "Host module triple required")
|
|
endif()
|
|
endif()
|
|
-
|
|
-message(STATUS "Module triple: ${SWIFT_MODULE_TRIPLE}")
|
|
+message(STATUS "Module triple: ${SWIFT_HOST_MODULE_TRIPLE}")
|
|
|
|
# Force single-threaded-only syntax trees to eliminate the Darwin
|
|
# dependency in the compiler.
|
|
@@ -79,9 +98,9 @@ endif()
|
|
|
|
add_subdirectory(Sources)
|
|
|
|
-export(EXPORT SwiftSyntaxTargets
|
|
- FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftSyntaxTargets.cmake"
|
|
- NAMESPACE SwiftSyntax::
|
|
-)
|
|
-
|
|
-add_subdirectory(cmake/modules)
|
|
+if(PROJECT_IS_TOP_LEVEL)
|
|
+ export(EXPORT SwiftSyntaxTargets
|
|
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftSyntaxTargets.cmake"
|
|
+ NAMESPACE SwiftSyntax::
|
|
+ )
|
|
+endif()
|
|
diff --git a/swift-syntax/Sources/CMakeLists.txt b/swift-syntax/Sources/CMakeLists.txt
|
|
index 3b317b0891..a6f6c9f5bc 100644
|
|
--- a/swift-syntax/Sources/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/CMakeLists.txt
|
|
@@ -6,31 +6,6 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-# cmake generation for Swift adds an order only dependency, which matches how C-family languages
|
|
-# works. In that case, however, ninja (and presumably other generators) will rebuild on header
|
|
-# changes. That's not the case for Swift, and thus if A -> B, A is not being rebuilt when the
|
|
-# ABI/API of B changes.
|
|
-#
|
|
-# For now workaround this by touching a file whenever B is rebuilt and then compiling that file as
|
|
-# part of A. Ideally this file would be generated by each of the targets, but that dependency didn't
|
|
-# seem to be being tracked.
|
|
-#
|
|
-# Remove once rdar://102202478 is fixed.
|
|
-function(target_link_libraries TARGET)
|
|
- cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})
|
|
-
|
|
- _target_link_libraries(${TARGET} PUBLIC ${ARGS_PUBLIC})
|
|
- foreach(DEPENDENCY ${ARGS_PUBLIC})
|
|
- add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
|
|
- COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
|
|
- DEPENDS ${DEPENDENCY}
|
|
- )
|
|
- target_sources(${TARGET} PRIVATE
|
|
- ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
|
|
- )
|
|
- endforeach()
|
|
-endfunction()
|
|
-
|
|
add_subdirectory(SwiftBasicFormat)
|
|
add_subdirectory(SwiftSyntax)
|
|
add_subdirectory(SwiftDiagnostics)
|
|
diff --git a/swift-syntax/Sources/SwiftBasicFormat/CMakeLists.txt b/swift-syntax/Sources/SwiftBasicFormat/CMakeLists.txt
|
|
index 4c6c2dcb82..05859828e7 100644
|
|
--- a/swift-syntax/Sources/SwiftBasicFormat/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftBasicFormat/CMakeLists.txt
|
|
@@ -6,12 +6,12 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftBasicFormat
|
|
+add_swift_syntax_library(SwiftBasicFormat
|
|
BasicFormat.swift
|
|
generated/BasicFormat+Extensions.swift
|
|
SyntaxProtocol+Formatted.swift
|
|
Trivia+FormatExtensions.swift
|
|
)
|
|
|
|
-target_link_libraries(SwiftBasicFormat PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftBasicFormat PUBLIC
|
|
SwiftSyntax)
|
|
diff --git a/swift-syntax/Sources/SwiftCompilerPluginMessageHandling/CMakeLists.txt b/swift-syntax/Sources/SwiftCompilerPluginMessageHandling/CMakeLists.txt
|
|
index c6e7c42432..f01fc1f2f1 100644
|
|
--- a/swift-syntax/Sources/SwiftCompilerPluginMessageHandling/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftCompilerPluginMessageHandling/CMakeLists.txt
|
|
@@ -6,7 +6,7 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftCompilerPluginMessageHandling
|
|
+add_swift_syntax_library(SwiftCompilerPluginMessageHandling
|
|
CompilerPluginMessageHandler.swift
|
|
Diagnostics.swift
|
|
Macros.swift
|
|
@@ -15,7 +15,7 @@ add_swift_host_library(SwiftCompilerPluginMessageHandling
|
|
PluginMessages.swift
|
|
)
|
|
|
|
-target_link_libraries(SwiftCompilerPluginMessageHandling PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftCompilerPluginMessageHandling PUBLIC
|
|
SwiftSyntax
|
|
SwiftBasicFormat
|
|
SwiftDiagnostics
|
|
diff --git a/swift-syntax/Sources/SwiftDiagnostics/CMakeLists.txt b/swift-syntax/Sources/SwiftDiagnostics/CMakeLists.txt
|
|
index 05281ea0bf..9807022350 100644
|
|
--- a/swift-syntax/Sources/SwiftDiagnostics/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftDiagnostics/CMakeLists.txt
|
|
@@ -6,7 +6,7 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftDiagnostics
|
|
+add_swift_syntax_library(SwiftDiagnostics
|
|
Diagnostic.swift
|
|
DiagnosticsFormatter.swift
|
|
FixIt.swift
|
|
@@ -16,5 +16,5 @@ add_swift_host_library(SwiftDiagnostics
|
|
Note.swift
|
|
)
|
|
|
|
-target_link_libraries(SwiftDiagnostics PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftDiagnostics PUBLIC
|
|
SwiftSyntax)
|
|
diff --git a/swift-syntax/Sources/SwiftIDEUtils/CMakeLists.txt b/swift-syntax/Sources/SwiftIDEUtils/CMakeLists.txt
|
|
index 309fd3efa3..3909d29315 100644
|
|
--- a/swift-syntax/Sources/SwiftIDEUtils/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftIDEUtils/CMakeLists.txt
|
|
@@ -6,11 +6,11 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftIDEUtils
|
|
+add_swift_syntax_library(SwiftIDEUtils
|
|
generated/SyntaxClassification.swift
|
|
Syntax+Classifications.swift
|
|
SyntaxClassifier.swift
|
|
)
|
|
|
|
-target_link_libraries(SwiftIDEUtils PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftIDEUtils PUBLIC
|
|
SwiftSyntax)
|
|
diff --git a/swift-syntax/Sources/SwiftOperators/CMakeLists.txt b/swift-syntax/Sources/SwiftOperators/CMakeLists.txt
|
|
index 886590411b..998b51abb6 100644
|
|
--- a/swift-syntax/Sources/SwiftOperators/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftOperators/CMakeLists.txt
|
|
@@ -6,7 +6,7 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftOperators
|
|
+add_swift_syntax_library(SwiftOperators
|
|
Operator.swift
|
|
OperatorError+Diagnostics.swift
|
|
OperatorError.swift
|
|
@@ -19,7 +19,7 @@ add_swift_host_library(SwiftOperators
|
|
SyntaxSynthesis.swift
|
|
)
|
|
|
|
-target_link_libraries(SwiftOperators PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftOperators PUBLIC
|
|
SwiftSyntax
|
|
SwiftDiagnostics
|
|
SwiftParser)
|
|
diff --git a/swift-syntax/Sources/SwiftParser/CMakeLists.txt b/swift-syntax/Sources/SwiftParser/CMakeLists.txt
|
|
index ae849ac9de..c5cce15b45 100644
|
|
--- a/swift-syntax/Sources/SwiftParser/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftParser/CMakeLists.txt
|
|
@@ -6,7 +6,7 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftParser
|
|
+add_swift_syntax_library(SwiftParser
|
|
Attributes.swift
|
|
Availability.swift
|
|
CharacterInfo.swift
|
|
@@ -52,6 +52,6 @@ add_swift_host_library(SwiftParser
|
|
Lexer/UnicodeScalarExtensions.swift
|
|
)
|
|
|
|
-target_link_libraries(SwiftParser PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftParser PUBLIC
|
|
SwiftSyntax
|
|
SwiftDiagnostics)
|
|
diff --git a/swift-syntax/Sources/SwiftParserDiagnostics/CMakeLists.txt b/swift-syntax/Sources/SwiftParserDiagnostics/CMakeLists.txt
|
|
index 91be323333..d73590bb0f 100644
|
|
--- a/swift-syntax/Sources/SwiftParserDiagnostics/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftParserDiagnostics/CMakeLists.txt
|
|
@@ -6,7 +6,7 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftParserDiagnostics
|
|
+add_swift_syntax_library(SwiftParserDiagnostics
|
|
DiagnosticExtensions.swift
|
|
LexerDiagnosticMessages.swift
|
|
MissingNodesError.swift
|
|
@@ -23,7 +23,7 @@ add_swift_host_library(SwiftParserDiagnostics
|
|
generated/TokenNameForDiagnostics.swift
|
|
)
|
|
|
|
-target_link_libraries(SwiftParserDiagnostics PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftParserDiagnostics PUBLIC
|
|
SwiftBasicFormat
|
|
SwiftDiagnostics
|
|
SwiftParser
|
|
diff --git a/swift-syntax/Sources/SwiftSyntax/CMakeLists.txt b/swift-syntax/Sources/SwiftSyntax/CMakeLists.txt
|
|
index 90c10e098b..5e59ce0e23 100644
|
|
--- a/swift-syntax/Sources/SwiftSyntax/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftSyntax/CMakeLists.txt
|
|
@@ -6,7 +6,7 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftSyntax
|
|
+add_swift_syntax_library(SwiftSyntax
|
|
AbsolutePosition.swift
|
|
Assert.swift
|
|
BumpPtrAllocator.swift
|
|
diff --git a/swift-syntax/Sources/SwiftSyntaxBuilder/CMakeLists.txt b/swift-syntax/Sources/SwiftSyntaxBuilder/CMakeLists.txt
|
|
index 36f5f1c900..38858cee6f 100644
|
|
--- a/swift-syntax/Sources/SwiftSyntaxBuilder/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftSyntaxBuilder/CMakeLists.txt
|
|
@@ -6,7 +6,7 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftSyntaxBuilder
|
|
+add_swift_syntax_library(SwiftSyntaxBuilder
|
|
ConvenienceInitializers.swift
|
|
Indenter.swift
|
|
ResultBuilderExtensions.swift
|
|
@@ -30,7 +30,7 @@ add_swift_host_library(SwiftSyntaxBuilder
|
|
target_compile_options(SwiftSyntaxBuilder PRIVATE
|
|
$<$<COMPILE_LANGUAGE:Swift>:-D;SWIFTSYNTAX_NO_OSLOG_DEPENDENCY>)
|
|
|
|
-target_link_libraries(SwiftSyntaxBuilder PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftSyntaxBuilder PUBLIC
|
|
SwiftBasicFormat
|
|
SwiftParser
|
|
SwiftParserDiagnostics
|
|
diff --git a/swift-syntax/Sources/SwiftSyntaxMacroExpansion/CMakeLists.txt b/swift-syntax/Sources/SwiftSyntaxMacroExpansion/CMakeLists.txt
|
|
index ad311fa5ee..d1a635f337 100644
|
|
--- a/swift-syntax/Sources/SwiftSyntaxMacroExpansion/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftSyntaxMacroExpansion/CMakeLists.txt
|
|
@@ -1,4 +1,4 @@
|
|
-add_swift_host_library(SwiftSyntaxMacroExpansion
|
|
+add_swift_syntax_library(SwiftSyntaxMacroExpansion
|
|
BasicMacroExpansionContext.swift
|
|
FunctionParameterUtils.swift
|
|
MacroExpansion.swift
|
|
@@ -8,7 +8,7 @@ add_swift_host_library(SwiftSyntaxMacroExpansion
|
|
Syntax+MacroEvaluation.swift
|
|
)
|
|
|
|
-target_link_libraries(SwiftSyntaxMacroExpansion PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftSyntaxMacroExpansion PUBLIC
|
|
SwiftSyntax
|
|
SwiftSyntaxMacros
|
|
)
|
|
diff --git a/swift-syntax/Sources/SwiftSyntaxMacros/CMakeLists.txt b/swift-syntax/Sources/SwiftSyntaxMacros/CMakeLists.txt
|
|
index 757b5eba93..d4dd2270d2 100644
|
|
--- a/swift-syntax/Sources/SwiftSyntaxMacros/CMakeLists.txt
|
|
+++ b/swift-syntax/Sources/SwiftSyntaxMacros/CMakeLists.txt
|
|
@@ -6,7 +6,7 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
-add_swift_host_library(SwiftSyntaxMacros
|
|
+add_swift_syntax_library(SwiftSyntaxMacros
|
|
MacroProtocols/AccessorMacro.swift
|
|
MacroProtocols/AttachedMacro.swift
|
|
MacroProtocols/CodeItemMacro.swift
|
|
@@ -24,6 +24,6 @@ add_swift_host_library(SwiftSyntaxMacros
|
|
MacroExpansionContext.swift
|
|
)
|
|
|
|
-target_link_libraries(SwiftSyntaxMacros PUBLIC
|
|
+target_link_swift_syntax_libraries(SwiftSyntaxMacros PUBLIC
|
|
SwiftSyntaxBuilder
|
|
)
|
|
diff --git a/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake b/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake
|
|
index 6428f80638..951c2d2e05 100644
|
|
--- a/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake
|
|
+++ b/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake
|
|
@@ -6,22 +6,44 @@
|
|
# See http://swift.org/LICENSE.txt for license information
|
|
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
|
|
|
|
+# cmake generation for Swift adds an order only dependency, which matches how C-family languages
|
|
+# works. In that case, however, ninja (and presumably other generators) will rebuild on header
|
|
+# changes. That's not the case for Swift, and thus if A -> B, A is not being rebuilt when the
|
|
+# ABI/API of B changes.
|
|
+#
|
|
+# For now workaround this by touching a file whenever B is rebuilt and then compiling that file as
|
|
+# part of A. Ideally this file would be generated by each of the targets, but that dependency didn't
|
|
+# seem to be being tracked.
|
|
+#
|
|
+# Remove once rdar://102202478 is fixed.
|
|
+function(target_link_swift_syntax_libraries TARGET)
|
|
+ cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})
|
|
+
|
|
+ target_link_libraries(${TARGET} PUBLIC ${ARGS_PUBLIC})
|
|
+ foreach(DEPENDENCY ${ARGS_PUBLIC})
|
|
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
|
|
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
|
|
+ DEPENDS ${DEPENDENCY}
|
|
+ )
|
|
+ target_sources(${TARGET} PRIVATE
|
|
+ ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
|
|
+ )
|
|
+ endforeach()
|
|
+endfunction()
|
|
+
|
|
# Add a new host library with the given name.
|
|
-function(add_swift_host_library name)
|
|
+function(add_swift_syntax_library name)
|
|
set(ASHL_SOURCES ${ARGN})
|
|
|
|
# Create the library target.
|
|
add_library(${name} ${ASHL_SOURCES})
|
|
|
|
- # Add this to the list of exported targets.
|
|
- set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS ${name})
|
|
-
|
|
# Determine where Swift modules will be built and installed.
|
|
set(module_dir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
|
set(module_base "${module_dir}/${name}.swiftmodule")
|
|
- set(module_file "${module_base}/${SWIFT_MODULE_TRIPLE}.swiftmodule")
|
|
- set(module_interface_file "${module_base}/${SWIFT_MODULE_TRIPLE}.swiftinterface")
|
|
- set(module_sourceinfo_file "${module_base}/${SWIFT_MODULE_TRIPLE}.swiftsourceinfo")
|
|
+ set(module_file "${module_base}/${SWIFT_HOST_MODULE_TRIPLE}.swiftmodule")
|
|
+ set(module_interface_file "${module_base}/${SWIFT_HOST_MODULE_TRIPLE}.swiftinterface")
|
|
+ set(module_sourceinfo_file "${module_base}/${SWIFT_HOST_MODULE_TRIPLE}.swiftsourceinfo")
|
|
|
|
# Add a custom target to create the module directory.
|
|
add_custom_command(
|
|
@@ -61,6 +83,18 @@ function(add_swift_host_library name)
|
|
-emit-module-interface-path;${module_interface_file}
|
|
>)
|
|
|
|
+ if(SWIFT_HOST_TRIPLE)
|
|
+ target_compile_options("${name}" PRIVATE
|
|
+ $<$<COMPILE_LANGUAGE:Swift>:-target;${SWIFT_HOST_TRIPLE};>
|
|
+ )
|
|
+ endif()
|
|
+
|
|
+ if(LLVM_USE_LINKER)
|
|
+ target_link_options(${name} PRIVATE
|
|
+ "-use-ld=${LLVM_USE_LINKER}"
|
|
+ )
|
|
+ endif()
|
|
+
|
|
# NOTE: workaround for CMake not setting up include flags yet
|
|
set_target_properties(${name} PROPERTIES
|
|
INTERFACE_INCLUDE_DIRECTORIES ${module_dir}
|
|
@@ -70,31 +104,39 @@ function(add_swift_host_library name)
|
|
BUILD_WITH_INSTALL_RPATH YES
|
|
)
|
|
|
|
+ if(SWIFT_HOST_LIBRARIES_RPATH)
|
|
+ # Don't add builder's stdlib RPATH automatically.
|
|
+ target_compile_options(${name} PRIVATE -no-toolchain-stdlib-rpath)
|
|
+ set_property(TARGET ${name}
|
|
+ PROPERTY INSTALL_RPATH "${SWIFT_HOST_LIBRARIES_RPATH}"
|
|
+ )
|
|
+ endif()
|
|
+
|
|
get_target_property(lib_type ${name} TYPE)
|
|
if(lib_type STREQUAL SHARED_LIBRARY)
|
|
if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
|
# Allow install_name_tool to update paths (for rdar://109473564)
|
|
set_property(TARGET ${name} APPEND_STRING PROPERTY
|
|
LINK_FLAGS " -Xlinker -headerpad_max_install_names")
|
|
- elseif (CMAKE_SYSTEM_NAME STREQUAL Linux)
|
|
- # Make some room to update paths.
|
|
- set_property(TARGET ${name} APPEND PROPERTY
|
|
- INSTALL_RPATH ":::::::::::::::::::::::::::::::::::::::::::::::::::::::")
|
|
endif()
|
|
endif()
|
|
|
|
- # Install this target
|
|
- install(TARGETS ${name}
|
|
- EXPORT SwiftSyntaxTargets
|
|
- ARCHIVE DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
|
|
- LIBRARY DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
|
|
- RUNTIME DESTINATION bin
|
|
- )
|
|
+ if(PROJECT_IS_TOP_LEVEL)
|
|
+ # Install this target
|
|
+ install(TARGETS ${name}
|
|
+ EXPORT SwiftSyntaxTargets
|
|
+ ARCHIVE DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
|
|
+ LIBRARY DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
|
|
+ RUNTIME DESTINATION bin
|
|
+ )
|
|
|
|
- # Install the module files.
|
|
- install(
|
|
- DIRECTORY ${module_base}
|
|
- DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
|
|
- FILES_MATCHING PATTERN "*.swiftinterface"
|
|
- )
|
|
+ # Install the module files.
|
|
+ install(
|
|
+ DIRECTORY ${module_base}
|
|
+ DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
|
|
+ FILES_MATCHING PATTERN "*.swiftinterface"
|
|
+ )
|
|
+ else()
|
|
+ set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
|
|
+ endif()
|
|
endfunction()
|
|
diff --git a/swift-syntax/cmake/modules/CMakeLists.txt b/swift-syntax/cmake/modules/CMakeLists.txt
|
|
deleted file mode 100644
|
|
index 069c64c0af..0000000000
|
|
--- a/swift-syntax/cmake/modules/CMakeLists.txt
|
|
+++ /dev/null
|
|
@@ -1,4 +0,0 @@
|
|
-get_property(SWIFTSYNTAX_EXPORTS GLOBAL PROPERTY SWIFTSYNTAX_EXPORTS)
|
|
-export(TARGETS ${SWIFTSYNTAX_EXPORTS}
|
|
- FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftSyntaxConfig.cmake
|
|
- NAMESPACE SwiftSyntax::)
|