Skip to content

Commit 56fc73f

Browse files
larryliu0820facebook-github-bot
authored andcommitted
Decentralize schema lib cmake build file (#151)
Summary: Pull Request resolved: #151 Split out schema header generation logic into `schema/CMakeLists.txt`. Reviewed By: huydhn Differential Revision: D48712734 fbshipit-source-id: d2456bd756de8f2257b32ff5d2e0e68bf64f917b
1 parent cca86d0 commit 56fc73f

File tree

2 files changed

+49
-32
lines changed

2 files changed

+49
-32
lines changed

CMakeLists.txt

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -127,38 +127,7 @@ add_subdirectory(third-party/gflags)
127127
#
128128
# program_schema: Generated .h files from schema/*.fbs inputs
129129
#
130-
131-
# The include directory that will contain the generated schema headers.
132-
set(_program_schema__include_dir "${CMAKE_CURRENT_BINARY_DIR}/schema/include")
133-
134-
# Paths to headers generated from the .fbs files.
135-
set(_program_schema__outputs)
136-
foreach(fbs_file ${_program_schema__srcs})
137-
string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}")
138-
list(APPEND _program_schema__outputs
139-
"${_program_schema__include_dir}/executorch/${generated}")
140-
endforeach()
141-
142-
# Generate the headers from the .fbs files.
143-
add_custom_command(
144-
OUTPUT ${_program_schema__outputs}
145-
COMMAND
146-
flatc --cpp --cpp-std c++11 --gen-mutable --scoped-enums
147-
# Add a subdirectory to the include dir so the files can be included as
148-
# <executorch/schema/x_generated.h>
149-
-o "${_program_schema__include_dir}/executorch/schema"
150-
${_program_schema__srcs}
151-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
152-
DEPENDS flatc ${_program_schema__srcs}
153-
COMMENT "Generating program_schema headers"
154-
VERBATIM)
155-
156-
add_library(program_schema INTERFACE ${_program_schema__outputs})
157-
set_target_properties(program_schema PROPERTIES LINKER_LANGUAGE CXX)
158-
target_include_directories(
159-
program_schema
160-
INTERFACE ${_program_schema__include_dir}
161-
${CMAKE_CURRENT_SOURCE_DIR}/third-party/flatbuffers/include)
130+
add_subdirectory(schema)
162131

163132
#
164133
# executorch: Core runtime library

schema/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)