Skip to content

Commit 73a1642

Browse files
committed
Build macro as library instead of executable
1 parent a975e76 commit 73a1642

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

Sources/FoundationEssentials/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,9 @@ include(ExternalProject)
2020
ExternalProject_Add(FoundationMacros
2121
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../FoundationMacros"
2222
INSTALL_COMMAND "")
23-
ExternalProject_Get_Property(FoundationMacros BINARY_DIR)
24-
if(CMAKE_HOST_WIN32)
25-
set(FoundationMacrosPath "${BINARY_DIR}/FoundationMacros.exe#FoundationMacros")
26-
else()
27-
set(FoundationMacrosPath "${BINARY_DIR}/FoundationMacros#FoundationMacros")
28-
endif()
29-
3023
add_dependencies(FoundationEssentials FoundationMacros)
3124

25+
3226
if(CMAKE_SYSTEM_NAME STREQUAL Linux OR CMAKE_SYSTEM_NAME STREQUAL Android)
3327
target_compile_options(FoundationEssentials PRIVATE
3428
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -Xcc -Xfrontend -D_GNU_SOURCE>")
@@ -39,7 +33,6 @@ target_compile_options(FoundationEssentials PRIVATE
3933
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend VariadicGenerics>"
4034
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>")
4135
target_compile_options(FoundationEssentials PRIVATE ${_SwiftFoundation_availability_macros})
42-
target_compile_options(FoundationEssentials PRIVATE -load-plugin-executable "${FoundationMacrosPath}")
4336
target_compile_options(FoundationEssentials PRIVATE -package-name "SwiftFoundation")
4437

4538
target_link_libraries(FoundationEssentials PUBLIC

Sources/FoundationMacros/CMakeLists.txt

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,39 @@ endif()
2727
project(FoundationMacros
2828
LANGUAGES Swift)
2929

30+
set(FOUNDATION_MACROS_HOST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host")
31+
set(FOUNDATION_MACROS_PLUGINS_DIR "${FOUNDATION_MACROS_HOST_DIR}/plugins")
32+
3033
file(GLOB_RECURSE _FoundationMacrosSources "*.swift")
31-
add_executable(FoundationMacros ${_FoundationMacrosSources})
34+
add_library(FoundationMacros SHARED ${_FoundationMacrosSources})
35+
36+
set_target_properties(FoundationMacros
37+
PROPERTIES
38+
ARCHIVE_OUTPUT_DIRECTORY "${FOUNDATION_MACROS_PLUGINS_DIR}"
39+
LIBRARY_OUTPUT_DIRECTORY "${FOUNDATION_MACROS_PLUGINS_DIR}"
40+
)
3241

3342
# Dependecies
3443
include(FetchContent)
35-
if (_SwiftSyntax_SourceDIR)
36-
FetchContent_Declare(SwiftSyntax
37-
SOURCE_DIR ${_SwiftSyntax_SourceDIR})
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}")
3848
else()
49+
# If building at desk, check out and link against the SwiftSyntax repo's targets
3950
FetchContent_Declare(SwiftSyntax
4051
GIT_REPOSITORY https://github.com/apple/swift-syntax.git
4152
GIT_TAG 84a4bedfd1294f6ee18e6dc9ad70df55fa6230f6)
53+
FetchContent_MakeAvailable(SwiftSyntax)
54+
55+
target_link_libraries(FoundationMacros
56+
SwiftSyntax
57+
SwiftSyntaxMacros
58+
SwiftCompilerPlugin)
4259
endif()
43-
FetchContent_MakeAvailable(SwiftSyntax)
4460

4561
# Link against SwiftSyntax
4662
target_compile_options(FoundationMacros PRIVATE -parse-as-library)
4763
target_compile_options(FoundationMacros PRIVATE
4864
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>")
49-
target_link_libraries(FoundationMacros
50-
SwiftSyntax
51-
SwiftSyntaxMacros
52-
SwiftCompilerPlugin)
65+

0 commit comments

Comments
 (0)