1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2024 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
cmake_minimum_required(VERSION 3.19.6...3.29)
if(POLICY CMP0157)
cmake_policy(SET CMP0157 NEW)
endif()
project(TestingMacros
LANGUAGES Swift)
list(APPEND CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/../../cmake/modules/shared)
if(WIN32)
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
find_package(SwiftSyntax CONFIG GLOBAL)
if(SwiftTesting_BuildMacrosAsExecutables)
# When building the macro plugin as an executable, clone and build
# swift-syntax.
include(FetchContent)
set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/_d)
FetchContent_Declare(SwiftSyntax
GIT_REPOSITORY https://github.com/swiftlang/swift-syntax
GIT_TAG cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25) # 600.0.0
FetchContent_MakeAvailable(SwiftSyntax)
endif()
# Include these modules _after_ swift-syntax is declared above, but _before_ the
# macro plugin target is declared below, so that its settings are not applied to
# the former but are applied to the latter.
include(AvailabilityDefinitions)
include(CompilerSettings)
if(SwiftTesting_BuildMacrosAsExecutables)
# When swift-syntax is built locally, the macro plugin must be built as an
# executable.
add_executable(TestingMacros)
set_target_properties(TestingMacros PROPERTIES
ENABLE_EXPORTS TRUE)
# Parse the module as a library, even though it's an executable, because it
# uses an `@main` type to define its entry point.
target_compile_options(TestingMacros PRIVATE -parse-as-library)
# Include the .swift file which contains its `@main` entry point type.
target_compile_definitions(TestingMacros PRIVATE SWT_NO_LIBRARY_MACRO_PLUGINS)
else()
add_library(TestingMacros SHARED)
target_link_options(TestingMacros PRIVATE "-no-toolchain-stdlib-rpath")
set_property(TARGET TestingMacros PROPERTY BUILD_WITH_INSTALL_RPATH YES)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(plugin_destination_dir "lib/swift/host/plugins/testing")
set_property(TARGET TestingMacros PROPERTY INSTALL_RPATH)
else()
set(plugin_destination_dir "lib/swift/host/plugins")
# RPATH 'lib/swift/{system}' and 'lib/swift/host'
set_property(TARGET TestingMacros PROPERTY
INSTALL_RPATH "$ORIGIN/../../$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>;$ORIGIN/..")
endif()
install(TARGETS TestingMacros
LIBRARY DESTINATION "${plugin_destination_dir}"
RUNTIME DESTINATION bin)
endif()
target_sources(TestingMacros PRIVATE
ConditionMacro.swift
SourceLocationMacro.swift
SuiteDeclarationMacro.swift
Support/Additions/DeclGroupSyntaxAdditions.swift
Support/Additions/EditorPlaceholderExprSyntaxAdditions.swift
Support/Additions/FunctionDeclSyntaxAdditions.swift
Support/Additions/MacroExpansionContextAdditions.swift
Support/Additions/TokenSyntaxAdditions.swift
Support/Additions/TriviaPieceAdditions.swift
Support/Additions/TypeSyntaxProtocolAdditions.swift
Support/Additions/VersionTupleSyntaxAdditions.swift
Support/Additions/WithAttributesSyntaxAdditions.swift
Support/Argument.swift
Support/AttributeDiscovery.swift
Support/AvailabilityGuards.swift
Support/CommentParsing.swift
Support/ConditionArgumentParsing.swift
Support/CRC32.swift
Support/DiagnosticMessage.swift
Support/DiagnosticMessage+Diagnosing.swift
Support/SourceCodeCapturing.swift
Support/SourceLocationGeneration.swift
TagMacro.swift
TestDeclarationMacro.swift
TestingMacrosMain.swift)
target_compile_options(TestingMacros PRIVATE
"SHELL:-Xfrontend -disable-implicit-string-processing-module-import"
"SHELL:-Xfrontend -disable-implicit-backtracing-module-import")
target_link_libraries(TestingMacros PRIVATE
SwiftSyntax::SwiftSyntax
SwiftSyntax::SwiftSyntaxMacroExpansion
SwiftSyntax::SwiftSyntaxMacros)
if(SwiftTesting_BuildMacrosAsExecutables)
# Link the 'SwiftCompilerPlugin' target, but only when built as an executable.
target_link_libraries(TestingMacros PRIVATE
SwiftSyntax::SwiftCompilerPlugin)
endif()
|