Fix iOS GN build and cleanup system_wrappers

Compile fixes for GN on iOS that finally gets our bots green.

Changes to system_wrappers:
* Updated to only use inclusive sources for maintainability
* Add a few missing GN headers.
* Cleanup GYP hack for atomic32_mac.cc
* Renamed changes sources to avoid problems with GYP/GN file
   suffix rules:
  - atomic32_mac.cc -> atomic32_darwin.cc
  - atomic32_posix.cc -> atomic32_non_darwin_unix.cc
See https://code.google.com/p/chromium/codesearch#chromium/src/build/config/BUILDCONFIG.gn&l=325
for details on which extensions can/cannot be used.

BUG=webrtc:5586
NOTRY=True

Review-Url: https://codereview.webrtc.org/1999723002
Cr-Commit-Position: refs/heads/master@{#12897}
diff --git a/webrtc/common_audio/BUILD.gn b/webrtc/common_audio/BUILD.gn
index b01b318..fcf8403 100644
--- a/webrtc/common_audio/BUILD.gn
+++ b/webrtc/common_audio/BUILD.gn
@@ -239,5 +239,11 @@
 
     configs += [ "..:common_config" ]
     public_configs = [ "..:common_inherited_config" ]
+
+    if (is_clang) {
+      # Suppress warnings from Chrome's Clang plugins.
+      # See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
+      configs -= [ "//build/config/clang:find_bad_constructs" ]
+    }
   }
 }
diff --git a/webrtc/modules/audio_device/ios/audio_device_ios.h b/webrtc/modules/audio_device/ios/audio_device_ios.h
index 9616a28..e6b72d6 100644
--- a/webrtc/modules/audio_device/ios/audio_device_ios.h
+++ b/webrtc/modules/audio_device/ios/audio_device_ios.h
@@ -92,7 +92,8 @@
   // See audio_device_not_implemented.cc for trivial implementations.
   int32_t PlayoutBuffer(AudioDeviceModule::BufferType& type,
                         uint16_t& sizeMS) const override;
-  int32_t ActiveAudioLayer(AudioDeviceModule::AudioLayer& audioLayer) const;
+  int32_t ActiveAudioLayer(
+      AudioDeviceModule::AudioLayer& audioLayer) const override;
   int32_t ResetAudioDevice() override;
   int32_t PlayoutIsAvailable(bool& available) override;
   int32_t RecordingIsAvailable(bool& available) override;
diff --git a/webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm b/webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm
index db7f42e..a9d599a 100644
--- a/webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm
+++ b/webrtc/modules/audio_device/ios/voice_processing_audio_unit.mm
@@ -370,10 +370,12 @@
       case kStarted:
         Stop();
         // Fall through.
+        FALLTHROUGH();
       case kInitialized:
         Uninitialize();
         break;
       case kUninitialized:
+        FALLTHROUGH();
       case kInitRequired:
         break;
     }
diff --git a/webrtc/modules/utility/BUILD.gn b/webrtc/modules/utility/BUILD.gn
index 6704cd6..6cd3dbb 100644
--- a/webrtc/modules/utility/BUILD.gn
+++ b/webrtc/modules/utility/BUILD.gn
@@ -24,6 +24,7 @@
     "source/file_recorder_impl.cc",
     "source/file_recorder_impl.h",
     "source/helpers_android.cc",
+    "source/helpers_ios.mm",
     "source/jvm_android.cc",
     "source/process_thread_impl.cc",
     "source/process_thread_impl.h",
diff --git a/webrtc/modules/video_coding/BUILD.gn b/webrtc/modules/video_coding/BUILD.gn
index e0f26f3..c18ae71 100644
--- a/webrtc/modules/video_coding/BUILD.gn
+++ b/webrtc/modules/video_coding/BUILD.gn
@@ -151,6 +151,11 @@
     "../../system_wrappers",
   ]
 
+  if (is_ios) {
+    sources += [ "codecs/h264/h264_objc.mm" ]
+    deps += [ ":webrtc_h264_video_toolbox" ]
+  }
+
   if (rtc_use_h264) {
     defines += [ "WEBRTC_USE_H264" ]
     if (rtc_initialize_ffmpeg) {
@@ -170,8 +175,52 @@
   }
 }
 
