Skip to content

Commit 5b31444

Browse files
authored
Merge pull request swiftlang#64082 from DougGregor/cmake-macro-rework
2 parents 57733f9 + e9ebcba commit 5b31444

File tree

7 files changed

+345
-328
lines changed

7 files changed

+345
-328
lines changed

lib/ASTGen/CMakeLists.txt

Lines changed: 20 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,20 @@
1-
if (SWIFT_SWIFT_PARSER)
2-
# Ensure that we do not link the _StringProcessing module. But we can
3-
# only pass this flag for new-enough compilers that support it.
4-
file(WRITE "${CMAKE_BINARY_DIR}/tmp/empty-check-string-processing.swift" "")
5-
execute_process(
6-
COMMAND
7-
"${CMAKE_Swift_COMPILER}"
8-
-Xfrontend -disable-implicit-string-processing-module-import
9-
-c - -o /dev/null
10-
INPUT_FILE
11-
"${CMAKE_BINARY_DIR}/tmp/empty-check-string-processing.swift"
12-
OUTPUT_QUIET ERROR_QUIET
13-
RESULT_VARIABLE
14-
SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT)
15-
if (NOT SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT)
16-
add_compile_options(
17-
$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend>
18-
$<$<COMPILE_LANGUAGE:Swift>:-disable-implicit-string-processing-module-import>)
19-
endif()
20-
21-
add_library(swiftASTGen STATIC
22-
Sources/ASTGen/ASTGen.swift
23-
Sources/ASTGen/Decls.swift
24-
Sources/ASTGen/Diagnostics.swift
25-
Sources/ASTGen/Exprs.swift
26-
Sources/ASTGen/Generics.swift
27-
Sources/ASTGen/Literals.swift
28-
Sources/ASTGen/LLVMJSON.swift
29-
Sources/ASTGen/Macros.swift
30-
Sources/ASTGen/Misc.swift
31-
Sources/ASTGen/PluginHost.swift
32-
Sources/ASTGen/PluginMessages.swift
33-
Sources/ASTGen/SourceFile.swift
34-
Sources/ASTGen/SourceManager.swift
35-
Sources/ASTGen/SourceManager+MacroExpansionContext.swift
36-
Sources/ASTGen/Stmts.swift
37-
Sources/ASTGen/Types.swift
38-
)
39-
40-
# The compat56 library is not available in current toolchains. The stage-0
41-
# compiler will build fine since the builder compiler is not aware of the 56
42-
# compat library, but the stage-1 and subsequent stage compilers will fail as
43-
# the stage-0 compiler is aware and will attempt to include the appropriate
44-
# compatibility library. We should turn this back on once we are building the
45-
# compiler correctly.
46-
# Note: This is safe at the moment because the 5.6 compat library only
47-
# contains concurrency runtime fixes, and the compiler frontend does not
48-
# use concurrency at the moment.
49-
target_compile_options(swiftASTGen PRIVATE
50-
$<$<COMPILE_LANGUAGE:Swift>:-runtime-compatibility-version>
51-
$<$<COMPILE_LANGUAGE:Swift>:none>)
52-
53-
# Set the appropriate target triple.
54-
if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
55-
set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}")
56-
endif()
57-
58-
if(SWIFT_HOST_VARIANT_SDK STREQUAL ANDROID)
59-
set(DEPLOYMENT_VERSION ${SWIFT_ANDROID_API_LEVEL})
60-
endif()
61-
62-
get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}"
63-
MACCATALYST_BUILD_FLAVOR ""
64-
DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}")
65-
66-
target_compile_options(swiftASTGen PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-target;${target}>)
67-
68-
# Workaround a cmake bug, see the corresponding function in swift-syntax
69-
function(force_target_link_libraries TARGET)
70-
cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})
71-
72-
foreach(DEPENDENCY ${ARGS_PUBLIC})
73-
target_link_libraries(${TARGET} PRIVATE
74-
${DEPENDENCY}
75-
)
76-
add_dependencies(${TARGET} ${DEPENDENCY})
77-
78-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
79-
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
80-
DEPENDS ${DEPENDENCY}
81-
)
82-
target_sources(${TARGET} PRIVATE
83-
${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
84-
)
85-
endforeach()
86-
endfunction()
87-
88-
# Workaround to touch the library and its objects so that we don't continually rebuild (again, see
89-
# corresponding change in swift-syntax).
90-
add_custom_command(
91-
TARGET swiftASTGen
92-
POST_BUILD
93-
COMMAND "${CMAKE_COMMAND}" -E touch_nocreate $<TARGET_FILE:swiftASTGen> $<TARGET_OBJECTS:swiftASTGen>
94-
COMMAND_EXPAND_LISTS
95-
COMMENT "Update mtime of library outputs workaround")
96-
97-
set(SWIFT_SYNTAX_MODULES
98-
SwiftBasicFormat
99-
SwiftParser
100-
SwiftParserDiagnostics
101-
SwiftDiagnostics
102-
SwiftSyntax
103-
SwiftOperators
104-
SwiftSyntaxBuilder
105-
SwiftSyntaxMacros
106-
)
107-
108-
# Compute the list of SwiftSyntax targets
109-
list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "SwiftSyntax::"
110-
OUTPUT_VARIABLE SWIFT_SYNTAX_TARGETS)
111-
112-
# TODO: Change to target_link_libraries when cmake is fixed
113-
force_target_link_libraries(swiftASTGen PUBLIC
114-
${SWIFT_SYNTAX_TARGETS}
115-
)
116-
target_link_libraries(swiftASTGen PUBLIC
117-
swiftAST
118-
)
119-
120-
set(SWIFT_SYNTAX_LIBRARIES_SOURCE_DIR
121-
"${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host")
122-
set(SWIFT_SYNTAX_LIBRARIES_DEST_DIR
123-
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host")
124-
125-
# Determine the SwiftSyntax shared library files that were built as
126-
# part of earlyswiftsyntax.
127-
list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND ${CMAKE_SHARED_LIBRARY_PREFIX}
128-
OUTPUT_VARIABLE SWIFT_SYNTAX_SHARED_LIBRARIES)
129-
list(TRANSFORM SWIFT_SYNTAX_SHARED_LIBRARIES APPEND
130-
${CMAKE_SHARED_LIBRARY_SUFFIX}
131-
OUTPUT_VARIABLE SWIFT_SYNTAX_SHARED_LIBRARIES)
132-
133-
# Copy over all of the shared libraries from earlyswiftsyntax so they can
134-
# be found via RPATH.
135-
foreach (sharedlib ${SWIFT_SYNTAX_SHARED_LIBRARIES})
136-
add_custom_command(
137-
TARGET swiftASTGen PRE_BUILD
138-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_SYNTAX_LIBRARIES_SOURCE_DIR}/${sharedlib} ${SWIFT_SYNTAX_LIBRARIES_DEST_DIR}/${sharedlib}
139-
COMMENT "Copying ${sharedlib}"
140-
)
141-
endforeach()
142-
143-
# Copy all of the Swift modules from earlyswiftsyntax so they can be found
144-
# in the same relative place within the build directory as in the final
145-
# toolchain.
146-
list(TRANSFORM SWIFT_SYNTAX_MODULES APPEND ".swiftmodule"
147-
OUTPUT_VARIABLE SWIFT_SYNTAX_MODULE_DIRS)
148-
foreach(module_dir ${SWIFT_SYNTAX_MODULE_DIRS})
149-
file(GLOB module_files
150-
"${SWIFT_SYNTAX_LIBRARIES_SOURCE_DIR}/${module_dir}/*.swiftinterface")
151-
add_custom_command(
152-
TARGET swiftASTGen PRE_BUILD
153-
COMMAND ${CMAKE_COMMAND} -E make_directory ${SWIFT_SYNTAX_LIBRARIES_DEST_DIR}/${module_dir}
154-
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${module_files} ${SWIFT_SYNTAX_LIBRARIES_DEST_DIR}/${module_dir}/
155-
COMMENT "Copying ${module_dir}"
156-
)
157-
endforeach()
158-
159-
target_include_directories(swiftASTGen PUBLIC
160-
${SWIFT_SYNTAX_LIBRARIES_DEST_DIR})
161-
162-
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS swiftASTGen)
163-
endif()
1+
add_pure_swift_host_library(swiftASTGen STATIC
2+
Sources/ASTGen/ASTGen.swift
3+
Sources/ASTGen/Decls.swift
4+
Sources/ASTGen/Diagnostics.swift
5+
Sources/ASTGen/Exprs.swift
6+
Sources/ASTGen/Generics.swift
7+
Sources/ASTGen/Literals.swift
8+
Sources/ASTGen/LLVMJSON.swift
9+
Sources/ASTGen/Macros.swift
10+
Sources/ASTGen/Misc.swift
11+
Sources/ASTGen/PluginHost.swift
12+
Sources/ASTGen/PluginMessages.swift
13+
Sources/ASTGen/SourceFile.swift
14+
Sources/ASTGen/SourceManager.swift
15+
Sources/ASTGen/SourceManager+MacroExpansionContext.swift
16+
Sources/ASTGen/Stmts.swift
17+
Sources/ASTGen/Types.swift
18+
19+
DEPENDENCIES swiftAST
20+
)

0 commit comments

Comments
 (0)