Skip to content

Commit 6dabd36

Browse files
authored
Merge pull request #1097 from DougGregor/swift-host-libs
2 parents 715f125 + c992215 commit 6dabd36

File tree

12 files changed

+99
-140
lines changed

12 files changed

+99
-140
lines changed

CMakeLists.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ project(SwiftSyntax LANGUAGES C Swift)
1515
set(SWIFT_VERSION 5)
1616
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})
1717

18-
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
18+
# The subdirectory into which host libraries will be installed.
19+
set(SWIFT_HOST_LIBRARIES_SUBDIRECTORY "swift/host")
1920

20-
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
21-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
22-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
21+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
22+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
2323

2424
set(CMAKE_MACOSX_RPATH YES)
2525

26+
include(AddSwiftHostLibrary)
27+
2628
# Ensure that we do not link the _StringProcessing module. But we can
2729
# only pass this flag for new-enough compilers that support it.
2830
file(WRITE "${CMAKE_BINARY_DIR}/tmp/empty-check-string-processing.swift" "")
@@ -42,6 +44,24 @@ if (NOT SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT)
4244
$<$<COMPILE_LANGUAGE:Swift>:-disable-implicit-string-processing-module-import>)
4345
endif()
4446

47+
# Determine the module triple.
48+
# FIXME: This is a hack. It's all a hack. Windows isn't setting
49+
# CMAKE_Swift_COMPILER_TARGET.
50+
if(CMAKE_Swift_COMPILER_TARGET)
51+
string(REGEX REPLACE "macosx[0-9]+([.][0-9]+)?" "macos" SWIFT_MODULE_TRIPLE
52+
${CMAKE_Swift_COMPILER_TARGET})
53+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
54+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
55+
set(SWIFT_MODULE_TRIPLE "x86_64-unknown-windows-msvc")
56+
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
57+
set(SWIFT_MODULE_TRIPLE "aarch64-unknown-windows-msvc")
58+
else()
59+
message(FATAL_ERROR "Unrecognized architecture for Windows host")
60+
endif()
61+
endif()
62+
63+
message(STATUS "Module triple: ${SWIFT_MODULE_TRIPLE}")
64+
4565
# Force single-threaded-only syntax trees to eliminate the Darwin
4666
# dependency in the compiler.
4767
add_compile_definitions(

Sources/IDEUtils/CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,11 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(IDEUtils STATIC
9+
add_swift_host_library(IDEUtils
1010
gyb_generated/SyntaxClassification.swift
1111
Syntax+Classifications.swift
1212
SyntaxClassifier.swift
1313
)
1414

1515
target_link_libraries(IDEUtils PUBLIC
1616
SwiftSyntax)
17-
18-
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS IDEUtils)
19-
20-
# NOTE: workaround for CMake not setting up include flags yet
21-
set_target_properties(IDEUtils PROPERTIES
22-
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
23-
24-
install(TARGETS IDEUtils
25-
EXPORT SwiftSyntaxTargets
26-
ARCHIVE DESTINATION lib
27-
LIBRARY DESTINATION lib
28-
RUNTIME DESTINATION bin)

Sources/SwiftBasicFormat/CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,11 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SwiftBasicFormat STATIC
9+
add_swift_host_library(SwiftBasicFormat
1010
generated/BasicFormat.swift
1111
SyntaxProtocol+Formatted.swift
1212
Trivia+Indented.swift
1313
)
1414

1515
target_link_libraries(SwiftBasicFormat PUBLIC
1616
SwiftSyntax)
17-
18-
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftBasicFormat)
19-
20-
# NOTE: workaround for CMake not setting up include flags yet
21-
set_target_properties(SwiftBasicFormat PROPERTIES
22-
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
23-
24-
install(TARGETS SwiftBasicFormat
25-
EXPORT SwiftSyntaxTargets
26-
ARCHIVE DESTINATION lib
27-
LIBRARY DESTINATION lib
28-
RUNTIME DESTINATION bin)

Sources/SwiftCompilerSupport/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SwiftCompilerSupport STATIC
9+
add_swift_host_library(SwiftCompilerSupport
1010
ConsistencyCheck.swift
1111
)
1212

@@ -17,16 +17,3 @@ target_link_libraries(SwiftCompilerSupport PUBLIC
1717
SwiftParserDiagnostics
1818
SwiftOperators
1919
)
20-
21-
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftCompilerSupport)
22-
23-
# NOTE: workaround for CMake not setting up include flags yet
24-
set_target_properties(SwiftCompilerSupport PROPERTIES
25-
INTERFACE_INCLUDE_DIRECTORIES
26-
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")
27-
28-
install(TARGETS SwiftCompilerSupport
29-
EXPORT SwiftSyntaxTargets
30-
ARCHIVE DESTINATION lib
31-
LIBRARY DESTINATION lib
32-
RUNTIME DESTINATION bin)

Sources/SwiftDiagnostics/CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SwiftDiagnostics STATIC
9+
add_swift_host_library(SwiftDiagnostics
1010
Diagnostic.swift
1111
DiagnosticsFormatter.swift
1212
FixIt.swift
@@ -16,15 +16,3 @@ add_library(SwiftDiagnostics STATIC
1616

1717
target_link_libraries(SwiftDiagnostics PUBLIC
1818
SwiftSyntax)
19-
20-
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftDiagnostics)
21-
22-
# NOTE: workaround for CMake not setting up include flags yet
23-
set_target_properties(SwiftDiagnostics PROPERTIES
24-
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
25-
26-
install(TARGETS SwiftDiagnostics
27-
EXPORT SwiftSyntaxTargets
28-
ARCHIVE DESTINATION lib
29-
LIBRARY DESTINATION lib
30-
RUNTIME DESTINATION bin)

Sources/SwiftOperators/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SwiftOperators STATIC
9+
add_swift_host_library(SwiftOperators
1010
Operator.swift
1111
OperatorError+Diagnostics.swift
1212
OperatorError.swift
@@ -23,16 +23,3 @@ target_link_libraries(SwiftOperators PUBLIC
2323
SwiftSyntax
2424
SwiftDiagnostics
2525
SwiftParser)
26-
27-
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftOperators)
28-
29-
# NOTE: workaround for CMake not setting up include flags yet
30-
set_target_properties(SwiftOperators PROPERTIES
31-
INTERFACE_INCLUDE_DIRECTORIES
32-
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")
33-
34-
install(TARGETS SwiftOperators
35-
EXPORT SwiftSyntaxTargets
36-
ARCHIVE DESTINATION lib
37-
LIBRARY DESTINATION lib
38-
RUNTIME DESTINATION bin)

Sources/SwiftParser/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SwiftParser STATIC
9+
add_swift_host_library(SwiftParser
1010
Attributes.swift
1111
Availability.swift
1212
CharacterInfo.swift
@@ -40,16 +40,3 @@ add_library(SwiftParser STATIC
4040
target_link_libraries(SwiftParser PUBLIC
4141
SwiftSyntax
4242
SwiftDiagnostics)
43-
44-
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftParser)
45-
46-
# NOTE: workaround for CMake not setting up include flags yet
47-
set_target_properties(SwiftParser PROPERTIES
48-
INTERFACE_INCLUDE_DIRECTORIES
49-
"${CMAKE_Swift_MODULE_DIRECTORY}")
50-
51-
install(TARGETS SwiftParser
52-
EXPORT SwiftSyntaxTargets
53-
ARCHIVE DESTINATION lib
54-
LIBRARY DESTINATION lib
55-
RUNTIME DESTINATION bin)

Sources/SwiftParserDiagnostics/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SwiftParserDiagnostics STATIC
9+
add_swift_host_library(SwiftParserDiagnostics
1010
DiagnosticExtensions.swift
1111
MissingNodesError.swift
1212
ParserDiagnosticMessages.swift
@@ -20,16 +20,3 @@ target_link_libraries(SwiftParserDiagnostics PUBLIC
2020
SwiftDiagnostics
2121
SwiftParser
2222
SwiftSyntax)
23-
24-
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftParserDiagnostics)
25-
26-
# NOTE: workaround for CMake not setting up include flags yet
27-
set_target_properties(SwiftParserDiagnostics PROPERTIES
28-
INTERFACE_INCLUDE_DIRECTORIES
29-
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")
30-
31-
install(TARGETS SwiftParserDiagnostics
32-
EXPORT SwiftSyntaxTargets
33-
ARCHIVE DESTINATION lib
34-
LIBRARY DESTINATION lib
35-
RUNTIME DESTINATION bin)

Sources/SwiftSyntax/CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SwiftSyntax STATIC
9+
add_swift_host_library(SwiftSyntax
1010
AbsolutePosition.swift
1111
BumpPtrAllocator.swift
1212
CommonAncestor.swift
@@ -54,15 +54,3 @@ add_library(SwiftSyntax STATIC
5454
gyb_generated/syntax_nodes/SyntaxStmtNodes.swift
5555
gyb_generated/syntax_nodes/SyntaxTypeNodes.swift
5656
)
57-
58-
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftSyntax)
59-
60-
# NOTE: workaround for CMake not setting up include flags yet
61-
set_target_properties(SwiftSyntax PROPERTIES
62-
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
63-
64-
install(TARGETS SwiftSyntax
65-
EXPORT SwiftSyntaxTargets
66-
ARCHIVE DESTINATION lib
67-
LIBRARY DESTINATION lib
68-
RUNTIME DESTINATION bin)

Sources/SwiftSyntaxBuilder/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# See http://swift.org/LICENSE.txt for license information
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

9-
add_library(SwiftSyntaxBuilder STATIC
9+
add_swift_host_library(SwiftSyntaxBuilder
1010
ConvenienceInitializers.swift
1111
HasTrailingComma.swift
1212
Indenter.swift
@@ -29,16 +29,3 @@ target_link_libraries(SwiftSyntaxBuilder PUBLIC
2929
SwiftParserDiagnostics
3030
SwiftSyntax
3131
)
32-
33-
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftSyntaxBuilder)
34-
35-
# NOTE: workaround for CMake not setting up include flags yet
36-
set_target_properties(SwiftSyntaxBuilder PROPERTIES
37-
INTERFACE_INCLUDE_DIRECTORIES
38-
"${CMAKE_Swift_MODULE_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}")
39-
40-
install(TARGETS SwiftSyntaxBuilder
41-
EXPORT SwiftSyntaxTargets
42-
ARCHIVE DESTINATION lib
43-
LIBRARY DESTINATION lib
44-
RUNTIME DESTINATION bin)

0 commit comments

Comments
 (0)