File: macCatalystUtils.cmake

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (114 lines) | stat: -rw-r--r-- 3,693 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# macCatalystUtils.cmake
#
# Utility functions for macCatalyst support in Swift.


# Include guard
if(MACCATALYST_UTILS_INCLUDED)
  return()
endif()

set(MACCATALYST_UTILS_INCLUDED TRUE)


# -----------------------------------------------------------------------------

# List of all valid macCatalyst build flavors
set(MACCATALYST_BUILD_FLAVORS "ios-like" "macos-like" "zippered" "unzippered-twin")


# Sets out_var with the macCatalyst build flavor if macCatalyst is enabled and building
# for the OSX sdk.
function(get_maccatalyst_build_flavor out_var sdk flavor)
  if(SWIFT_ENABLE_MACCATALYST AND sdk STREQUAL "OSX")
    if(flavor IN_LIST MACCATALYST_BUILD_FLAVORS)
      set("${out_var}" "${flavor}" PARENT_SCOPE)
    elseif(NOT flavor STREQUAL "")
      message(FATAL_ERROR "Invalid MACCATALYST_BUILD_FLAVOR: ${flavor}")
    else()
      # Unset the variable to indicate the absence of a build flavor
      unset("${out_var}" PARENT_SCOPE)
    endif()
  else()
    # Unset the variable to indicate macCatalyst is not enabled
    unset("${out_var}" PARENT_SCOPE)
  endif()
endfunction()

# Form a versioned target triple for the given SDK.
function(get_versioned_target_triple target_out_var sdk arch version)
  if (SWIFT_SDK_${sdk}_IS_SIMULATOR)
    # The version goes before the "-simulator".
    set(target "${SWIFT_SDK_${sdk}_ARCH_${arch}_TRIPLE}")
    string(REPLACE "-simulator" "" target "${target}")
    set(target "${target}${version}-simulator")
  else ()
    set(target "${SWIFT_SDK_${sdk}_ARCH_${arch}_TRIPLE}${version}")
  endif()

  set(${target_out_var} "${target}" PARENT_SCOPE)
endfunction()

# Sets target_out_var to the target triple for the given SDK and maccatalyst flavor.
# For zippered flavors also sets the target_variant_out_var. For other
# flavors the target_variant_out_var is unset, causing it to be undefined.
function(get_target_triple target_out_var target_variant_out_var sdk arch)
  # parse args
  set(option_args)
  set(single_value_args MACCATALYST_BUILD_FLAVOR DEPLOYMENT_VERSION)
  set(multi_value_args)
  cmake_parse_arguments(TARGET
    "${option_args}"
    "${single_value_args}"
    "${multi_value_args}"
    ${ARGN})

  set(deployment_version "${TARGET_DEPLOYMENT_VERSION}")

  # Default target triple
  get_versioned_target_triple(target ${sdk} ${arch} "${deployment_version}")

  set(target_variant)

  get_maccatalyst_build_flavor(maccatalyst_build_flavor
    "${sdk}" "${TARGET_MACCATALYST_BUILD_FLAVOR}")

  if(maccatalyst_build_flavor STREQUAL "ios-like")
    set(target "${arch}-apple-ios${SWIFT_DARWIN_DEPLOYMENT_VERSION_MACCATALYST}-macabi")
  elseif(maccatalyst_build_flavor STREQUAL "macos-like")
    # Use the default macOS triple.
  elseif(maccatalyst_build_flavor STREQUAL "zippered")
    set(target "${arch}-apple-macosx${SWIFT_DARWIN_DEPLOYMENT_VERSION_OSX}")
    set(target_variant "${arch}-apple-ios${SWIFT_DARWIN_DEPLOYMENT_VERSION_MACCATALYST}-macabi")
  elseif(maccatalyst_build_flavor STREQUAL "unzippered-twin")
    # Use the default triple for now
  endif()

  set(${target_out_var} "${target}" PARENT_SCOPE)
  set(${target_variant_out_var} "${target_variant}" PARENT_SCOPE)
endfunction()


# Removes all instances of `-${flag} <arg>` from an input list of flags
function(remove_given_flag flags_var flag_name)
  set(output_flags)

  set(seen_flag FALSE)
  foreach(flag ${${flags_var}})
    # Skip flag argument
    if(seen_flag)
      set(seen_flag FALSE)
      continue()
    endif()

    # Skip flag
    if(flag STREQUAL "-${flag_name}")
      set(seen_flag TRUE)
      continue()
    endif()

    list(APPEND output_flags "${flag}")
  endforeach()

  set("${flags_var}" "${output_flags}" PARENT_SCOPE)
endfunction()