@@ -59,6 +59,7 @@ print_configured_options()
59
59
60
60
include (tools/cmake/Utils.cmake)
61
61
include (CMakeDependentOption)
62
+ include (ExternalProject)
62
63
63
64
set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
64
65
@@ -260,6 +261,8 @@ cmake_dependent_option(
260
261
"NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF
261
262
)
262
263
264
+ add_subdirectory (third-party)
265
+
263
266
if (EXECUTORCH_BUILD_EXTENSION_TRAINING)
264
267
set (EXECUTORCH_BUILD_EXTENSION_DATA_LOADER ON )
265
268
set (EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ON )
@@ -454,81 +457,6 @@ if(EXECUTORCH_USE_CPP_CODE_COVERAGE)
454
457
endif ()
455
458
endif ()
456
459
457
- #
458
- # flatc: Flatbuffer commandline tool to generate .h files from .fbs files
459
- #
460
- cmake_dependent_option(
461
- EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON
462
- "NOT FLATC_EXECUTABLE" OFF
463
- )
464
-
465
- set (FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "" )
466
- set (FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "" )
467
- set (FLATBUFFERS_BUILD_FLATLIB OFF CACHE BOOL "" )
468
- set (FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "" )
469
- set (FLATBUFFERS_INSTALL OFF CACHE BOOL "" )
470
- # exir lets users set the alignment of tensor data embedded in the flatbuffer,
471
- # and some users need an alignment larger than the default, which is typically
472
- # 32.
473
- set (FLATBUFFERS_MAX_ALIGNMENT 1024)
474
-
475
- if (EXECUTORCH_BUILD_FLATC)
476
- if (FLATC_EXECUTABLE)
477
- # We could ignore this, but it could lead to confusion about which `flatc`
478
- # is actually being used.
479
- message (
480
- FATAL_ERROR "May not set both EXECUTORCH_BUILD_FLATC and FLATC_EXECUTABLE"
481
- )
482
- endif ()
483
-
484
- # Build flatc for the *host* to generate files as part of the build step.
485
- include (ExternalProject)
486
- ExternalProject_Add(
487
- flatbuffers
488
- PREFIX ${CMAKE_CURRENT_BINARY_DIR} /third-party/flatbuffers
489
- BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} /third-party/flatbuffers
490
- SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /third-party/flatbuffers
491
- CMAKE_ARGS -DFLATBUFFERS_BUILD_FLATC=ON
492
- -DFLATBUFFERS_BUILD_FLATHASH=${FLATBUFFERS_BUILD_FLATHASH}
493
- -DFLATBUFFERS_BUILD_FLATLIB=${FLATBUFFERS_BUILD_FLATLIB}
494
- -DFLATBUFFERS_BUILD_TESTS=${FLATBUFFERS_BUILD_TESTS}
495
- -DFLATBUFFERS_INSTALL=${FLATBUFFERS_INSTALL}
496
- -DCMAKE_CXX_FLAGS="-DFLATBUFFERS_MAX_ALIGNMENT=${FLATBUFFERS_MAX_ALIGNMENT} "
497
- # If building for iOS, "unset" these variables to rely on the host (macOS) defaults.
498
- $<$<AND :$<BOOL :${CMAKE_TOOLCHAIN_IOS} >,$<BOOL :$<FILTER :${PLATFORM} ,EXCLUDE ,^MAC>>>:-DCMAKE_OSX_SYSROOT=>
499
- INSTALL_COMMAND ""
500
- BUILD_BYPRODUCTS <BINARY_DIR>/flatc
501
- )
502
- ExternalProject_Get_Property(flatbuffers BINARY_DIR)
503
- if (WIN32 )
504
- # flatbuffers does not use CMAKE_BUILD_TYPE. Internally, the build forces Release
505
- # config, but from CMake's perspective the build type is always Debug.
506
- set (FLATC_EXECUTABLE ${BINARY_DIR} /$<CONFIG>/flatc.exe)
507
- elseif (CMAKE_GENERATOR STREQUAL "Xcode" )
508
- set (FLATC_EXECUTABLE ${BINARY_DIR} /$<CONFIG>/flatc)
509
- else ()
510
- set (FLATC_EXECUTABLE ${BINARY_DIR} /flatc)
511
- endif ()
512
- set (FLATC_EXECUTABLE_BUILT_FROM_SOURCE YES )
513
- endif ()
514
-
515
- if (NOT FLATC_EXECUTABLE)
516
- message (
517
- WARNING "FLATC_EXECUTABLE not specified, looking for flatc"
518
- )
519
- find_program (FLATC_EXECUTABLE flatc)
520
-
521
- if (NOT FLATC_EXECUTABLE)
522
- message (FATAL_ERROR "FLATC_EXECUTABLE must be set when EXECUTORCH_BUILD_FLATC is disabled." )
523
- endif ()
524
- endif ()
525
-
526
- add_executable (flatc IMPORTED GLOBAL )
527
- set_target_properties (flatc PROPERTIES IMPORTED_LOCATION ${FLATC_EXECUTABLE} )
528
-
529
- if (FLATC_EXECUTABLE_BUILT_FROM_SOURCE)
530
- add_dependencies (flatc flatbuffers)
531
- endif ()
532
460
533
461
#
534
462
# program_schema: Generated .h files from schema/*.fbs inputs
0 commit comments