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