Skip to content

Commit d8cbdc3

Browse files
authored
Merge pull request swiftlang#76843 from rintaro/cmake-astgen-cxxinterop
[CMake] Reorganize CMakeLists.txt for ASTGen
2 parents 79a0afb + d480761 commit d8cbdc3

File tree

6 files changed

+106
-112
lines changed

6 files changed

+106
-112
lines changed

cmake/modules/AddPureSwift.cmake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,39 @@ function(_add_host_swift_compile_options name)
8282
endif()
8383
endfunction()
8484

85+
# Set compile options for C/C++ interop
86+
function(_set_swift_cxx_interop_options name)
87+
target_compile_options(${name} PRIVATE
88+
"SHELL: -Xcc -std=c++17 -Xcc -DCOMPILED_WITH_SWIFT"
89+
90+
# FIXME: Needed to work around an availability issue with CxxStdlib
91+
"SHELL: -Xfrontend -disable-target-os-checking"
92+
93+
# Necessary to avoid treating IBOutlet and IBAction as keywords
94+
"SHELL:-Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable"
95+
)
96+
97+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
98+
target_compile_options(${name} PRIVATE
99+
# Make 'offsetof()' a const value.
100+
"SHELL:-Xcc -D_CRT_USE_BUILTIN_OFFSETOF"
101+
# Workaround for https://github.com/swiftlang/llvm-project/issues/7172
102+
"SHELL:-Xcc -Xclang -Xcc -fmodule-format=raw"
103+
)
104+
endif()
105+
106+
# Prior to 5.9, we have to use the experimental flag for C++ interop.
107+
if (CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.9)
108+
target_compile_options(${name} PRIVATE
109+
"SHELL:-Xfrontend -enable-experimental-cxx-interop"
110+
)
111+
else()
112+
target_compile_options(${name} PRIVATE
113+
"-cxx-interoperability-mode=default"
114+
)
115+
endif()
116+
endfunction()
117+
85118
function(_set_pure_swift_link_flags name relpath_to_lib_dir)
86119
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD")
87120
# Don't add builder's stdlib RPATH automatically.
@@ -171,6 +204,9 @@ endfunction()
171204
# STATIC
172205
# Build a static library.
173206
#
207+
# CXX_INTEROP
208+
# Use C++ interop.
209+
#
174210
# EMIT_MODULE
175211
# Emit '.swiftmodule' to
176212
#
@@ -196,6 +232,7 @@ function(add_pure_swift_host_library name)
196232
set(options
197233
SHARED
198234
STATIC
235+
CXX_INTEROP
199236
EMIT_MODULE)
200237
set(single_parameter_options
201238
PACKAGE_NAME)
@@ -223,6 +260,9 @@ function(add_pure_swift_host_library name)
223260
add_library(${name} ${libkind} ${APSHL_SOURCES})
224261
_add_host_swift_compile_options(${name})
225262
_set_pure_swift_package_options(${name} "${APSHL_PACKAGE_NAME}")
263+
if(APSHL_CXX_INTEROP)
264+
_set_swift_cxx_interop_options(${name})
265+
endif()
226266

227267
set_property(TARGET ${name}
228268
PROPERTY BUILD_WITH_INSTALL_RPATH YES)

lib/ASTGen/CMakeLists.txt

Lines changed: 3 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(ASTGen_Swift_dependencies)
1+
add_subdirectory(Sources)
22

