@@ -29,6 +29,7 @@ project(FoundationMacros
2929# SwiftSyntax Dependency
3030find_package (SwiftSyntax QUIET )
3131if (NOT SwiftSyntax_FOUND)
32+ message (STATUS "SwiftSyntax_DIR not provided, checking out local copy of swift-syntax" )
3233 include (FetchContent)
3334
3435 # If building at desk, check out and link against the SwiftSyntax repo's targets
@@ -37,16 +38,25 @@ if(NOT SwiftSyntax_FOUND)
3738 GIT_TAG 4c6cc0a3b9e8f14b3ae2307c5ccae4de6167ac2c) # 600.0.0-prerelease-2024-06-12
3839 FetchContent_MakeAvailable(SwiftSyntax)
3940else ()
40- message (STATUS "Using swift-syntax from ${SwiftSyntax_DIR} " )
41+ message (STATUS "SwiftSyntax_DIR provided, using swift-syntax from ${SwiftSyntax_DIR} " )
4142endif ()
4243
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
4457 FoundationMacros.swift
4558 PredicateMacro.swift)
4659
47- target_compile_definitions (FoundationMacros PRIVATE FOUNDATION_MACROS_LIBRARY)
48-
49- target_compile_options (FoundationMacros PRIVATE -parse-as-library)
5060target_compile_options (FoundationMacros PRIVATE
5161 "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>"
5262 "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend StrictConcurrency>"
@@ -72,6 +82,8 @@ set_target_properties(FoundationMacros PROPERTIES
7282 INSTALL_RPATH "$ORIGIN/../../../swift/${SWIFT_SYSTEM_NAME} :$ORIGIN/.."
7383 INSTALL_REMOVE_ENVIRONMENT_RPATH ON )
7484
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