[ios] Partially decouple iOS and macOS GN configuration.

Duplicates configs defined in //build/config/mac/BUILD.gn that
are shared with iOS to //build/config/ios/BUILD.gn. Remove all
conditions testing "is_mac" or "is_ios" (as they are now known
from the filename).

Change dependencies on previously shared targets to select the
correct target based on the "target_os".

BUG=635745

Review-Url: https://codereview.chromium.org/2843493002
Cr-Original-Commit-Position: refs/heads/master@{#467680}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 1982eef8e01ab5e8ce6aeba827faa54c8e88838a
diff --git a/config/BUILD.gn b/config/BUILD.gn
index 4a34178..5092108 100644
--- a/config/BUILD.gn
+++ b/config/BUILD.gn
@@ -288,7 +288,10 @@
       "//build/config/mac:mac_executable_flags",
     ]
   } else if (is_ios) {
-    configs += [ "//build/config/ios:ios_dynamic_flags" ]
+    configs += [
+      "//build/config/ios:ios_dynamic_flags",
+      "//build/config/ios:ios_executable_flags",
+    ]
   } else if (is_linux || is_android) {
     configs += [ "//build/config/gcc:executable_ldconfig" ]
     if (is_android) {
diff --git a/config/BUILDCONFIG.gn b/config/BUILDCONFIG.gn
index d055e70..9ff1041 100644
--- a/config/BUILDCONFIG.gn
+++ b/config/BUILDCONFIG.gn
@@ -544,7 +544,7 @@
     # that shouldn't use the windows subsystem.
     "//build/config/win:console",
   ]
-} else if (is_mac || is_ios) {
+} else if (is_mac) {
   _linker_configs = [ "//build/config/mac:strip_all" ]
 } else {
   _linker_configs = []
diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn
index f37205e..c2f9aff 100644
--- a/config/compiler/BUILD.gn
+++ b/config/compiler/BUILD.gn
@@ -165,8 +165,10 @@
     configs += [ "//build/config/linux:compiler" ]
   } else if (is_nacl) {
     configs += [ "//build/config/nacl:compiler" ]
-  } else if (is_ios || is_mac) {
+  } else if (is_mac) {
     configs += [ "//build/config/mac:compiler" ]
+  } else if (is_ios) {
+    configs += [ "//build/config/ios:compiler" ]
   }
 
   # See the definitions below.
diff --git a/config/ios/BUILD.gn b/config/ios/BUILD.gn
index ec6b9e6..71f87de 100644
--- a/config/ios/BUILD.gn
+++ b/config/ios/BUILD.gn
@@ -23,6 +23,53 @@
   enable_ios_bitcode = false
 }
 
+# This is included by reference in the //build/config/compiler config that
+# is applied to all targets. It is here to separate out the logic.
+config("compiler") {
+  # These flags are shared between the C compiler and linker.
+  common_ios_flags = []
+
+  # CPU architecture.
+  if (current_cpu == "x64") {
+    common_ios_flags += [
+      "-arch",
+      "x86_64",
+    ]
+  } else if (current_cpu == "x86") {
+    common_ios_flags += [
+      "-arch",
+      "i386",
+    ]
+  } else if (current_cpu == "armv7" || current_cpu == "arm") {
+    common_ios_flags += [
+      "-arch",
+      "armv7",
+    ]
+  } else if (current_cpu == "arm64") {
+    common_ios_flags += [
+      "-arch",
+      "arm64",
+    ]
+  }
+
+  # This is here so that all files get recompiled after an Xcode update.
+  # (defines are passed via the command line, and build system rebuild things
+  # when their commandline changes). Nothing should ever read this define.
+  defines = [ "CR_XCODE_VERSION=$xcode_version" ]
+
+  asmflags = common_ios_flags
+  cflags = common_ios_flags
+
+  # Without this, the constructors and destructors of a C++ object inside
+  # an Objective C struct won't be called, which is very bad.
+  cflags_objcc = [ "-fobjc-call-cxx-cdtors" ]
+
+  cflags_c = [ "-std=c99" ]
+  cflags_objc = cflags_c
+
+  ldflags = common_ios_flags
+}
+
 # This is included by reference in the //build/config/compiler:runtime_library
 # config that is applied to all targets. It is here to separate out the logic
 # that is iOS-only. Please see that target for advice on what should go in
@@ -67,6 +114,9 @@
   }
 }
 
+config("ios_executable_flags") {
+}
+
 config("ios_dynamic_flags") {
   ldflags = [ "-Wl,-ObjC" ]  # Always load Objective-C categories and class.
 }
