@@ -27,26 +27,39 @@ endif()
27
27
project (FoundationMacros
28
28
LANGUAGES Swift)
29
29
30
+ set (FOUNDATION_MACROS_HOST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY} /swift/host" )
31
+ set (FOUNDATION_MACROS_PLUGINS_DIR "${FOUNDATION_MACROS_HOST_DIR} /plugins" )
32
+
30
33
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
+ )
32
41
33
42
# Dependecies
34
43
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} " )
38
48
else ()
49
+ # If building at desk, check out and link against the SwiftSyntax repo's targets
39
50
FetchContent_Declare(SwiftSyntax
40
51
GIT_REPOSITORY https://github.com/apple /swift-syntax.git
41
52
GIT_TAG 84a4bedfd1294f6ee18e6dc9ad70df55fa6230f6)
53
+ FetchContent_MakeAvailable(SwiftSyntax)
54
+
55
+ target_link_libraries (FoundationMacros
56
+ SwiftSyntax
57
+ SwiftSyntaxMacros
58
+ SwiftCompilerPlugin)
42
59
endif ()
43
- FetchContent_MakeAvailable(SwiftSyntax)
44
60
45
61
# Link against SwiftSyntax
46
62
target_compile_options (FoundationMacros PRIVATE -parse-as-library)
47
63
target_compile_options (FoundationMacros PRIVATE
48
64
"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