File: SwiftCompilerCapability.cmake

package info (click to toggle)
swiftlang 6.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,856,264 kB
  • sloc: cpp: 9,995,718; ansic: 2,234,019; asm: 1,092,167; python: 313,940; objc: 82,726; f90: 80,126; lisp: 38,373; pascal: 25,580; sh: 20,378; ml: 5,058; perl: 4,751; makefile: 4,725; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (82 lines) | stat: -rw-r--r-- 2,799 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
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift.org open source project
##
## Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
## See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
##
##===----------------------------------------------------------------------===##

# Test if the Swift compiler returns success for supplied compiler arguments....
function(swift_supports_compiler_arguments out_var)
  file(WRITE "${CMAKE_BINARY_DIR}/tmp/dummy.swift" "")
  execute_process(
    COMMAND "${CMAKE_Swift_COMPILER}" -parse ${ARGN} -
    INPUT_FILE "${CMAKE_BINARY_DIR}/tmp/dummy.swift"
    OUTPUT_QUIET ERROR_QUIET
    RESULT_VARIABLE result
  )
  if(NOT result)
    set("${out_var}" "TRUE" PARENT_SCOPE)
  else()
    set("${out_var}" "FALSE" PARENT_SCOPE)
  endif()
endfunction()

# Test if the Swift compiler supports -disable-implicit-<module>-module-import.
macro(swift_supports_implicit_module module_name out_var)
  swift_supports_compiler_arguments(${out_var}
    -Xfrontend -disable-implicit-${module_name}-module-import
  )
endmacro()

function(swift_get_swiftlang_version out_var)
  execute_process(
    COMMAND "${CMAKE_Swift_COMPILER}" -version
    OUTPUT_VARIABLE output ERROR_VARIABLE output
    RESULT_VARIABLE result
    TIMEOUT 10
  )

  if(output MATCHES [[swiftlang-([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)]])
    set("${out_var}" "${CMAKE_MATCH_1}" PARENT_SCOPE)
  endif()
endfunction()

# Get "package cross-module-optimization" compiler arguments suitable for the compiler.
function(swift_get_package_cmo_support out_var)
  # > 6.0 : Fixed feature.
  swift_supports_compiler_arguments(result
    -package-name my-package
    -enable-library-evolution
    -Xfrontend -package-cmo
    -Xfrontend -allow-non-resilient-access
  )
  if(result)
    set(${out_var} IMPLEMENTED PARENT_SCOPE)
    return()
  endif()

  # == 6.0 : Experimental.
  swift_supports_compiler_arguments(result
    -package-name my-package
    -Xfrontend -experimental-package-cmo
    -Xfrontend -experimental-allow-non-resilient-access
    -Xfrontend -experimental-package-bypass-resilience
  )
  if(result)
    # Package CMO is implmented in Xcode 16 Beta 4 (swiftlang-6.0.0.6.8) or later.
    # Consider it's not supported in non Xcode toolchain with "-experimental" options.
    swift_get_swiftlang_version(swiftlang_version)
    if(swiftlang_version AND swiftlang_version VERSION_GREATER_EQUAL 6.0.0.6)
      set(${out_var} EXPERIMENTAL PARENT_SCOPE)
      return()
    endif()
  endif()

  # < 6.0 : Not supported.
  set(${out_var} NO PARENT_SCOPE)
endfunction()