GYP variables for building expat, icu, libsrtp, usrsctp

This makes the build more flexible when linking against
prebuilt external libraries.

Use existing build_* variables for libyuv and json in talk/
(already in use in webrtc/).

Also make it possible to avoid building the GTK parts of the Linux build.

BUG=4242
R=andrew@webrtc.org, tommi@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/44179005

Cr-Commit-Position: refs/heads/master@{#9087}
diff --git a/talk/app/webrtc/java/jni/jni_helpers.cc b/talk/app/webrtc/java/jni/jni_helpers.cc
index 5ce9926..32d17a1 100644
--- a/talk/app/webrtc/java/jni/jni_helpers.cc
+++ b/talk/app/webrtc/java/jni/jni_helpers.cc
@@ -103,7 +103,7 @@
 // Return thread ID as a string.
 static std::string GetThreadId() {
   char buf[21];  // Big enough to hold a kuint64max plus terminating NULL.
-  CHECK_LT(snprintf(buf, sizeof(buf), "%llu", syscall(__NR_gettid)),
+  CHECK_LT(snprintf(buf, sizeof(buf), "%ld", syscall(__NR_gettid)),
            sizeof(buf))
       << "Thread id is bigger than uint64??";
   return std::string(buf);
diff --git a/talk/build/common.gypi b/talk/build/common.gypi
index 2d6fca0..4735bc8 100644
--- a/talk/build/common.gypi
+++ b/talk/build/common.gypi
@@ -40,6 +40,18 @@
         'java_home%': '<!(python -c "import os; dir=os.getenv(\'JAVA_HOME\', \'/usr/lib/jvm/java-7-openjdk-amd64\'); assert os.path.exists(os.path.join(dir, \'include/jni.h\')), \'Point \\$JAVA_HOME or the java_home gyp variable to a directory containing include/jni.h!\'; print dir")',
       }],
     ],
