File: CMakeLists.txt

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (97 lines) | stat: -rw-r--r-- 3,508 bytes parent folder | download
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
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift open source project
##
## Copyright (c) 2024 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.md for the list of Swift project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##

cmake_minimum_required(VERSION 3.22)

if(POLICY CMP0156)
    # Deduplicate linked libraries where appropriate
    cmake_policy(SET CMP0156 NEW)
endif()
if(POLICY CMP0157)
    # New Swift build model: improved incremental build performance and LSP support
  cmake_policy(SET CMP0157 NEW)
endif()

project(FoundationMacros
  LANGUAGES Swift)

if(NOT SWIFT_SYSTEM_NAME)
  if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
    set(SWIFT_SYSTEM_NAME macosx)
  else()
    set(SWIFT_SYSTEM_NAME "$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
  endif()
endif()

# SwiftSyntax Dependency
find_package(SwiftSyntax QUIET)
if(NOT SwiftSyntax_FOUND)
  message(STATUS "SwiftSyntax_DIR not provided, checking out local copy of swift-syntax")
    include(FetchContent)

    # If building at desk, check out and link against the SwiftSyntax repo's targets
    FetchContent_Declare(SwiftSyntax
        GIT_REPOSITORY https://github.com/swiftlang/swift-syntax.git
        GIT_TAG release/6.1)
    FetchContent_MakeAvailable(SwiftSyntax)
else()
  message(STATUS "SwiftSyntax_DIR provided, using swift-syntax from ${SwiftSyntax_DIR}")
endif()

if(NOT FoundationMacros_BuildLocalExecutable)
    add_library(FoundationMacros SHARED)
    target_compile_definitions(FoundationMacros PRIVATE FOUNDATION_MACROS_LIBRARY)
else()
    add_executable(FoundationMacros)
    target_link_libraries(FoundationMacros PUBLIC
        SwiftSyntax::SwiftCompilerPlugin)
endif()

# Parse the module as a library, even if it's an executable, because it uses an `@main` type to define its entry point.
target_compile_options(FoundationMacros PRIVATE -parse-as-library)

target_sources(FoundationMacros PRIVATE
    FoundationMacros.swift
    PredicateMacro.swift)

target_compile_options(FoundationMacros PRIVATE
    "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend AccessLevelOnImport>"
    "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-experimental-feature -Xfrontend StrictConcurrency>"
    "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend InferSendableFromCaptures>")

target_link_libraries(FoundationMacros PUBLIC
    SwiftSyntax::SwiftSyntax
    SwiftSyntax::SwiftSyntaxMacros
    SwiftSyntax::SwiftDiagnostics
    SwiftSyntax::SwiftSyntaxBuilder
)

set_target_properties(FoundationMacros PROPERTIES
    ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
    PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
    RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin

    INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_BINARY_DIR}/lib

    # The macro is installed into lib/swift/host/plugins, but needs to load
    # libraries from lib/swift/host and lib/swift/${SWIFT_SYSTEM_NAME}
    INSTALL_RPATH "$ORIGIN/../../../swift/${SWIFT_SYSTEM_NAME}:$ORIGIN/.."
    INSTALL_REMOVE_ENVIRONMENT_RPATH ON)

if(NOT FoundationMacros_BuildLocalExecutable)
    install(TARGETS FoundationMacros
        LIBRARY DESTINATION lib/swift/host/plugins
        RUNTIME DESTINATION bin)
endif()