|
| 1 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This source code is licensed under the BSD-style license found in the |
| 5 | +# LICENSE file in the root directory of this source tree. |
| 6 | + |
| 7 | +# Flatbuffer schema header lib. Please this file formatted by running: |
| 8 | +# ~~~ |
| 9 | +# cmake-format --first-comment-is-literal=True CMakeLists.txt |
| 10 | +# ~~~ |
| 11 | + |
| 12 | +# The include directory that will contain the generated schema headers. |
| 13 | +set(_program_schema__include_dir "${CMAKE_CURRENT_BINARY_DIR}/schema/include") |
| 14 | + |
| 15 | +# Source root directory for executorch. |
| 16 | +if(NOT EXECUTORCH_ROOT) |
| 17 | + set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) |
| 18 | +endif() |
| 19 | + |
| 20 | +# Paths to headers generated from the .fbs files. |
| 21 | +set(_program_schema__srcs program.fbs scalar_type.fbs) |
| 22 | + |
| 23 | +set(_program_schema__outputs) |
| 24 | +foreach(fbs_file ${_program_schema__srcs}) |
| 25 | + string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}") |
| 26 | + list(APPEND _program_schema__outputs |
| 27 | + "${_program_schema__include_dir}/executorch/${generated}") |
| 28 | +endforeach() |
| 29 | + |
| 30 | +# Generate the headers from the .fbs files. |
| 31 | +add_custom_command( |
| 32 | + OUTPUT ${_program_schema__outputs} |
| 33 | + COMMAND |
| 34 | + flatc --cpp --cpp-std c++11 --gen-mutable --scoped-enums |
| 35 | + # Add a subdirectory to the include dir so the files can be included as |
| 36 | + # <executorch/schema/x_generated.h> |
| 37 | + -o "${_program_schema__include_dir}/executorch/schema" |
| 38 | + ${_program_schema__srcs} |
| 39 | + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 40 | + DEPENDS flatc ${_program_schema__srcs} |
| 41 | + COMMENT "Generating program_schema headers" |
| 42 | + VERBATIM) |
| 43 | + |
| 44 | +add_library(program_schema INTERFACE ${_program_schema__outputs}) |
| 45 | +set_target_properties(program_schema PROPERTIES LINKER_LANGUAGE CXX) |
| 46 | +target_include_directories( |
| 47 | + program_schema INTERFACE ${_program_schema__include_dir} |
| 48 | + ${EXECUTORCH_ROOT}/third-party/flatbuffers/include) |
0 commit comments