Skip to content

Commit 7648be8

Browse files
tarun292facebook-github-bot
authored andcommitted
Add support for building bundled_program schema in CMake (#656)
Summary: Pull Request resolved: #656 - Move the schema building code into a function in `schema/CMakeLists.txt` - Add support for building bundled program schema Reviewed By: larryliu0820 Differential Revision: D49992580 fbshipit-source-id: b7c0aecef44fffd028006aaf52bf51470d11423a
1 parent 5e62815 commit 7648be8

File tree

2 files changed

+35
-32
lines changed

2 files changed

+35
-32
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ option(EXECUTORCH_BUILD_SIZE_TEST "Whether to build size test" OFF)
112112

113113
# Selective build options.
114114
option(EXECUTORCH_SELECT_ALL_OPS
115-
"Whether to register all ops defined in portable kernel library." ON)
115+
"Whether to register all ops defined in portable kernel library." ON)
116116

117117
# Option to register op list
118118
option(EXECUTORCH_SELECT_OPS_LIST "Register the following list of ops" OFF)
119119

120120
# Option to register ops from yaml file
121-
option(EXECUTORCH_SELECT_OPS_YAML
122-
"Register all the ops from a given yaml file" OFF)
121+
option(EXECUTORCH_SELECT_OPS_YAML "Register all the ops from a given yaml file"
122+
OFF)
123123
# Do not enable select all ops if any of the other select options is on.
124124
if(EXECUTORCH_SELECT_OPS_LIST OR EXECUTORCH_SELECT_OPS_YAML)
125125
set(EXECUTORCH_SELECT_ALL_OPS OFF)

schema/CMakeLists.txt

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,35 @@ if(NOT EXECUTORCH_ROOT)
2121
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)
2222
endif()
2323

24-
# Paths to headers generated from the .fbs files.
25-
set(_program_schema__srcs program.fbs scalar_type.fbs)
26-
27-
set(_program_schema__outputs)
28-
foreach(fbs_file ${_program_schema__srcs})
29-
string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}")
30-
list(APPEND _program_schema__outputs
31-
"${_program_schema__include_dir}/executorch/${generated}")
32-
endforeach()
33-
34-
# Generate the headers from the .fbs files.
35-
add_custom_command(
36-
OUTPUT ${_program_schema__outputs}
37-
COMMAND
38-
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --gen-mutable --scoped-enums
39-
# Add a subdirectory to the include dir so the files can be included as
40-
# <executorch/schema/x_generated.h>
41-
-o "${_program_schema__include_dir}/executorch/schema"
42-
${_program_schema__srcs}
43-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
44-
DEPENDS ${FLATC_EXECUTABLE} ${_program_schema__srcs}
45-
COMMENT "Generating program_schema headers"
46-
VERBATIM)
47-
48-
add_library(program_schema INTERFACE ${_program_schema__outputs})
49-
set_target_properties(program_schema PROPERTIES LINKER_LANGUAGE CXX)
50-
target_include_directories(
51-
program_schema INTERFACE ${_program_schema__include_dir}
52-
${EXECUTORCH_ROOT}/third-party/flatbuffers/include)
24+
function(generate_program_schema _schema_srcs _schema_name)
25+
set(_schema_outputs)
26+
foreach(fbs_file ${_schema_srcs})
27+
string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}")
28+
list(APPEND _schema_outputs
29+
"${_program_schema__include_dir}/executorch/${generated}")
30+
endforeach()
31+
32+
# Generate the headers from the .fbs files.
33+
add_custom_command(
34+
OUTPUT ${_schema_outputs}
35+
COMMAND
36+
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --gen-mutable --scoped-enums -o
37+
"${_program_schema__include_dir}/executorch/schema" ${_schema_srcs}
38+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
39+
DEPENDS ${FLATC_EXECUTABLE} ${_schema_srcs}
40+
COMMENT "Generating ${_schema_name} headers"
41+
VERBATIM)
42+
43+
add_library(${_schema_name} INTERFACE ${_schema_outputs})
44+
set_target_properties(${_schema_name} PROPERTIES LINKER_LANGUAGE CXX)
45+
target_include_directories(
46+
${_schema_name}
47+
INTERFACE ${_program_schema__include_dir}
48+
${EXECUTORCH_ROOT}/third-party/flatbuffers/include)
49+
endfunction()
50+
51+
set(program_schema_srcs program.fbs scalar_type.fbs)
52+
generate_program_schema("${program_schema_srcs}" "program_schema")
53+
54+
set(bundled_schema_srcs bundled_program_schema.fbs scalar_type.fbs)
55+
generate_program_schema("${bundled_schema_srcs}" "bundled_schema")

0 commit comments

Comments
 (0)