From 5699278b679f27e1426ff1867807d689f0e806d4 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Fri, 18 May 2018 15:09:41 -0400 Subject: 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 Reviewed-by: Mike Klein --- gn/gn_to_cmake.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'gn/gn_to_cmake.py') diff --git a/gn/gn_to_cmake.py b/gn/gn_to_cmake.py index 8b4f48479f..0e82d64c9f 100644 --- a/gn/gn_to_cmake.py +++ b/gn/gn_to_cmake.py @@ -475,8 +475,15 @@ def WriteSourceVariables(out, target, project): 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 @@ def WriteProject(project): 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 -- cgit v1.2.3