From 35fa3df8ecc3f451af0512e70a03f89ee407c85c Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 1 Dec 2018 02:33:16 -0800 Subject: [PATCH] Fixes for macOS build. Also run tests in CMake test. --- BUILD | 2 +- CMakeLists.txt | 6 ++---- build_defs.bzl | 2 +- tools/make_cmakelists.py | 30 ++++++++++++++++++------------ 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/BUILD b/BUILD index 97380a4257..a0eadb3918 100644 --- a/BUILD +++ b/BUILD @@ -407,7 +407,7 @@ cc_binary( make_shell_script( name = "gen_run_cmake_build", out = "run_cmake_build.sh", - contents = "mkdir build && cd build && cmake .. && make -j8" + contents = "mkdir build && cd build && cmake .. && make -j8 && make test" ) sh_test( diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c6d5fa032..412cdcd09d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,11 +117,9 @@ add_library(upb_json upb/json/printer.h) target_link_libraries(upb_json upb) -add_library(upb_cc_bindings - upb/bindings/stdc++/string.h) -target_link_libraries(upb_cc_bindings +add_library(upb_cc_bindings INTERFACE) +target_link_libraries(upb_cc_bindings INTERFACE upb) -set_target_properties(upb_cc_bindings PROPERTIES LINKER_LANGUAGE CXX) add_library(upb_test tests/testmain.cc tests/test_util.h diff --git a/build_defs.bzl b/build_defs.bzl index 5bbbc4fd28..362691a878 100644 --- a/build_defs.bzl +++ b/build_defs.bzl @@ -147,7 +147,7 @@ def generated_file_staleness_test(name, outs, generated_pattern): srcs = [script_src], testonly = 1, cmd = "cat $(location " + script_src + ") > $@; " + - "sed -i 's|INSERT_FILE_LIST_HERE|" + "\\n ".join(file_list) + "|' $@", + "sed -i '' -e 's|INSERT_FILE_LIST_HERE|" + "\\\n ".join(file_list) + "|' $@", ) native.py_test( diff --git a/tools/make_cmakelists.py b/tools/make_cmakelists.py index d7996d8748..b8f46b9029 100755 --- a/tools/make_cmakelists.py +++ b/tools/make_cmakelists.py @@ -22,11 +22,12 @@ class BuildFileFunctions(object): def __init__(self, converter): self.converter = converter - def _add_deps(self, kwargs): + def _add_deps(self, kwargs, keyword=""): if "deps" not in kwargs: return - self.converter.toplevel += "target_link_libraries(%s\n %s)\n" % ( + self.converter.toplevel += "target_link_libraries(%s%s\n %s)\n" % ( kwargs["name"], + keyword, "\n ".join(StripColons(kwargs["deps"])) ) @@ -37,17 +38,22 @@ class BuildFileFunctions(object): if kwargs["name"] == "amalgamation" or kwargs["name"] == "upbc_generator": return files = kwargs.get("srcs", []) + kwargs.get("hdrs", []) - self.converter.toplevel += "add_library(%s\n %s)\n" % ( - kwargs["name"], - "\n ".join(files) - ) - self._add_deps(kwargs) - # CMake wants to know if each library is C or C++. - # If there are only .h files, it can't infer. Assume C++. - if not filter(IsSourceFile, files): - line = "set_target_properties(%s PROPERTIES LINKER_LANGUAGE CXX)\n" - self.converter.toplevel += line % (kwargs["name"]) + if filter(IsSourceFile, files): + # Has sources, make this a normal library. + self.converter.toplevel += "add_library(%s\n %s)\n" % ( + kwargs["name"], + "\n ".join(files) + ) + self._add_deps(kwargs) + else: + # Header-only library, have to do a couple things differently. + # For some info, see: + # http://mariobadr.com/creating-a-header-only-library-with-cmake.html + self.converter.toplevel += "add_library(%s INTERFACE)\n" % ( + kwargs["name"] + ) + self._add_deps(kwargs, " INTERFACE") def cc_binary(self, **kwargs): pass