diff --git a/config/ios/rules.gni b/config/ios/rules.gni
index 2cafb96..5be23dd 100644
--- a/config/ios/rules.gni
+++ b/config/ios/rules.gni
@@ -102,25 +102,11 @@
     }
 
     if (enable_stripping) {
-      # Check whether //build/config/mac:strip_all has been removed from the
-      # configs variables (as this is how stripping is disabled for a single
-      # target).
-      _strip_all_in_config = false
-      if (defined(invoker.configs)) {
-        foreach(_config, invoker.configs) {
-          if (_config == "//build/config/mac:strip_all") {
-            _strip_all_in_config = true
-          }
-        }
-      }
-
-      if (_strip_all_in_config) {
-        args += [ "-Wcrl,strip,-x,-S" ]
-        if (save_unstripped_output) {
-          outputs += [ "$root_out_dir/$_output_name.unstripped" ]
-          args += [ "-Wcrl,unstripped," +
-                    rebase_path("$root_out_dir/.", root_build_dir) ]
-        }
+      args += [ "-Wcrl,strip,-x,-S" ]
+      if (save_unstripped_output) {
+        outputs += [ "$root_out_dir/$_output_name.unstripped" ]
+        args += [ "-Wcrl,unstripped," +
+                  rebase_path("$root_out_dir/.", root_build_dir) ]
       }
     }
   }
diff --git a/config/mac/BUILD.gn b/config/mac/BUILD.gn
index 84180e6..0f7cecc 100644
--- a/config/mac/BUILD.gn
+++ b/config/mac/BUILD.gn
@@ -6,16 +6,8 @@
 import("//build/config/mac/mac_sdk.gni")
 import("//build/config/mac/symbols.gni")
 
-if (is_ios) {
-  # This needs to be imported after mac_sdk.gni as it overrides some of the
-  # variables defined by it.
-  import("//build/config/ios/ios_sdk.gni")
-}
-
 # This is included by reference in the //build/config/compiler config that
 # is applied to all targets. It is here to separate out the logic.
-#
-# This is applied to BOTH desktop Mac and iOS targets.
 config("compiler") {
   # These flags are shared between the C compiler and linker.
   common_mac_flags = []
@@ -31,16 +23,6 @@
       "-arch",
       "i386",
     ]
-  } else if (current_cpu == "armv7" || current_cpu == "arm") {
-    common_mac_flags += [
-      "-arch",
-      "armv7",
-    ]
-  } else if (current_cpu == "arm64") {
-    common_mac_flags += [
-      "-arch",
-      "arm64",
-    ]
   }
 
   # This is here so that all files get recompiled after an Xcode update.
@@ -60,16 +42,7 @@
 
   ldflags = common_mac_flags
 
-  if (is_ios && additional_toolchains != []) {
-    # For fat build, the generation of the dSYM happens after the fat binary has
-    # been created with "lipo" thus the stripping cannot happen at link time but
-    # after running "lipo" too.
-    _save_unstripped_output = false
-  } else {
-    _save_unstripped_output = save_unstripped_output
-  }
-
-  if (_save_unstripped_output) {
+  if (save_unstripped_output) {
     ldflags += [ "-Wcrl,unstripped," + rebase_path(root_out_dir) ]
   }
 }
@@ -89,13 +62,11 @@
   cflags = common_flags
   ldflags = common_flags
 
-  if (is_mac) {
-    # Prevent Mac OS X AssertMacros.h from defining macros that collide
-    # with common names, like 'check', 'require', and 'verify'.
-    # (Included by system header. Also exists on iOS but not included.)
-    # http://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/AssertMacros.h
-    defines = [ "__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0" ]
-  }
+  # Prevent Mac OS X AssertMacros.h (included by system header) from defining
+  # macros that collide with common names, like 'check', 'require', and
+  # 'verify'.
+  # http://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/AssertMacros.h
+  defines = [ "__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0" ]
 }
 
 # On Mac, this is used for everything except static libraries.
@@ -127,10 +98,7 @@
 # from a binary, but some targets may wish to specify a saves file to preserve
 # specific symbols.
 config("strip_all") {
-  # On iOS, the final applications are assembled using lipo (to support fat
-  # builds). This configuration is thus always empty and the correct flags
-  # are passed to the linker_driver.py script directly during the lipo call.
-  if (enable_stripping && !is_ios) {
+  if (enable_stripping) {
     ldflags = [ "-Wcrl,strip,-x,-S" ]
   }
 }