Add rules for cmake 3.11 to not error

As of cmake 3.11, the add_library target must have sources
associated with it. If there are sources, just compile
the file empty.cpp.

Change-Id: I7fec03dc0f0d2e6098572ed6e9fcdfaac3811024
Reviewed-on: https://skia-review.googlesource.com/129189
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/gn/gn_to_cmake.py b/gn/gn_to_cmake.py
index 8b4f484..0e82d64 100644
--- a/gn/gn_to_cmake.py
+++ b/gn/gn_to_cmake.py
@@ -475,8 +475,15 @@
   source_types = {'cxx':[], 'c':[], 'asm':[],
                   'obj':[], 'obj_target':[], 'input':[], 'other':[]}
 
+  all_sources = target.properties.get('sources', [])
+
+  # As of cmake 3.11 add_library must have sources. If there are
+  # no sources, add empty.cpp as the file to compile.
+  if len(all_sources) == 0:
+    all_sources.append(posixpath.join(project.build_path, 'empty.cpp'))
+
   # TODO .def files on Windows
-  for source in target.properties.get('sources', []):
+  for source in all_sources:
     _, ext = posixpath.splitext(source)
     source_abs_path = project.GetAbsolutePath(source)
     source_types[source_file_types.get(ext, 'other')].append(source_abs_path)
@@ -621,6 +628,10 @@
   out.write('cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR)\n')
   out.write('cmake_policy(VERSION 2.8.8)\n\n')
 
+  out.write('file(WRITE "')
+  out.write(posixpath.join(project.build_path, "empty.cpp"))
+  out.write('")\n')
+
   # Update the gn generated ninja build.
   # If a build file has changed, this will update CMakeLists.ext if
   # gn gen out/config --ide=json --json-ide-script=../../gn/gn_to_cmake.py