@@ -29,6 +29,7 @@ project(FoundationMacros
29
29
# SwiftSyntax Dependency
30
30
find_package (SwiftSyntax QUIET )
31
31
if (NOT SwiftSyntax_FOUND )
32
+ message (STATUS "SwiftSyntax_DIR not provided, checking out local copy of swift-syntax" )
32
33
include (FetchContent )
33
34
34
35
# If building at desk, check out and link against the SwiftSyntax repo's targets
@@ -37,16 +38,25 @@ if(NOT SwiftSyntax_FOUND)
37
38
GIT_TAG 4c6cc0a3b9e8f14b3ae2307c5ccae4de6167ac2c ) # 600.0.0-prerelease-2024-06-12
38
39
FetchContent_MakeAvailable (SwiftSyntax )
39
40
else ()
40
- message (STATUS "Using swift-syntax from ${SwiftSyntax_DIR} " )
41
+ message (STATUS "SwiftSyntax_DIR provided, using swift-syntax from ${SwiftSyntax_DIR} " )
41
42
endif ()
42
43
43
- add_library (FoundationMacros SHARED
44
+ if (NOT FoundationMacros_BuildLocalExecutable )
45
+ add_library (FoundationMacros SHARED )
46
+ target_compile_definitions (FoundationMacros PRIVATE FOUNDATION_MACROS_LIBRARY )
47
+ else ()
48
+ add_executable (FoundationMacros )
49
+ target_link_libraries (FoundationMacros PUBLIC
50
+ SwiftSyntax::SwiftCompilerPlugin )
51
+ endif ()
52
+
53
+ # Parse the module as a library, even if it's an executable, because it uses an `@main` type to define its entry point.
54
+ target_compile_options (FoundationMacros PRIVATE -parse-as-library )
55
+
56
+ target_sources (FoundationMacros PRIVATE
44
57
FoundationMacros.swift
45
58
PredicateMacro.swift )
46
59
47
- target_compile_definitions (FoundationMacros PRIVATE FOUNDATION_MACROS_LIBRARY )
48
-
49
- target_compile_options (FoundationMacros PRIVATE -parse-as-library )
50
60
target_compile_options (FoundationMacros PRIVATE
51
61
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>"
52
62
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend StrictConcurrency>"
@@ -72,6 +82,8 @@ set_target_properties(FoundationMacros PROPERTIES
72
82
INSTALL_RPATH "$ORIGIN/../../../swift/${SWIFT_SYSTEM_NAME} :$ORIGIN/.."
73
83
INSTALL_REMOVE_ENVIRONMENT_RPATH ON )
74
84
75
- install (TARGETS FoundationMacros
76
- LIBRARY DESTINATION lib/swift/host/plugins
77
- RUNTIME DESTINATION bin )
85
+ if (NOT FoundationMacros_BuildLocalExecutable )
86
+ install (TARGETS FoundationMacros
87
+ LIBRARY DESTINATION lib/swift/host/plugins
88
+ RUNTIME DESTINATION bin )
89
+ endif ()
0 commit comments