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