Skip to content

Commit 2cd5873

Browse files
authored
Merge pull request swiftlang#646 from DougGregor/cmake-build
2 parents 6eb1701 + 87b53ab commit 2cd5873

File tree

8 files changed

+210
-1
lines changed

8 files changed

+210
-1
lines changed

CMakeLists.txt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
cmake_minimum_required(VERSION 3.19.6)
10+
11+
project(SwiftSyntax LANGUAGES C Swift)
12+
13+
set(SWIFT_VERSION 5)
14+
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})
15+
16+
# ensure Swift compiler can find _CSwiftSyntax
17+
add_compile_options($<$<COMPILE_LANGUAGE:Swift>:-I$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}/Sources/_CSwiftSyntax/include>)
18+
19+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
20+
21+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
22+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
23+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
24+
25+
set(CMAKE_MACOSX_RPATH YES)
26+
27+
add_subdirectory(Sources)

Package.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,22 @@ let package = Package(
5555
.target(
5656
name: "_CSwiftSyntax",
5757
exclude: [
58+
"CMakeLists.txt",
5859
"README.md"
5960
]
6061
),
6162
.target(
6263
name: "SwiftDiagnostics",
63-
dependencies: ["SwiftSyntax"]
64+
dependencies: ["SwiftSyntax"],
65+
exclude: [
66+
"CMakeLists.txt"
67+
]
6468
),
6569
.target(
6670
name: "SwiftSyntax",
6771
dependencies: ["_CSwiftSyntax"],
6872
exclude: [
73+
"CMakeLists.txt",
6974
"Misc.swift.gyb",
7075
"Raw/RawSyntaxNodes.swift.gyb",
7176
"Raw/RawSyntaxValidation.swift.gyb",
@@ -111,6 +116,7 @@ let package = Package(
111116
name: "SwiftParser",
112117
dependencies: ["SwiftDiagnostics", "SwiftSyntax"],
113118
exclude: [
119+
"CMakeLists.txt",
114120
"README.md"
115121
]
116122
),

Sources/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_subdirectory(_CSwiftSyntax)
10+
add_subdirectory(SwiftSyntax)
11+
add_subdirectory(SwiftDiagnostics)
12+
add_subdirectory(SwiftParser)
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(SwiftDiagnostics STATIC
10+
FixIt.swift
11+
Message.swift
12+
Diagnostic.swift
13+
)
14+
15+
target_link_libraries(SwiftDiagnostics PUBLIC
16+
SwiftSyntax)
17+
18+
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftDiagnostics)
19+
20+
# NOTE: workaround for CMake not setting up include flags yet
21+
set_target_properties(SwiftDiagnostics PROPERTIES
22+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
23+
24+
install(TARGETS SwiftDiagnostics
25+
ARCHIVE DESTINATION lib
26+
LIBRARY DESTINATION lib
27+
RUNTIME DESTINATION bin)

Sources/SwiftParser/CMakeLists.txt

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(SwiftParser STATIC
10+
Names.swift
11+
Lexer.swift
12+
Declarations.swift
13+
Directives.swift
14+
CharacterInfo.swift
15+
Attributes.swift
16+
Lookahead.swift
17+
Expressions.swift
18+
LoopProgressCondition.swift
19+
Statements.swift
20+
TokenPrecedence.swift
21+
Modifiers.swift
22+
Patterns.swift
23+
Availability.swift
24+
TriviaParser.swift
25+
TokenConsumer.swift
26+
Parser.swift
27+
Recovery.swift
28+
TopLevel.swift
29+
Types.swift
30+
31+
Diagnostics/ParserDiagnosticMessages.swift
32+
Diagnostics/ParseDiagnosticsGenerator.swift)
33+
34+
target_link_libraries(SwiftParser PUBLIC
35+
SwiftSyntax
36+
SwiftDiagnostics)
37+
38+
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftParser)
39+
40+
# Rename the installed library to avoid clashing with the C++
41+
# "libswiftParser" on case-insensitive file systems.
42+
set_target_properties(SwiftParser PROPERTIES OUTPUT_NAME "SwiftSwiftParser")
43+
44+
# NOTE: workaround for CMake not setting up include flags yet
45+
set_target_properties(SwiftParser PROPERTIES
46+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
47+
48+
install(TARGETS SwiftParser
49+
ARCHIVE DESTINATION lib
50+
LIBRARY DESTINATION lib
51+
RUNTIME DESTINATION bin)

Sources/SwiftSyntax/CMakeLists.txt

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(SwiftSyntax STATIC
10+
AbsolutePosition.swift
11+
AtomicCounter.swift
12+
BumpPtrAllocator.swift
13+
IncrementalParseTransition.swift
14+
SourceLength.swift
15+
SourceLocation.swift
16+
SourcePresence.swift
17+
Syntax.swift
18+
SyntaxArena.swift
19+
SyntaxChildren.swift
20+
SyntaxClassifier.swift
21+
SyntaxData.swift
22+
SyntaxOtherNodes.swift
23+
SyntaxText.swift
24+
SyntaxTreeViewMode.swift
25+
SyntaxVerifier.swift
26+
Utils.swift
27+
28+
Raw/RawSyntax.swift
29+
Raw/RawSyntaxLayoutView.swift
30+
Raw/RawSyntaxNodeProtocol.swift
31+
Raw/RawSyntaxTokenView.swift
32+
33+
Raw/gyb_generated/RawSyntaxNodes.swift
34+
Raw/gyb_generated/RawSyntaxValidation.swift
35+
36+
gyb_generated/Misc.swift
37+
gyb_generated/SyntaxAnyVisitor.swift
38+
gyb_generated/SyntaxBaseNodes.swift
39+
gyb_generated/SyntaxClassification.swift
40+
gyb_generated/SyntaxCollections.swift
41+
gyb_generated/SyntaxEnum.swift
42+
gyb_generated/SyntaxFactory.swift
43+
gyb_generated/SyntaxKind.swift
44+
gyb_generated/SyntaxRewriter.swift
45+
gyb_generated/SyntaxTraits.swift
46+
gyb_generated/SyntaxVisitor.swift
47+
gyb_generated/TokenKind.swift
48+
gyb_generated/Tokens.swift
49+
gyb_generated/Trivia.swift
50+
51+
gyb_generated/syntax_nodes/SyntaxDeclNodes.swift
52+
gyb_generated/syntax_nodes/SyntaxExprNodes.swift
53+
gyb_generated/syntax_nodes/SyntaxNodes.swift
54+
gyb_generated/syntax_nodes/SyntaxPatternNodes.swift
55+
gyb_generated/syntax_nodes/SyntaxStmtNodes.swift
56+
gyb_generated/syntax_nodes/SyntaxTypeNodes.swift
57+
)
58+
59+
target_link_libraries(SwiftSyntax PRIVATE
60+
_CSwiftSyntax)
61+
62+
set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS SwiftSyntax)
63+
64+
# NOTE: workaround for CMake not setting up include flags yet
65+
set_target_properties(SwiftSyntax PROPERTIES
66+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
67+
68+
install(TARGETS SwiftSyntax
69+
ARCHIVE DESTINATION lib
70+
LIBRARY DESTINATION lib
71+
RUNTIME DESTINATION bin)

Sources/_CSwiftSyntax/CMakeLists.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
10+
add_library(_CSwiftSyntax STATIC
11+
src/atomic-counter.c)
12+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module _CSwiftSyntax {
2+
header "atomic-counter.h"
3+
}

0 commit comments

Comments
 (0)