Enable use of the Xcode IDE via cmake.

Xcode needs special handling when an executable target contains
no C++ sources, but links C++ dependencies.

BUG=https://bugs.chromium.org/p/aomedia/issues/detail?id=76

Change-Id: Ifd4f6208c8f96386194691d45279df1e70a8fc17
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 54af54b..c75579c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -900,3 +900,22 @@
                    $<TARGET_OBJECTS:webm>)
   endif ()
 endif ()
+
+if (XCODE)
+  if (CONFIG_LIBYUV OR CONFIG_WEBM_IO)
+    # The Xcode generator does not obey LINKER_LANGUAGE. Because of the issue
+    # what looks like a C++ file needs to be in any target that Xcode will link
+    # when the target contains a C++ dependency.
+    # Without this Xcode will try to link with the C linker, which always ends
+    # badly when a dependency actually includes C++.
+    # Note: LINKER_LANGUAGE is explicitly set to C++ for all targets touched
+    # here, it really is the Xcode generator's fault, or just a deficiency in
+    # Xcode itself.
+    set(XCODE_DUMMY_CXX_FILE "${AOM_CONFIG_DIR}/dummy.cc")
+    file(WRITE "${XCODE_DUMMY_CXX_FILE}"
+         "// Xcode needs a C++ file to link, ignore this file.")
+    foreach (aom_app ${AOM_APP_TARGETS})
+      target_sources(${aom_app} PUBLIC "${XCODE_DUMMY_CXX_FILE}")
+    endforeach ()
+  endif ()
+endif ()