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