-# TODO(tkchin): Source set for webrtc_h264_video_toolbox. Currently not
-# possible to add, see https://crbug.com/297668.
+if (is_ios) {
+  source_set("webrtc_h264_video_toolbox") {
+    sources = [
+      "codecs/h264/h264_video_toolbox_decoder.cc",
+      "codecs/h264/h264_video_toolbox_decoder.h",
+      "codecs/h264/h264_video_toolbox_encoder.cc",
+      "codecs/h264/h264_video_toolbox_encoder.h",
+      "codecs/h264/h264_video_toolbox_nalu.cc",
+      "codecs/h264/h264_video_toolbox_nalu.h",
+    ]
+
+    configs += [ "//build/config/compiler:enable_arc" ]
+
+    cflags = [ "-Wobjc-missing-property-synthesis" ]
+
+    precompiled_header = "../../sdk/objc/WebRTC-Prefix.pch"
+    precompiled_source = "../../sdk/objc/WebRTC-Prefix.pch"
+
+    deps = [
+      "../../sdk:rtc_sdk_common_objc",
+    ]
+
+    libs = [
+      "CoreFoundation.framework",
+      "CoreMedia.framework",
+      "CoreVideo.framework",
+      "VideoToolbox.framework",
+    ]
+
+    if (is_clang) {
+      # Suppress warnings from Chrome's Clang plugins.
+      # See http://code.google.com/p/webrtc/issues/detail?id=163 for details.
+      configs -= [ "//build/config/clang:find_bad_constructs" ]
+    }
+
+    if (rtc_build_libyuv) {
+      deps += [ "$rtc_libyuv_dir" ]
+      public_deps = [
+        "$rtc_libyuv_dir",
+      ]
+    } else {
+      # Need to add a directory normally exported by libyuv.
+      include_dirs += [ "$rtc_libyuv_dir/include" ]
+    }
+  }
+}
 
 source_set("webrtc_i420") {
   sources = [
diff --git a/webrtc/sdk/BUILD.gn b/webrtc/sdk/BUILD.gn
index 91a4c88..fbca40d 100644
--- a/webrtc/sdk/BUILD.gn
+++ b/webrtc/sdk/BUILD.gn
@@ -10,16 +10,22 @@
 import("//build_overrides/webrtc.gni")
 
 if (is_ios) {
+  config("rtc_sdk_common_objc_config") {
+    include_dirs = [
+      "objc/Framework/Classes",
+      "objc/Framework/Headers",
+    ]
+  }
+
   source_set("rtc_sdk_common_objc") {
     deps = [
       "../base:rtc_base",
     ]
     cflags = [ "-fobjc-arc" ]
     configs += [ "..:common_config" ]
-    public_configs = [ "..:common_inherited_config" ]
-    include_dirs = [
-      "objc/Framework/Classes",
-      "objc/Framework/Headers",
+    public_configs = [
+      "..:common_inherited_config",
+      ":rtc_sdk_common_objc_config",
     ]
     sources = [
       "objc/Framework/Classes/NSString+StdString.h",
@@ -54,14 +60,8 @@
       ":rtc_sdk_common_objc",
       #"../../talk/libjingle:libjingle_peerconnection",
     ]
-    cflags = [
-      "-fobjc-arc",
-      "-Wobjc-missing-property-synthesis",
-    ]
-    include_dirs = [
-      "objc/Framework/Classes",
-      "objc/Framework/Headers",
-    ]
+    configs += [ "//build/config/compiler:enable_arc" ]
+    cflags = [ "-Wobjc-missing-property-synthesis" ]
     sources = [
       # Add these when there's a BUILD.gn for peer connection APIs
       #"objc/Framework/Classes/RTCAVFoundationVideoSource+Private.h",
diff --git a/webrtc/system_wrappers/BUILD.gn b/webrtc/system_wrappers/BUILD.gn
index da785e2..435418f 100644
--- a/webrtc/system_wrappers/BUILD.gn
+++ b/webrtc/system_wrappers/BUILD.gn
@@ -27,6 +27,7 @@
     "include/fix_interlocked_exchange_pointer_win.h",
     "include/logging.h",
     "include/metrics.h",
+    "include/ntp_time.h",
     "include/rtp_to_ntp.h",
     "include/rw_lock_wrapper.h",
     "include/sleep.h",
@@ -38,7 +39,6 @@
     "include/trace.h",
     "include/utf_util_win.h",
     "source/aligned_malloc.cc",
-    "source/atomic32_mac.cc",
     "source/atomic32_win.cc",
     "source/clock.cc",
     "source/condition_variable_event_win.cc",
@@ -112,16 +112,13 @@
     libs += [ "rt" ]
   }
 
-  if (!is_mac && !is_ios) {
-    sources += [ "source/atomic32_posix.cc" ]
+  if (is_linux || is_android) {
+    sources += [ "source/atomic32_non_darwin_unix.cc" ]
   }
 
   if (is_ios || is_mac) {
     defines += [ "WEBRTC_THREAD_RR" ]
-  }
-
-  if (is_ios) {
-    sources += [ "source/atomic32_mac.cc" ]
+    sources += [ "source/atomic32_darwin.cc" ]
   }
 
   if (is_win) {
diff --git a/webrtc/system_wrappers/source/atomic32_mac.cc b/webrtc/system_wrappers/source/atomic32_darwin.cc
similarity index 100%
rename from webrtc/system_wrappers/source/atomic32_mac.cc
rename to webrtc/system_wrappers/source/atomic32_darwin.cc
diff --git a/webrtc/system_wrappers/source/atomic32_posix.cc b/webrtc/system_wrappers/source/atomic32_non_darwin_unix.cc
similarity index 100%
rename from webrtc/system_wrappers/source/atomic32_posix.cc
rename to webrtc/system_wrappers/source/atomic32_non_darwin_unix.cc
diff --git a/webrtc/system_wrappers/system_wrappers.gyp b/webrtc/system_wrappers/system_wrappers.gyp
index d46ec82..91ebdd3 100644
--- a/webrtc/system_wrappers/system_wrappers.gyp
+++ b/webrtc/system_wrappers/system_wrappers.gyp
@@ -21,8 +21,8 @@
         'include/aligned_malloc.h',
         'include/atomic32.h',
         'include/clock.h',
-        'include/cpu_info.h',
         'include/cpu_features_wrapper.h',
+        'include/cpu_info.h',
         'include/critical_section_wrapper.h',
         'include/data_log.h',
         'include/data_log_c.h',
@@ -31,7 +31,6 @@
         'include/field_trial.h',
         'include/file_wrapper.h',
         'include/fix_interlocked_exchange_pointer_win.h',
-        'include/logcat_trace_context.h',
         'include/logging.h',
         'include/metrics.h',
         'include/ntp_time.h',
@@ -46,17 +45,13 @@
         'include/trace.h',
         'include/utf_util_win.h',
         'source/aligned_malloc.cc',
-        'source/atomic32_mac.cc',
-        'source/atomic32_posix.cc',
         'source/atomic32_win.cc',
         'source/clock.cc',
         'source/condition_variable_event_win.cc',
         'source/condition_variable_event_win.h',
-        'source/cpu_info.cc',
         'source/cpu_features.cc',
-        'source/data_log.cc',
+        'source/cpu_info.cc',
         'source/data_log_c.cc',
-        'source/data_log_no_op.cc',
         'source/event.cc',
         'source/event_timer_posix.cc',
         'source/event_timer_posix.h',
@@ -64,7 +59,6 @@
         'source/event_timer_win.h',
         'source/file_impl.cc',
         'source/file_impl.h',
-        'source/logcat_trace_context.cc',
         'source/logging.cc',
         'source/rtp_to_ntp.cc',
         'source/rw_lock.cc',
@@ -86,9 +80,9 @@
       ],
       'conditions': [
         ['enable_data_logging==1', {
-          'sources!': [ 'source/data_log_no_op.cc', ],
+          'sources': [ 'source/data_log.cc', ],
         }, {
-          'sources!': [ 'source/data_log.cc', ],
+          'sources': [ 'source/data_log_no_op.cc', ],
         },],
         ['OS=="android"', {
           'defines': [
@@ -110,8 +104,7 @@
               '-llog',
             ],
           },
-        }, {  # OS!="android"
-          'sources!': [
+          'sources': [
             'include/logcat_trace_context.h',
             'source/logcat_trace_context.cc',
           ],
@@ -135,14 +128,19 @@
           'link_settings': {
             'libraries': [ '$(SDKROOT)/System/Library/Frameworks/ApplicationServices.framework', ],
           },
-          'sources!': [
-            'source/atomic32_posix.cc',
+        }],
+        ['OS=="linux" or OS=="android"', {
+          'sources': [
+            'source/atomic32_non_darwin_unix.cc',
           ],
         }],
         ['OS=="ios" or OS=="mac"', {
           'defines': [
             'WEBRTC_THREAD_RR',
           ],
+          'sources': [
+            'source/atomic32_darwin.cc',
+          ],
         }],
         ['OS=="win"', {
           'link_settings': {
@@ -150,20 +148,6 @@
           },
         }],
       ], # conditions
-      'target_conditions': [
-        # We need to do this in a target_conditions block to override the
-        # filename_rules filters.
-        ['OS=="ios"', {
-          # Pull in specific Mac files for iOS (which have been filtered out
-          # by file name rules).
-          'sources/': [
-            ['include', '^source/atomic32_mac\\.'],
-          ],
-          'sources!': [
-            'source/atomic32_posix.cc',
-          ],
-        }],
-      ],
       # Disable warnings to enable Win64 build, issue 1323.
       'msvs_disabled_warnings': [
         4267,  # size_t to int truncation.