Skip to content

Commit fdacd9d

Browse files
committed
[CMake] Add 'CXX_INTEROP' option to add_pure_swift_host_library
1 parent 58ba27b commit fdacd9d

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
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: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
1818
list(APPEND ASTGen_Swift_dependencies _CompilerRegexParser)
1919
endif()
2020

21-
add_pure_swift_host_library(swiftASTGen STATIC
21+
add_pure_swift_host_library(swiftASTGen STATIC CXX_INTEROP
2222
Sources/ASTGen/ASTGen.swift
2323
Sources/ASTGen/ASTGen+CompilerBuildConfiguration.swift
2424
Sources/ASTGen/Bridge.swift
@@ -52,7 +52,7 @@ add_pure_swift_host_library(swiftASTGen STATIC
5252
${ASTGen_Swift_dependencies}
5353
)
5454

55-
add_pure_swift_host_library(swiftMacros STATIC
55+
add_pure_swift_host_library(swiftMacros STATIC CXX_INTEROP
5656
Sources/Macros/Macros.swift
5757
Sources/Macros/PluginHost.swift
5858
Sources/Macros/SourceManager.swift
@@ -69,44 +69,14 @@ add_pure_swift_host_library(swiftMacros STATIC
6969
swiftASTGen
7070
)
7171

72-
add_pure_swift_host_library(swiftIDEUtilsBridging
72+
add_pure_swift_host_library(swiftIDEUtilsBridging CXX_INTEROP
7373
Sources/SwiftIDEUtilsBridging/NameMatcherBridging.swift
7474

7575
DEPENDENCIES
7676
swiftAST
7777
SWIFT_DEPENDENCIES
7878
_CompilerSwiftIDEUtils
7979
_CompilerSwiftSyntax
80+
_CompilerSwiftIDEUtils
8081
swiftASTGen
8182
)
82-
83-
set(compile_options
84-
"SHELL: -Xcc -std=c++17 -Xcc -DCOMPILED_WITH_SWIFT"
85-
86-
# FIXME: Needed to work around an availability issue with CxxStdlib
87-
"SHELL: -Xfrontend -disable-target-os-checking"
88-
89-
# Necessary to avoid treating IBOutlet and IBAction as keywords
90-
"SHELL:-Xcc -UIBOutlet -Xcc -UIBAction -Xcc -UIBInspectable"
91-
)
92-
93-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
94-
list(APPEND compile_options
95-
# Make 'offsetof()' a const value.
96-
"SHELL:-Xcc -D_CRT_USE_BUILTIN_OFFSETOF"
97-
# Workaround for https://github.com/swiftlang/llvm-project/issues/7172
98-
"SHELL:-Xcc -Xclang -Xcc -fmodule-format=raw")
99-
endif()
100-
101-
# Prior to 5.9, we have to use the experimental flag for C++ interop.
102-
if (CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.9)
103-
list(APPEND compile_options "SHELL:-Xfrontend -enable-experimental-cxx-interop")
104-
else()
105-
list(APPEND compile_options "-cxx-interoperability-mode=default")
106-
endif()
107-
108-
if(SWIFT_BUILD_SWIFT_SYNTAX)
109-
foreach(target swiftASTGen swiftIDEUtilsBridging swiftMacros)
110-
target_compile_options(${target} PRIVATE ${compile_options})
111-
endforeach()
112-
endif()

0 commit comments

Comments
 (0)