@@ -474,6 +474,17 @@ cmake_dependent_option(
474
474
"NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF
475
475
)
476
476
477
+
478
+ set (FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "" )
479
+ set (FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "" )
480
+ set (FLATBUFFERS_BUILD_FLATLIB OFF CACHE BOOL "" )
481
+ set (FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "" )
482
+ set (FLATBUFFERS_INSTALL OFF CACHE BOOL "" )
483
+ # exir lets users set the alignment of tensor data embedded in the flatbuffer,
484
+ # and some users need an alignment larger than the default, which is typically
485
+ # 32.
486
+ set (FLATBUFFERS_MAX_ALIGNMENT 1024)
487
+
477
488
if (EXECUTORCH_BUILD_FLATC)
478
489
if (FLATC_EXECUTABLE)
479
490
# We could ignore this, but it could lead to confusion about which `flatc`
@@ -483,35 +494,39 @@ if(EXECUTORCH_BUILD_FLATC)
483
494
)
484
495
endif ()
485
496
497
+ # Build flatc for the *host* to generate files as part of the build step.
486
498
include (ExternalProject)
487
-
488
499
ExternalProject_Add(
489
500
flatc
490
501
PREFIX ${CMAKE_CURRENT_BINARY_DIR} /third-party/flatbuffers
502
+ BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} /third-party/flatbuffers
491
503
SOURCE_DIR ${CMAKE_SOURCE_DIR} /third-party/flatbuffers
492
504
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
505
+ -DFLATBUFFERS_BUILD_FLATHASH=${FLATBUFFERS_BUILD_FLATHASH}
506
+ -DFLATBUFFERS_BUILD_FLATLIB=${FLATBUFFERS_BUILD_FLATLIB}
507
+ -DFLATBUFFERS_BUILD_TESTS=${FLATBUFFERS_BUILD_TESTS}
508
+ -DFLATBUFFERS_INSTALL=${FLATBUFFERS_INSTALL}
509
+ -DCMAKE_CXX_FLAGS="-DFLATBUFFERS_MAX_ALIGNMENT=${FLATBUFFERS_MAX_ALIGNMENT} "
501
510
INSTALL_COMMAND ""
502
511
)
503
512
ExternalProject_Get_Property(flatc BINARY_DIR)
504
513
set (FLATC_EXECUTABLE ${BINARY_DIR} /flatc)
505
-
506
514
endif ()
507
515
508
516
if (NOT FLATC_EXECUTABLE)
509
517
message (
510
- FATAL_ERROR
511
- "FLATC_EXECUTABLE must be set when EXECUTORCH_BUILD_FLATC is disabled. "
512
- "Note that EXECUTORCH_BUILD_FLATC may be disabled implicitly when "
513
- "cross-compiling or when EXECUTORCH_BUILD_HOST_TARGETS is disabled."
518
+ WARNING "FLATC_EXECUTABLE not specified, looking for flatc"
514
519
)
520
+ find_program (FLATC_EXECUTABLE flatc)
521
+
522
+ if (NOT FLATC_EXECUTABLE)
523
+ message (
524
+ FATAL_ERROR
525
+ "FLATC_EXECUTABLE must be set when EXECUTORCH_BUILD_FLATC is disabled. "
526
+ "Note that EXECUTORCH_BUILD_FLATC may be disabled implicitly when "
527
+ "cross-compiling or when EXECUTORCH_BUILD_HOST_TARGETS is disabled."
528
+ )
529
+ endif ()
515
530
endif ()
516
531
517
532
#
0 commit comments