1# Copyright 2014 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import("//build/config/ios/ios_sdk.gni")
6import("//build/config/sysroot.gni")
7import("//build/toolchain/toolchain.gni")
8
9declare_args() {
10  # Enabling this option makes clang compile to an intermediate
11  # representation ("bitcode"), and not to native code. This is preferred
12  # when including WebRTC in the apps that will be sent to Apple's App Store
13  # and mandatory for the apps that run on watchOS or tvOS.
14  # The option only works when building with Xcode (use_xcode_clang = true).
15  # Mimicking how Xcode handles it, the production builds (is_debug = false)
16  # get real bitcode sections added, while the debug builds (is_debug = true)
17  # only get bitcode-section "markers" added in them.
18  # NOTE: This option is ignored when building versions for the iOS simulator,
19  # where a part of libvpx is compiled from the assembly code written using
20  # Intel assembly syntax; Yasm / Nasm do not support emitting bitcode parts.
21  # That is not a limitation for now as Xcode mandates the presence of bitcode
22  # only when building bitcode-enabled projects for real devices (ARM CPUs).
23  enable_ios_bitcode = false
24}
25
26# This is included by reference in the //build/config/compiler config that
27# is applied to all targets. It is here to separate out the logic.
28config("compiler") {
29  # These flags are shared between the C compiler and linker.
30  common_ios_flags = []
31
32  # CPU architecture.
33  if (current_cpu == "x64") {
34    common_ios_flags += [
35      "-arch",
36      "x86_64",
37    ]
38  } else if (current_cpu == "x86") {
39    common_ios_flags += [
40      "-arch",
41      "i386",
42    ]
43  } else if (current_cpu == "armv7" || current_cpu == "arm") {
44    common_ios_flags += [
45      "-arch",
46      "armv7",
47    ]
48  } else if (current_cpu == "arm64") {
49    common_ios_flags += [
50      "-arch",
51      "arm64",
52    ]
53  }
54
55  # This is here so that all files get recompiled after an Xcode update.
56  # (defines are passed via the command line, and build system rebuild things
57  # when their commandline changes). Nothing should ever read this define.
58  defines = [ "CR_XCODE_VERSION=$xcode_version" ]
59
60  asmflags = common_ios_flags
61  cflags = common_ios_flags
62
63  # Without this, the constructors and destructors of a C++ object inside
64  # an Objective C struct won't be called, which is very bad.
65  cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]
66
67  cflags_c = [ "-std=c99" ]
68  cflags_objc = cflags_c
69
70  ldflags = common_ios_flags
71}
72
73# This is included by reference in the //build/config/compiler:runtime_library
74# config that is applied to all targets. It is here to separate out the logic
75# that is iOS-only. Please see that target for advice on what should go in
76# :runtime_library vs. :compiler.
77config("runtime_library") {
78  common_flags = [
79    "-isysroot",
80    sysroot,
81
82    "-stdlib=libc++",
83  ]
84
85  if (use_ios_simulator) {
86    common_flags += [ "-mios-simulator-version-min=$ios_deployment_target" ]
87  } else {
88    common_flags += [ "-miphoneos-version-min=$ios_deployment_target" ]
89  }
90
91  if (use_xcode_clang && enable_ios_bitcode && !use_ios_simulator) {
92    if (is_debug) {
93      common_flags += [ "-fembed-bitcode-marker" ]
94    } else {
95      common_flags += [ "-fembed-bitcode" ]
96    }
97  }
98
99  asmflags = common_flags
100  cflags = common_flags
101  ldflags = common_flags
102
103  # TODO(crbug.com/634373): Remove once Xcode's libc++ has LLVM r256325. Most
104  # likely this means one Xcode 8 is released and required.
105  if (use_xcode_clang && get_path_info(ios_sdk_version, "name") != "10") {
106    common_cc_flags = [
107      "-isystem",
108      rebase_path("//third_party/llvm-build/Release+Asserts/include/c++/v1",
109                  root_build_dir),
110    ]
111
112    cflags_cc = common_cc_flags
113    cflags_objcc = common_cc_flags
114  }
115
116  if (ios_enable_coverage) {
117    configs = [ ":enable_coverage" ]
118  }
119}
120
121config("ios_executable_flags") {
122}
123
124config("ios_dynamic_flags") {
125  ldflags = [ "-Wl,-ObjC" ]  # Always load Objective-C categories and class.
126}
127
128config("xctest_config") {
129  common_flags = [
130    "-F",
131    "$ios_sdk_platform_path/Developer/Library/Frameworks",
132  ]
133
134  cflags = common_flags
135  ldflags = common_flags
136
137  libs = [
138    "Foundation.framework",
139    "XCTest.framework",
140  ]
141}
142
143# This enables support for LLVM code coverage. See
144# http://llvm.org/docs/CoverageMappingFormat.html.
145config("enable_coverage") {
146  cflags = [
147    "-fprofile-instr-generate",
148    "-fcoverage-mapping",
149  ]
150  ldflags = [ "-fprofile-instr-generate" ]
151}
152
153group("xctest") {
154  public_configs = [ ":xctest_config" ]
155}
156