1.. _module-pw_flatbuffers: 2 3============== 4pw_flatbuffers 5============== 6.. pigweed-module:: 7 :name: pw_flatbuffers 8 9The flatbuffers module supports the use of cmake to build C++ headers from a 10set of flatbuffers schema files. The user of these build files may either use 11the provided flatbuffers distribution or provide their own. 12 13----------------------- 14Flatbuffers compilation 15----------------------- 16pw_flatbuffers currently only supports ``cmake`` as the build system. 17 18CMake 19===== 20CMake provides a ``pw_flatbuffer_library`` function to build flatbuffer schema 21files into C++ headers. The user of this function is expected to configure the 22flatbuffers compiler as well as provide any needed dependencies such as 23flatbuffers headers. Support for outputting other languages supported by 24``flatc`` is currently not implemented. 25 26 27**Arguments** 28 29* ``NAME``: Name of dependency to create. The dependency target name will be 30 ``NAME.cpp`` 31* ``SOURCES``: Source schema files to compile to headers 32* ``DEPS``: Dependencies needed to compile the passed in schema files 33* ``FLATC_FLAGS``: flags to be passed to ``flatc`` when building 34 35**Globals** 36 37Additionally, several global cache variables influence the behavior of 38``pw_flatbuffer_library``. 39 40* ``pw_flatbuffers_FLATC``: Path to the flatbuffers compiler executable. This 41 defaults to simply using ``flatc`` and relying on the shell ``PATH`` to 42 locate the compiler. 43* ``pw_flatbuffers_FLATC_FLAGS``: Global flags to pass to all invocations of 44 the ``flatc`` compiler. Defaults to empty. 45* ``pw_flatbuffers_LIBRARY``: Flatbuffer header library dependency to 46 automatically add to all flatbuffers libraries built. Defaults to unset 47 unless using the pigweed provided flatbuffers by setting 48 ``dir_pw_third_party_flatbuffers``, in which case this will default to the 49 pigweed provided third party flatbuffers. If left unset, the user takes 50 responsibility for properly providing the flatbuffer dependencies to code. 51 52**Example*** 53 54.. code_block: cmake 55 56 # Point to our installed directory 57 set(dir_pw_third_party_flatbuffers ${path_to_flatbuffers_install}) 58 59 # Set global flags, such as the C++ version 60 set(pw_flatbuffers_FLATC_FLAGS --cpp-std c++11 CACHE LIST "Global args to flatc") 61 62 include($ENV{PW_ROOT}/pw_build/pigweed.cmake) 63 include($ENV{PW_ROOT}/pw_flatbuffers/flatbuffers.cmake) 64 65 # Build the fbs files to headers 66 pw_flatbuffer_library(simple_test_schema 67 SOURCES 68 pw_flatbuffers_test_schema/simple_test.fbs 69 ) 70 71 # Build a test exe 72 pw_add_test(pw_flatbuffers.simple_test 73 SOURCES 74 simple_test.cc 75 PRIVATE_DEPS 76 simple_test_schema.cpp 77 GROUPS 78 modules 79 ) 80 81 82GN 83== 84GN is not currently supported. 85 86Bazel 87===== 88Bazel is not currently supported. 89