• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2024 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("$build_root/config/mac/mac_sdk.gni")
15import("$build_root/config/mac/symbols.gni")
16import("$build_root/config/sysroot.gni")
17
18# This is included by reference in the //build/config/compiler config that
19# is applied to all targets. It is here to separate out the logic.
20config("compiler") {
21  # These flags are shared between the C compiler and linker.
22  common_mac_flags = []
23
24  # CPU architecture.
25  if (current_cpu == "x64") {
26    common_mac_flags += [
27      "-arch",
28      "x86_64",
29    ]
30  } else if (current_cpu == "x86") {
31    common_mac_flags += [
32      "-arch",
33      "i386",
34    ]
35  }
36
37  # This is here so that all files get recompiled after an Xcode update.
38  # (defines are passed via the command line, and build system rebuild things
39  # when their commandline changes). Nothing should ever read this define.
40  defines = [ "CR_XCODE_VERSION=$xcode_version" ]
41
42  defines += [
43    "_LIBCPP_CONFIG_SITE",
44    "_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT=0",
45  ]
46
47  asmflags = common_mac_flags
48  cflags = common_mac_flags
49
50  # Without this, the constructors and destructors of a C++ object inside
51  # an Objective C struct won't be called, which is very bad.
52  cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]
53
54  ldflags = common_mac_flags
55
56  # Create a new read-only segment for protected memory. The default segments
57  # (__TEXT and __DATA) are mapped read-execute and read-write by default.
58  ldflags += [
59    "-segprot",
60    "PROTECTED_MEMORY",
61    "rw",
62    "r",
63  ]
64
65  if (save_unstripped_output) {
66    ldflags += [ "-Wcrl,unstripped," + rebase_path(root_out_dir) ]
67  }
68}
69
70# This is included by reference in the //build/config/compiler:runtime_library
71# config that is applied to all targets. It is here to separate out the logic
72# that is Mac-only. Please see that target for advice on what should go in
73# :runtime_library vs. :compiler.
74config("runtime_config") {
75  common_flags = [
76    "-isysroot",
77    sysroot,
78    "-mmacosx-version-min=$mac_deployment_target",
79  ]
80
81  asmflags = common_flags
82  cflags = common_flags
83  ldflags = common_flags
84  framework_dirs = [ sysroot ]
85
86  # Prevent Mac OS X AssertMacros.h (included by system header) from defining
87  # macros that collide with common names, like 'check', 'require', and
88  # 'verify'.
89  # http://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/AssertMacros.h
90  defines = [ "__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0" ]
91}
92
93# On Mac, this is used for everything except static libraries.
94config("mac_dynamic_flags") {
95  ldflags = [ "-Wl,-ObjC" ]  # Always load Objective-C categories and classes.
96
97  if (is_component_build) {
98    ldflags += [
99      # Path for loading shared libraries for unbundled binaries.
100      "-Wl,-rpath,@loader_path/.",
101
102      # Path for loading shared libraries for bundled binaries. Get back from
103      # Binary.app/Contents/MacOS.
104      "-Wl,-rpath,@loader_path/../../..",
105    ]
106  }
107}
108
109# The ldflags referenced below are handled by
110# //build/toolchain/mac/linker_driver.py.
111# Remove this config if a target wishes to change the arguments passed to the
112# strip command during linking. This config by default strips all symbols
113# from a binary, but some targets may wish to specify an exports file to
114# preserve specific symbols.
115config("strip_all") {
116  if (enable_stripping) {
117    ldflags = [ "-Wcrl,strip,-x,-S" ]
118  }
119}
120