Skip to content

Commit c467797

Browse files
jmschonfeldiCharlesHu
authored andcommitted
Update FoundationMacros cmake build to link against the right SwiftSyntax
1 parent 4bfc548 commit c467797

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

Sources/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@
1313
##===----------------------------------------------------------------------===##
1414

1515
add_subdirectory(_CShims)
16+
add_subdirectory(FoundationMacros)
1617
add_subdirectory(FoundationEssentials)
1718
add_subdirectory(FoundationInternationalization)

Sources/FoundationEssentials/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@
1515
file(GLOB_RECURSE _FoundationEssentialsSources "*.swift")
1616
add_library(FoundationEssentials SHARED ${_FoundationEssentialsSources})
1717

18-
# Configure FoundationMacros
19-
include(ExternalProject)
20-
ExternalProject_Add(FoundationMacros
21-
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../FoundationMacros"
22-
INSTALL_COMMAND "")
18+
# Depend on FoundationMacros
2319
add_dependencies(FoundationEssentials FoundationMacros)
2420

21+
if(FOUNDATION_MACROS_BUILD_AS_EXECUTABLE)
22+
if(CMAKE_HOST_WIN32)
23+
set(FoundationMacrosPath "${CMAKE_BINARY_DIR}/FoundationMacros.exe#FoundationMacros")
24+
else()
25+
set(FoundationMacrosPath "${CMAKE_BINARY_DIR}/FoundationMacros#FoundationMacros")
26+
endif()
27+
target_compile_options(FoundationEssentials PRIVATE -load-plugin-executable "${FoundationMacrosPath}")
28+
endif()
2529

2630
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android)
2731
target_compile_options(FoundationEssentials PRIVATE

Sources/FoundationMacros/CMakeLists.txt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,37 @@ set(FOUNDATION_MACROS_HOST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host")
3131
set(FOUNDATION_MACROS_PLUGINS_DIR "${FOUNDATION_MACROS_HOST_DIR}/plugins")
3232

3333
file(GLOB_RECURSE _FoundationMacrosSources "*.swift")
34-
add_library(FoundationMacros SHARED ${_FoundationMacrosSources})
3534

36-
set_target_properties(FoundationMacros
37-
PROPERTIES
38-
ARCHIVE_OUTPUT_DIRECTORY "${FOUNDATION_MACROS_PLUGINS_DIR}"
39-
LIBRARY_OUTPUT_DIRECTORY "${FOUNDATION_MACROS_PLUGINS_DIR}"
40-
)
41-
42-
# Dependecies
35+
# SwiftSyntax Dependency
4336
include(FetchContent)
44-
if (SWIFT_BUILD_SWIFT_SYNTAX)
45-
# If building in the toolchain, link against the already-built SwiftSyntax
46-
target_include_directories(FoundationMacros PUBLIC "${SWIFT_HOST_LIBRARIES_DEST_DIR}")
47-
target_link_directories(FoundationMacros PUBLIC "${SWIFT_HOST_LIBRARIES_DEST_DIR}")
48-
else()
37+
find_package(SwiftSyntax)
38+
if(NOT SwiftSyntax_FOUND)
4939
# If building at desk, check out and link against the SwiftSyntax repo's targets
5040
FetchContent_Declare(SwiftSyntax
5141
GIT_REPOSITORY https://github.com/apple/swift-syntax.git
5242
GIT_TAG 84a4bedfd1294f6ee18e6dc9ad70df55fa6230f6)
5343
FetchContent_MakeAvailable(SwiftSyntax)
54-
55-
target_link_libraries(FoundationMacros
56-
SwiftSyntax
57-
SwiftSyntaxMacros
58-
SwiftCompilerPlugin)
44+
add_executable(FoundationMacros ${_FoundationMacrosSources})
45+
set(FOUNDATION_MACROS_BUILD_AS_EXECUTABLE YES)
46+
else()
47+
add_library(FoundationMacros SHARED ${_FoundationMacrosSources})
48+
target_compile_definitions(FoundationMacros PRIVATE FOUNDATION_MACROS_LIBRARY)
5949
endif()
6050

61-
# Link against SwiftSyntax
51+
set_target_properties(FoundationMacros
52+
PROPERTIES
53+
ARCHIVE_OUTPUT_DIRECTORY "${FOUNDATION_MACROS_PLUGINS_DIR}"
54+
LIBRARY_OUTPUT_DIRECTORY "${FOUNDATION_MACROS_PLUGINS_DIR}"
55+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}
56+
)
57+
58+
target_link_libraries(FoundationMacros
59+
SwiftSyntax::SwiftSyntax
60+
SwiftSyntax::SwiftSyntaxMacros
61+
SwiftSyntax::SwiftDiagnostics
62+
SwiftSyntax::SwiftSyntaxBuilder
63+
)
64+
6265
target_compile_options(FoundationMacros PRIVATE -parse-as-library)
6366
target_compile_options(FoundationMacros PRIVATE
6467
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>")

Sources/FoundationMacros/FoundationMacros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if !FOUNDATION_FRAMEWORK
13+
#if !FOUNDATION_FRAMEWORK && !FOUNDATION_MACROS_LIBRARY
1414

1515
import SwiftSyntaxMacros
1616
import SwiftCompilerPlugin

0 commit comments

Comments
 (0)