33
# If requested, build the regular expression parser into the compiler itself.
44
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
@@ -14,116 +14,7 @@ if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
1414
add_pure_swift_host_library(_CompilerRegexParser STATIC
1515
"${COMPILER_REGEX_PARSER_SOURCES}"
1616
)
17-
18-
list(APPEND ASTGen_Swift_dependencies _CompilerRegexParser)
19-
endif()
20-
21-
add_pure_swift_host_library(swiftASTGen STATIC
22-
Sources/ASTGen/ASTGen.swift
23-
Sources/ASTGen/ASTGen+CompilerBuildConfiguration.swift
24-
Sources/ASTGen/Bridge.swift
25-
Sources/ASTGen/CompilerBuildConfiguration.swift
26-
Sources/ASTGen/DeclAttrs.swift
27-
Sources/ASTGen/Decls.swift
28-
Sources/ASTGen/Diagnostics.swift
29-
Sources/ASTGen/DiagnosticsBridge.swift
30-
Sources/ASTGen/Exprs.swift
31-
Sources/ASTGen/Generics.swift
32-
Sources/ASTGen/LegacyParse.swift
33-
Sources/ASTGen/Literals.swift
34-
Sources/ASTGen/ParameterClause.swift
35-
Sources/ASTGen/Patterns.swift
36-
Sources/ASTGen/Regex.swift
37-
Sources/ASTGen/SourceFile.swift
38-
Sources/ASTGen/Stmts.swift
39-
Sources/ASTGen/TypeAttrs.swift
40-
Sources/ASTGen/Types.swift
41-
42-
DEPENDENCIES
43-
swiftAST
44-
SWIFT_DEPENDENCIES
45-
_CompilerSwiftSyntax
46-
_CompilerSwiftIfConfig
47-
_CompilerSwiftOperators
48-
_CompilerSwiftSyntaxBuilder
49-
_CompilerSwiftParser
50-
_CompilerSwiftParserDiagnostics
51-
_CompilerSwiftDiagnostics
52-
${ASTGen_Swift_dependencies}
53-
)
54-
55-
add_pure_swift_host_library(swiftMacros STATIC
56-
Sources/Macros/Macros.swift
57-
Sources/Macros/PluginHost.swift
58-
Sources/Macros/SourceManager.swift
59-
60-
DEPENDENCIES
61-
swiftAST
62-
SWIFT_DEPENDENCIES
63-
_CompilerSwiftCompilerPluginMessageHandling
64-
_CompilerSwiftDiagnostics
65-
_CompilerSwiftOperators
66-
_CompilerSwiftParser
67-
_CompilerSwiftSyntax
68-
_CompilerSwiftSyntaxMacroExpansion
69-
swiftASTGen
70-
)
71-
72-
add_pure_swift_host_library(swiftIDEUtilsBridging
73-
Sources/SwiftIDEUtilsBridging/NameMatcherBridging.swift
74-
75-
DEPENDENCIES
76-
swiftAST
77-
SWIFT_DEPENDENCIES
78-
_CompilerSwiftIDEUtils
79-
_CompilerSwiftSyntax
80-
swiftASTGen
81-
)
82-
83-
set(c_include_paths
84-
# LLVM modules and headers.
85-
"${LLVM_MAIN_INCLUDE_DIR}"
86-
# Generated LLVM headers.
87-
"${LLVM_INCLUDE_DIR}"
88-
# Clang modules and headers.
89-
${CLANG_INCLUDE_DIRS}
90-
# Bridging modules and headers.
91-
"${SWIFT_MAIN_INCLUDE_DIR}"
92-
# Generated C headers.
93-
"${CMAKE_CURRENT_BINARY_DIR}/../../include")
94-
set(c_include_paths_args)
95-
foreach(c_include_path ${c_include_paths})
96-
list(APPEND c_include_paths_args "SHELL: -Xcc -I -Xcc ${c_include_path}")
97-
endforeach()
98-
99-
set(compile_options
100-
${c_include_paths_args}
101-
"SHELL: -Xcc -std=c++17 -Xcc -DCOMPILED_WITH_SWIFT"
102-
103-
# FIXME: Needed to work around an availability issue with CxxStdlib
104-
"SHELL: -Xfrontend -disable-target-os-checking"
105-
106-
# Necessary to avoid treating IBOutlet and IBAction as keywords
107-
"SHELL:-Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable"
108-
)
109-
110-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
111-
list(APPEND compile_options
112-
# Make 'offsetof()' a const value.
113-
"SHELL:-Xcc -D_CRT_USE_BUILTIN_OFFSETOF"
114-
# Workaround for https://github.com/swiftlang/llvm-project/issues/7172
115-
"SHELL:-Xcc -Xclang -Xcc -fmodule-format=raw")
116-
endif()
117-
118-
# Prior to 5.9, we have to use the experimental flag for C++ interop.
119-
if (CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.9)
120-
list(APPEND compile_options "SHELL:-Xfrontend -enable-experimental-cxx-interop")
12117
else()
122-
list(APPEND compile_options "-cxx-interoperability-mode=default")
123-
endif()
124-
125-
if(SWIFT_BUILD_SWIFT_SYNTAX)
126-
foreach(target swiftASTGen swiftIDEUtilsBridging swiftMacros)
127-
target_compile_options(${target} PRIVATE ${compile_options})
128-
endforeach()
18+
# Dummy target for dependencies
19+
add_custom_target(_CompilerRegexParser)
12920
endif()
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
add_pure_swift_host_library(swiftASTGen STATIC CXX_INTEROP
2+
ASTGen.swift
3+
ASTGen+CompilerBuildConfiguration.swift
4+
Bridge.swift
5+
CompilerBuildConfiguration.swift
6+
DeclAttrs.swift
7+
Decls.swift
8+
Diagnostics.swift
9+
DiagnosticsBridge.swift
10+
Exprs.swift
11+
Generics.swift
12+
LegacyParse.swift
13+
Literals.swift
14+
ParameterClause.swift
15+
Patterns.swift
16+
Regex.swift
17+
SourceFile.swift
18+
Stmts.swift
19+
TypeAttrs.swift
20+
Types.swift
21+
22+
DEPENDENCIES
23+
swiftAST
24+
SWIFT_DEPENDENCIES
25+
_CompilerRegexParser
26+
_CompilerSwiftSyntax
27+
_CompilerSwiftIfConfig
28+
_CompilerSwiftOperators
29+
_CompilerSwiftSyntaxBuilder
30+
_CompilerSwiftParser
31+
_CompilerSwiftParserDiagnostics
32+
_CompilerSwiftDiagnostics
33+
)

lib/ASTGen/Sources/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_subdirectory(ASTGen)
2+
add_subdirectory(Macros)
3+
add_subdirectory(SwiftIDEUtilsBridging)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
add_pure_swift_host_library(swiftMacros STATIC CXX_INTEROP
2+
Macros.swift
3+
PluginHost.swift
4+
SourceManager.swift
5+
6+
DEPENDENCIES
7+
swiftAST
8+
SWIFT_DEPENDENCIES
9+
_CompilerSwiftCompilerPluginMessageHandling
10+
_CompilerSwiftDiagnostics
11+
_CompilerSwiftOperators
12+
_CompilerSwiftParser
13+
_CompilerSwiftSyntax
14+
_CompilerSwiftSyntaxMacroExpansion
15+
swiftASTGen
16+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
add_pure_swift_host_library(swiftIDEUtilsBridging CXX_INTEROP
2+
NameMatcherBridging.swift
3+
4+
DEPENDENCIES
5+
swiftAST
6+
SWIFT_DEPENDENCIES
7+
_CompilerSwiftIDEUtils
8+
_CompilerSwiftSyntax
9+
_CompilerSwiftIDEUtils
10+
swiftASTGen
11+
)

0 commit comments

Comments
 (0)