@@ -31,34 +31,37 @@ set(FOUNDATION_MACROS_HOST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host")
31
31
set (FOUNDATION_MACROS_PLUGINS_DIR "${FOUNDATION_MACROS_HOST_DIR} /plugins" )
32
32
33
33
file (GLOB_RECURSE _FoundationMacrosSources "*.swift" )
34
- add_library (FoundationMacros SHARED ${_FoundationMacrosSources} )
35
34
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
43
36
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)
49
39
# If building at desk, check out and link against the SwiftSyntax repo's targets
50
40
FetchContent_Declare(SwiftSyntax
51
41
GIT_REPOSITORY https://github.com/apple /swift-syntax.git
52
42
GIT_TAG 84a4bedfd1294f6ee18e6dc9ad70df55fa6230f6)
53
43
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 )
59
49
endif ()
60
50
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
+
62
65
target_compile_options (FoundationMacros PRIVATE -parse-as-library)
63
66
target_compile_options (FoundationMacros PRIVATE
64
67
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>" )
0 commit comments