@@ -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)
512506endif ()
507+
513508if (NOT FLATC_EXECUTABLE)
514509 message (
515510 FATAL_ERROR
0 commit comments