+    # Disable these to not build components which can be externally provided.
+    'build_expat%': 1,
+    'build_icu%': 1,
+    'build_json%': 1,
+    'build_libsrtp%': 1,
+    'build_libyuv%': 1,
+    'build_usrsctp%': 1,
+    # Make it possible to provide custom locations for some libraries.
+    'libyuv_dir%': '<(DEPTH)/third_party/libyuv',
+
+    # Disable this to skip building source requiring GTK.
+    'use_gtk%': 1,
   },
   'target_defaults': {
     'include_dirs': [
diff --git a/talk/libjingle.gyp b/talk/libjingle.gyp
index 37cbf6b..c86d8f0 100755
--- a/talk/libjingle.gyp
+++ b/talk/libjingle.gyp
@@ -47,7 +47,6 @@
           'type': 'shared_library',
           'dependencies': [
             'libjingle_peerconnection',
-            '<(DEPTH)/third_party/icu/icu.gyp:icuuc',
           ],
           'sources': [
             'app/webrtc/java/jni/classreferenceholder.cc',
@@ -58,9 +57,14 @@
             'app/webrtc/java/jni/peerconnection_jni.cc',
           ],
           'include_dirs': [
-            '<(DEPTH)/third_party/libyuv/include',
+            '<(libyuv_dir)/include',
           ],
           'conditions': [
+            ['build_icu==1', {
+              'dependencies': [
+                '<(DEPTH)/third_party/icu/icu.gyp:icuuc',
+              ],
+            }],
             ['OS=="linux"', {
               'defines': [
                 'HAVE_GTK',
@@ -69,12 +73,16 @@
                 '<(java_home)/include',
                 '<(java_home)/include/linux',
               ],
-              'link_settings': {
-                'libraries': [
-                  '<!@(pkg-config --libs-only-l gobject-2.0 gthread-2.0'
-                      ' gtk+-2.0)',
-                ],
-              },
+              'conditions': [
+                ['use_gtk==1', {
+                  'link_settings': {
+                    'libraries': [
+                      '<!@(pkg-config --libs-only-l gobject-2.0 gthread-2.0'
+                          ' gtk+-2.0)',
+                    ],
+                  },
+                }],
+              ],
             }],
             ['OS=="android"', {
               'sources': [
@@ -358,26 +366,31 @@
       'target_name': 'libjingle',
       'type': 'none',
       'dependencies': [
-        '<(DEPTH)/third_party/expat/expat.gyp:expat',
-        '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp',
         '<(webrtc_root)/base/base.gyp:rtc_base',
       ],
-      'export_dependent_settings': [
-        '<(DEPTH)/third_party/expat/expat.gyp:expat',
-        '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp',
+      'conditions': [
+        ['build_json==1', {
+          'dependencies': [
+            '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp',
+          ],
+          'export_dependent_settings': [
+            '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp',
+          ],
+        }],
+        ['build_expat==1', {
+          'dependencies': [
+            '<(DEPTH)/third_party/expat/expat.gyp:expat',
+          ],
+          'export_dependent_settings': [
+            '<(DEPTH)/third_party/expat/expat.gyp:expat',
+          ],
+        }],
       ],
     },  # target libjingle
     {
       'target_name': 'libjingle_media',
       'type': 'static_library',
-      'include_dirs': [
-        # TODO(jiayl): move this into the direct_dependent_settings of
-        # usrsctp.gyp.
-        '<(DEPTH)/third_party/usrsctp',
-      ],
       'dependencies': [
-        '<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv',
-        '<(DEPTH)/third_party/usrsctp/usrsctp.gyp:usrsctplib',
         '<(webrtc_root)/common.gyp:webrtc_common',
         '<(webrtc_root)/modules/modules.gyp:video_render_module',
         '<(webrtc_root)/webrtc.gyp:webrtc',
@@ -392,7 +405,7 @@
       ],
       'direct_dependent_settings': {
         'include_dirs': [
-          '<(DEPTH)/third_party/libyuv/include',
+          '<(libyuv_dir)/include',
         ],
       },
       'sources': [
@@ -484,6 +497,19 @@
         'media/webrtc/webrtcvoiceengine.h',
       ],
       'conditions': [
+        ['build_libyuv==1', {
+          'dependencies': ['<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv',],
+        }],
+        ['build_usrsctp==1', {
+          'include_dirs': [
+            # TODO(jiayl): move this into the direct_dependent_settings of
+            # usrsctp.gyp.
+            '<(DEPTH)/third_party/usrsctp',
+          ],
+          'dependencies': [
+            '<(DEPTH)/third_party/usrsctp/usrsctp.gyp:usrsctplib',
+          ],
+        }],
         ['build_with_chromium==1', {
           'dependencies': [
             '<(webrtc_root)/modules/modules.gyp:video_capture',
@@ -497,8 +523,6 @@
         }],
         ['OS=="linux"', {
           'sources': [
-            'media/devices/gtkvideorenderer.cc',
-            'media/devices/gtkvideorenderer.h',
             'media/devices/libudevsymboltable.cc',
             'media/devices/libudevsymboltable.h',
             'media/devices/linuxdeviceinfo.cc',
@@ -507,12 +531,20 @@
             'media/devices/v4llookup.cc',
             'media/devices/v4llookup.h',
           ],
+          'conditions': [
+            ['use_gtk==1', {
+              'sources': [
+                'media/devices/gtkvideorenderer.cc',
+                'media/devices/gtkvideorenderer.h',
+              ],
+              'cflags': [
+                '<!@(pkg-config --cflags gobject-2.0 gthread-2.0 gtk+-2.0)',
+              ],
+            }],
+          ],
           'include_dirs': [
             'third_party/libudev'
           ],
-          'cflags': [
-            '<!@(pkg-config --cflags gobject-2.0 gthread-2.0 gtk+-2.0)',
-          ],
           'libraries': [
             '-lrt',
             '-lXext',
@@ -601,10 +633,16 @@
       'target_name': 'libjingle_p2p',
       'type': 'static_library',
       'dependencies': [
-        '<(DEPTH)/third_party/libsrtp/libsrtp.gyp:libsrtp',
         'libjingle',
         'libjingle_media',
       ],
+      'conditions': [
+        ['build_libsrtp==1', {
+          'dependencies': [
+            '<(DEPTH)/third_party/libsrtp/libsrtp.gyp:libsrtp',
+          ],
+        }],
+      ],
       'include_dirs': [
         '<(DEPTH)/testing/gtest/include',
       ],
diff --git a/talk/libjingle_examples.gyp b/talk/libjingle_examples.gyp
index 0972708..da5a214 100755
--- a/talk/libjingle_examples.gyp
+++ b/talk/libjingle_examples.gyp
@@ -97,11 +97,15 @@
             'examples/peerconnection/client/peer_connection_client.h',
           ],
           'dependencies': [
-            '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp',
             'libjingle.gyp:libjingle_peerconnection',
             '<@(libjingle_tests_additional_deps)',
           ],
           'conditions': [
+            ['build_json==1', {
+              'dependencies': [
+                '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp',
+              ],
+            }],
             # TODO(ronghuawu): Move these files to a win/ directory then they
             # can be excluded automatically.
             ['OS=="win"', {
diff --git a/talk/libjingle_tests.gyp b/talk/libjingle_tests.gyp
index e0937b6..7183972 100755
--- a/talk/libjingle_tests.gyp
+++ b/talk/libjingle_tests.gyp
@@ -31,17 +31,21 @@
       'target_name': 'libjingle_unittest_main',
       'type': 'static_library',
       'dependencies': [
-        '<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv',
         '<(webrtc_root)/base/base_tests.gyp:rtc_base_tests_utils',
         '<@(libjingle_tests_additional_deps)',
       ],
       'direct_dependent_settings': {
         'include_dirs': [
-          '<(DEPTH)/third_party/libyuv/include',
+          '<(libyuv_dir)/include',
           '<(DEPTH)/testing/gtest/include',
           '<(DEPTH)/testing/gtest',
         ],
       },
+      'conditions': [
+        ['build_libyuv==1', {
+          'dependencies': ['<(DEPTH)/third_party/libyuv/libyuv.gyp:libyuv',],
+        }],
+      ],
       'include_dirs': [
          '<(DEPTH)/testing/gtest/include',
          '<(DEPTH)/testing/gtest',
@@ -140,7 +144,6 @@
       'target_name': 'libjingle_p2p_unittest',
       'type': 'executable',
       'dependencies': [
-        '<(DEPTH)/third_party/libsrtp/libsrtp.gyp:libsrtp',
         '<(webrtc_root)/base/base_tests.gyp:rtc_base_tests_utils',
         'libjingle.gyp:libjingle',
         'libjingle.gyp:libjingle_p2p',
@@ -160,6 +163,11 @@
         'session/media/srtpfilter_unittest.cc',
       ],
       'conditions': [
+        ['build_libsrtp==1', {
+          'dependencies': [
+            '<(DEPTH)/third_party/libsrtp/libsrtp.gyp:libsrtp',
+          ],
+        }],
         ['OS=="win"', {
           'msvs_settings': {
             'VCLinkerTool': {
diff --git a/webrtc/build/common.gypi b/webrtc/build/common.gypi
index cf1ffe1..2d7d985 100644
--- a/webrtc/build/common.gypi
+++ b/webrtc/build/common.gypi
@@ -84,14 +84,16 @@
     'enable_protobuf%': 1,
 
     # Disable these to not build components which can be externally provided.
+    'build_expat%': 1,
+    'build_icu%': 1,
     'build_json%': 1,
     'build_libjpeg%': 1,
-    'build_libyuv%': 1,
     'build_libvpx%': 1,
-    'build_vp9%': 1,
-    'build_ssl%': 1,
+    'build_libyuv%': 1,
     'build_openmax_dl%': 1,
     'build_opus%': 1,
+    'build_ssl%': 1,
+    'build_vp9%': 1,
 
     # Disable by default
     'have_dbus_glib%': 0,
diff --git a/webrtc/build/webrtc.gni b/webrtc/build/webrtc.gni
index 3441fa0..336f7a1 100644
--- a/webrtc/build/webrtc.gni
+++ b/webrtc/build/webrtc.gni
@@ -37,14 +37,16 @@
   rtc_enable_protobuf = true
 
   # Disable these to not build components which can be externally provided.
+  rtc_build_expat = true
+  rtc_build_icu = true
   rtc_build_json = true
   rtc_build_libjpeg = true
-  rtc_build_libyuv = true
   rtc_build_libvpx = true
-  rtc_build_vp9 = true
-  rtc_build_ssl = true
-  rtc_build_opus = true
+  rtc_build_libyuv = true
   rtc_build_openmax_dl = true
+  rtc_build_opus = true
+  rtc_build_ssl = true
+  rtc_build_vp9 = true
 
   # Disable by default.
   rtc_have_dbus_glib = false
diff --git a/webrtc/libjingle/libjingle.gyp b/webrtc/libjingle/libjingle.gyp
index a54bd20..f92f346 100644
--- a/webrtc/libjingle/libjingle.gyp
+++ b/webrtc/libjingle/libjingle.gyp
@@ -16,10 +16,16 @@
       'target_name': 'libjingle_xmpphelp',
       'type': 'static_library',
       'dependencies': [
-        '<(DEPTH)/third_party/expat/expat.gyp:expat',
         '<(talk_root)/libjingle.gyp:libjingle',
         '<(talk_root)/libjingle.gyp:libjingle_p2p',
       ],
+      'conditions': [
+        ['build_expat==1', {
+          'dependencies': [
+            '<(DEPTH)/third_party/expat/expat.gyp:expat',
+          ],
+        }],
+      ],
       'sources': [
         'xmpp/jingleinfotask.cc',
         'xmpp/jingleinfotask.h',
@@ -33,14 +39,10 @@
         '<(webrtc_root)/base/base.gyp:rtc_base',
         '<(webrtc_root)/common.gyp:webrtc_common',
         '<(webrtc_root)/libjingle/xmpp/xmpp.gyp:rtc_xmpp',
-        '<(DEPTH)/third_party/expat/expat.gyp:expat',
       ],
       'cflags_cc!': [
         '-Wnon-virtual-dtor',
       ],
-      'export_dependent_settings': [
-        '<(DEPTH)/third_party/expat/expat.gyp:expat',
-      ],
       'sources': [
         'session/constants.cc',
         'session/constants.h',
@@ -87,6 +89,14 @@
             'FEATURE_ENABLE_PSTN',
           ],
         }],
+        ['build_expat==1', {
+          'dependencies': [
+            '<(DEPTH)/third_party/expat/expat.gyp:expat',
+          ],
+          'export_dependent_settings': [
+            '<(DEPTH)/third_party/expat/expat.gyp:expat',
+          ],
+        }],
       ],
     },
     {
diff --git a/webrtc/libjingle/xmllite/xmllite.gyp b/webrtc/libjingle/xmllite/xmllite.gyp
index e1bef96..c297b42 100644
--- a/webrtc/libjingle/xmllite/xmllite.gyp
+++ b/webrtc/libjingle/xmllite/xmllite.gyp
@@ -14,10 +14,16 @@
       'type': 'static_library',
       'dependencies': [
         '<(webrtc_root)/base/base.gyp:rtc_base',
-        '<(DEPTH)/third_party/expat/expat.gyp:expat',
       ],
-      'export_dependent_settings': [
-        '<(DEPTH)/third_party/expat/expat.gyp:expat',
+      'conditions': [
+        ['build_expat==1', {
+          'dependencies': [
+            '<(DEPTH)/third_party/expat/expat.gyp:expat',
+          ],
+          'export_dependent_settings': [
+            '<(DEPTH)/third_party/expat/expat.gyp:expat',
+          ],
+        }],
       ],
       'sources': [
         'qname.cc',
diff --git a/webrtc/libjingle/xmpp/xmpp.gyp b/webrtc/libjingle/xmpp/xmpp.gyp
index b46c62c..6b738e7 100644
--- a/webrtc/libjingle/xmpp/xmpp.gyp
+++ b/webrtc/libjingle/xmpp/xmpp.gyp
@@ -15,7 +15,6 @@
       'dependencies': [
         '<(webrtc_root)/base/base.gyp:rtc_base',
         '<(webrtc_root)/libjingle/xmllite/xmllite.gyp:rtc_xmllite',
-        '<(DEPTH)/third_party/expat/expat.gyp:expat',
       ],
       'defines': [
         'FEATURE_ENABLE_SSL',
@@ -23,9 +22,6 @@
       'cflags_cc!': [
         '-Wnon-virtual-dtor',
       ],
-      'export_dependent_settings': [
-        '<(DEPTH)/third_party/expat/expat.gyp:expat',
-      ],
       'sources': [
         'asyncsocket.h',
         'chatroommodule.h',
@@ -111,6 +107,14 @@
         ],
       },
       'conditions': [
+        ['build_expat==1', {
+          'dependencies': [
+            '<(DEPTH)/third_party/expat/expat.gyp:expat',
+          ],
+          'export_dependent_settings': [
+            '<(DEPTH)/third_party/expat/expat.gyp:expat',
+          ],
+        }],
         ['build_with_chromium==0', {
           'defines': [
             'FEATURE_ENABLE_VOICEMAIL',
diff --git a/webrtc/modules/video_capture/BUILD.gn b/webrtc/modules/video_capture/BUILD.gn
index b7e9d30..0ba15c0 100644
--- a/webrtc/modules/video_capture/BUILD.gn
+++ b/webrtc/modules/video_capture/BUILD.gn
@@ -138,10 +138,12 @@
         "android/video_capture_android.h",
       ]
 
-      deps += [
-        "//third_party/icu:icuuc",
-        "//third_party/jsoncpp",
-      ]
+      if (rtc_build_json) {
+        deps += [ "//third_party/jsoncpp" ]
+      }
+      if (rtc_build_icu) {
+        deps += [ "//third_party/icu:icuuc" ]
+      }
     }
     if (is_ios) {
       sources = [
diff --git a/webrtc/modules/video_capture/video_capture.gypi b/webrtc/modules/video_capture/video_capture.gypi
index 3c9b93c..9163c1c 100644
--- a/webrtc/modules/video_capture/video_capture.gypi
+++ b/webrtc/modules/video_capture/video_capture.gypi
@@ -116,16 +116,24 @@
               },
             }],  # win
             ['OS=="android"', {
-              'dependencies': [
-                '<(DEPTH)/third_party/icu/icu.gyp:icuuc',
-                '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp',
-              ],
               'sources': [
                 'android/device_info_android.cc',
                 'android/device_info_android.h',
                 'android/video_capture_android.cc',
                 'android/video_capture_android.h',
               ],
+              'conditions': [
+                ['build_json==1', {
+                  'dependencies': [
+                    '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp',
+                  ],
+                }],
+                ['build_icu==1', {
+                  'dependencies': [
+                    '<(DEPTH)/third_party/icu/icu.gyp:icuuc',
+                  ],
+                }],
+              ],
             }],  # android
             ['OS=="ios"', {
               'sources': [
diff --git a/webrtc/webrtc_examples.gyp b/webrtc/webrtc_examples.gyp
index 5d18aa6..35fc938 100644
--- a/webrtc/webrtc_examples.gyp
+++ b/webrtc/webrtc_examples.gyp
@@ -15,7 +15,6 @@
           'target_name': 'libwebrtcdemo-jni',
           'type': 'loadable_module',
           'dependencies': [
-            '<(DEPTH)/third_party/icu/icu.gyp:icuuc',
             '<(webrtc_root)/common.gyp:webrtc_common',
             '<(webrtc_root)/modules/modules.gyp:video_render_module_internal_impl',
             '<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers_default',
@@ -27,6 +26,13 @@
             'examples/android/media_demo/jni/on_load.cc',
             'examples/android/media_demo/jni/voice_engine_jni.cc',
           ],
+          'conditions': [
+            ['build_icu==1', {
+              'dependencies': [
+                '<(DEPTH)/third_party/icu/icu.gyp:icuuc',
+              ],
+            }],
+          ],
           'variables': {
             # This library uses native JNI exports; tell GYP so that the
             # required symbols will be kept.