Skip to content

Commit a7e70da

Browse files
committed
Build flatc for the host instead of the target platform
1 parent de41eaa commit a7e70da

File tree

8 files changed

+27
-28
lines changed

8 files changed

+27
-28
lines changed

CMakeLists.txt

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -482,34 +482,29 @@ if(EXECUTORCH_BUILD_FLATC)
482482
FATAL_ERROR "May not set both EXECUTORCH_BUILD_FLATC and FLATC_EXECUTABLE"
483483
)
484484
endif()
485-
set(FLATC_EXECUTABLE flatc)
486-
set(FLATBUFFERS_BUILD_FLATC
487-
ON
488-
CACHE BOOL ""
489-
)
490-
set(FLATBUFFERS_BUILD_FLATHASH
491-
OFF
492-
CACHE BOOL ""
493-
)
494-
set(FLATBUFFERS_BUILD_FLATLIB
495-
OFF
496-
CACHE BOOL ""
497-
)
498-
set(FLATBUFFERS_BUILD_TESTS
499-
OFF
500-
CACHE BOOL ""
501-
)
502-
set(FLATBUFFERS_INSTALL
503-
OFF
504-
CACHE BOOL ""
485+
486+
include(ExternalProject)
487+
488+
ExternalProject_Add(
489+
host_flatc
490+
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/third-party/flatbuffers
491+
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third-party/flatbuffers
492+
CMAKE_ARGS -DFLATBUFFERS_BUILD_FLATC=ON
493+
-DFLATBUFFERS_BUILD_FLATHASH=OFF
494+
-DFLATBUFFERS_BUILD_FLATLIB=OFF
495+
-DFLATBUFFERS_BUILD_TESTS=OFF
496+
-DFLATBUFFERS_INSTALL=OFF
497+
# exir lets users set the alignment of tensor data embedded in
498+
# the flatbuffer, and some users need an alignment larger than
499+
# the default, which is typically 32.
500+
-DCMAKE_CXX_FLAGS=-DFLATBUFFERS_MAX_ALIGNMENT=1024
501+
INSTALL_COMMAND ""
505502
)
506-
add_subdirectory(third-party/flatbuffers)
503+
ExternalProject_Get_Property(host_flatc BINARY_DIR)
504+
set(FLATC_EXECUTABLE ${BINARY_DIR}/flatc)
507505

508-
# exir lets users set the alignment of tensor data embedded in the flatbuffer,
509-
# and some users need an alignment larger than the default, which is typically
510-
# 32.
511-
target_compile_definitions(flatc PRIVATE FLATBUFFERS_MAX_ALIGNMENT=1024)
512506
endif()
507+
513508
if(NOT FLATC_EXECUTABLE)
514509
message(
515510
FATAL_ERROR

backends/apple/mps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ add_custom_command(
5050
"${_mps_schema__include_dir}/executorch/backends/apple/mps"
5151
${_mps_schema__srcs}
5252
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
53+
DEPENDS host_flatc
5354
COMMENT "Generating mps_schema headers"
5455
VERBATIM
5556
)

backends/qualcomm/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ add_custom_command(
4949
OUTPUT qcir_schema_output
5050
COMMAND ${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
5151
${qcir_schema_include_dir} ${qcir_schema_include_dir}/qcir.fbs
52+
DEPENDS host_flatc
5253
COMMENT "Generating qualcomm ir schema headers"
5354
VERBATIM
5455
)

backends/vulkan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ add_custom_command(
9292
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
9393
"${SCHEMA_INCLUDE_DIR}/executorch/backends/vulkan/serialization/" ${_vulkan_schema__srcs}
9494
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
95+
DEPENDS host_flatc
9596
COMMENT "Generating vulkan_schema headers"
9697
VERBATIM
9798
)

backends/xnnpack/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ add_custom_command(
8282
${_xnnpack_schema__srcs}
8383
COMMAND mv ${_xnnpack_flatbuffer__outputs} ${_xnnpack_schema__outputs}
8484
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
85+
DEPENDS host_flatc
8586
COMMENT "Generating xnnpack_schema headers"
8687
VERBATIM
8788
)

devtools/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ add_custom_command(
205205
"${_bundled_schema__include_dir}/executorch/devtools/bundled_program/schema"
206206
${_bundled_program_schema__srcs}
207207
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/devtools
208-
DEPENDS ${FLATC_EXECUTABLE} ${_bundled_program_schema__srcs}
208+
DEPENDS host_flatc ${_bundled_program_schema__srcs}
209209
COMMENT "Generating bundled_program headers"
210210
VERBATIM
211211
)

extension/flat_tensor/serialize/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function(generate_flat_tensor_schema _schema_srcs _schema_name)
3737
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --gen-mutable --scoped-enums -o
3838
"${_flat_tensor_schema__output_dir}" ${_schema_srcs}
3939
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
40-
DEPENDS ${FLATC_EXECUTABLE} ${_schema_srcs}
40+
DEPENDS host_flatc ${_schema_srcs}
4141
COMMENT "Generating ${_schema_name} headers"
4242
VERBATIM
4343
)

schema/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function(generate_program_schema _schema_srcs _schema_name)
3737
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --gen-mutable --scoped-enums -o
3838
"${_program_schema__output_dir}" ${_schema_srcs}
3939
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
40-
DEPENDS ${FLATC_EXECUTABLE} ${_schema_srcs}
40+
DEPENDS host_flatc ${_schema_srcs}
4141
COMMENT "Generating ${_schema_name} headers"
4242
VERBATIM
4343
)

0 commit comments

Comments
 (0)