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