Add bazel_to_cmake support for flatbuffer_cc_library

Closes https://github.com/google/iree/pull/722

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/iree/pull/722 from iml130:flatbuffer_cc_library 3f3bcec75e4934b331508beb1342ed952b65edeb
PiperOrigin-RevId: 294355706
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake.py b/build_tools/bazel_to_cmake/bazel_to_cmake.py
index c15b9b8..ae11f14 100755
--- a/build_tools/bazel_to_cmake/bazel_to_cmake.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake.py
@@ -255,6 +255,13 @@
     deps_list = "\n".join(["    %s" % (dep,) for dep in deps_list])
     return "  DEPS\n%s\n" % (deps_list,)
 
+  def _convert_flatc_args_block(self, flatc_args):
+    if not flatc_args:
+      return ""
+    flatc_args = "\n".join(
+        ["    \"%s\"" % (flatc_arg,) for flatc_arg in flatc_args])
+    return "  FLATC_ARGS\n%s\n" % (flatc_args,)
+
   def _convert_unimplemented_function(self, function, details=""):
     message = "Unimplemented %(function)s: %(details)s" % {
         "function": function,
@@ -441,6 +448,18 @@
     "translation_block": translation_block,
     }
 
+  def iree_flatbuffer_cc_library(self, name, srcs, flatc_args=[]):
+    name_block = self._convert_name_block(name)
+    srcs_block = self._convert_srcs_block(srcs)
+    flatc_args_block = self._convert_flatc_args_block(flatc_args)
+
+    self.converter.body += """flatbuffer_cc_library(
+%(name_block)s%(srcs_block)s%(flatc_args_block)s  PUBLIC\n)\n\n""" % {
+    "name_block": name_block,
+    "srcs_block": srcs_block,
+    "flatc_args_block": flatc_args_block,
+    }
+
   def gentbl(self,
              name,
              tblgen,
diff --git a/build_tools/cmake/flatbuffer_cc_library.cmake b/build_tools/cmake/flatbuffer_cc_library.cmake
index ea39045..e3c1c69 100644
--- a/build_tools/cmake/flatbuffer_cc_library.cmake
+++ b/build_tools/cmake/flatbuffer_cc_library.cmake
@@ -26,6 +26,11 @@
 # COPTS: List of private compile options
 # DEFINES: List of public defines
 # LINKOPTS: List of link options
+# FLATC_ARGS: List of flattbuffers arguments. Default:
+#             "--keep-prefix"
+#             "--scoped-enums"
+#             "--reflect-names"
+#             "--gen-object-api"
 # PUBLIC: Add this so that this library will be exported under iree::
 # Also in IDE, target will appear in IREE folder while non PUBLIC will be in IREE/internal.
 # TESTONLY: When added, this target will only be built if user passes -DIREE_BUILD_TESTS=ON to CMake.
@@ -62,7 +67,7 @@
   cmake_parse_arguments(_RULE
     "PUBLIC;TESTONLY"
     "NAME"
-    "SRCS;COPTS;DEFINES;LINKOPTS;DEPS"
+    "SRCS;COPTS;DEFINES;LINKOPTS;DEPS;FLATC_ARGS"
     ${ARGN}
   )
 
@@ -71,17 +76,22 @@
     iree_package_name(_PACKAGE_NAME)
     set(_NAME "${_PACKAGE_NAME}_${_RULE_NAME}")
 
-    set(FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS
-      # Preserve root-relative include paths in generated code.
-      "--keep-prefix"
-      # Use C++11 'enum class' for enums.
-      "--scoped-enums"
-      # Include reflection tables used for dumping debug representations.
-      "--reflect-names"
-      # Generate FooT types for unpack/pack support. Note that this should only
-      # be used in tooling as the code size/runtime overhead is non-trivial.
-      "--gen-object-api"
-    )
+    if(NOT DEFINED _RULE_FLATC_ARGS)
+      set(FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS
+        # Preserve root-relative include paths in generated code.
+        "--keep-prefix"
+        # Use C++11 'enum class' for enums.
+        "--scoped-enums"
+        # Include reflection tables used for dumping debug representations.
+        "--reflect-names"
+        # Generate FooT types for unpack/pack support. Note that this should only
+        # be used in tooling as the code size/runtime overhead is non-trivial.
+        "--gen-object-api"
+      )
+    else()
+      set(FLATBUFFERS_FLATC_SCHEMA_EXTRA_ARGS ${_RULE_FLATC_ARGS})
+    endif()
+
     build_flatbuffers(
       "${_RULE_SRCS}"
       "${IREE_ROOT_DIR}"