Skip to content

Commit dad16ab

Browse files
committed
include library target
1 parent 855bed9 commit dad16ab

File tree

9 files changed

+32
-48
lines changed

9 files changed

+32
-48
lines changed

CMakeLists.txt

+29-14
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,17 @@ cmake_dependent_option(
474474
"NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF
475475
)
476476

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+
477488
if(EXECUTORCH_BUILD_FLATC)
478489
if(FLATC_EXECUTABLE)
479490
# We could ignore this, but it could lead to confusion about which `flatc`
@@ -483,35 +494,39 @@ if(EXECUTORCH_BUILD_FLATC)
483494
)
484495
endif()
485496

497+
# Build flatc for the *host* to generate files as part of the build step.
486498
include(ExternalProject)
487-
488499
ExternalProject_Add(
489500
flatc
490501
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/third-party/flatbuffers
502+
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/third-party/flatbuffers
491503
SOURCE_DIR ${CMAKE_SOURCE_DIR}/third-party/flatbuffers
492504
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}"
501510
INSTALL_COMMAND ""
502511
)
503512
ExternalProject_Get_Property(flatc BINARY_DIR)
504513
set(FLATC_EXECUTABLE ${BINARY_DIR}/flatc)
505-
506514
endif()
507515

508516
if(NOT FLATC_EXECUTABLE)
509517
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"
514519
)
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()
515530
endif()
516531

517532
#

backends/apple/mps/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ if(NOT PYTHON_EXECUTABLE)
2222
resolve_python_executable()
2323
endif()
2424

25-
if(NOT FLATC_EXECUTABLE)
26-
set(FLATC_EXECUTABLE flatc)
27-
endif()
28-
2925
set(_common_compile_options -Wno-deprecated-declarations)
3026
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
3127

backends/qualcomm/CMakeLists.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ if(${ANDROID})
3939
find_library(android_log log)
4040
endif()
4141

42-
if(NOT FLATC_EXECUTABLE)
43-
set(FLATC_EXECUTABLE flatc)
44-
endif()
45-
4642
set(qcir_schema_include_dir ${CMAKE_CURRENT_LIST_DIR}/aot/ir)
4743
set(qcir_schema_output ${qcir_schema_include_dir}/qcir_generated.h)
4844
add_custom_command(
@@ -101,6 +97,7 @@ add_custom_command(
10197
"${_qnn_schema__include_dir}/executorch/backends/qualcomm"
10298
${_qnn_schema__srcs}
10399
WORKING_DIRECTORY ${EXECUTORCH_SOURCE_DIR}
100+
DEPENDS flatc
104101
COMMENT "Generating qnn_schema headers"
105102
VERBATIM
106103
)

backends/vulkan/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ if(NOT PYTHON_EXECUTABLE)
2828
set(PYTHON_EXECUTABLE python3)
2929
endif()
3030

31-
if(NOT FLATC_EXECUTABLE)
32-
set(FLATC_EXECUTABLE flatc)
33-
endif()
34-
3531
# Include this file to access target_link_options_shared_lib This is required to
3632
# provide access to target_link_options_shared_lib which allows libraries to be
3733
# linked with the --whole-archive flag. This is required for libraries that

backends/xnnpack/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ if(NOT CMAKE_CXX_STANDARD)
1818
set(CMAKE_CXX_STANDARD 17)
1919
endif()
2020

21-
if(NOT FLATC_EXECUTABLE)
22-
set(FLATC_EXECUTABLE flatc)
23-
endif()
24-
2521
# Source root directory for executorch.
2622
if(NOT EXECUTORCH_ROOT)
2723
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)

devtools/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ if(NOT PYTHON_EXECUTABLE)
3838
resolve_python_executable()
3939
endif()
4040

41-
if(NOT FLATC_EXECUTABLE)
42-
set(FLATC_EXECUTABLE flatc)
43-
endif()
44-
4541
# Paths to headers generated from the .fbs files. set(_etdump_schemas
4642
# etdump_schema_flatcc.fbs scalar_type.fbs)
4743

examples/apple/mps/CMakeLists.txt

-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ if(NOT CMAKE_CXX_STANDARD)
1818
set(CMAKE_CXX_STANDARD 17)
1919
endif()
2020

21-
if(NOT FLATC_EXECUTABLE)
22-
set(FLATC_EXECUTABLE flatc)
23-
endif()
24-
2521
# Source root directory for executorch.
2622
if(NOT EXECUTORCH_ROOT)
2723
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../../..)

extension/flat_tensor/serialize/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
# cmake-format -i CMakeLists.txt
1010
# ~~~
1111

12-
if(NOT FLATC_EXECUTABLE)
13-
set(FLATC_EXECUTABLE flatc)
14-
endif()
15-
1612
# The include directory that will contain the generated schema headers.
1713
set(_flat_tensor_schema__include_dir "${CMAKE_BINARY_DIR}/extension/flat_tensor/include")
1814
set(_flat_tensor_schema__output_dir "${_flat_tensor_schema__include_dir}/executorch/extension/flat_tensor/serialize")
@@ -49,7 +45,7 @@ function(generate_flat_tensor_schema _schema_srcs _schema_name)
4945
# and some users need an alignment larger than the default, which is typically
5046
# 32.
5147
target_compile_definitions(
52-
${_schema_name} INTERFACE FLATBUFFERS_MAX_ALIGNMENT=1024
48+
${_schema_name} INTERFACE FLATBUFFERS_MAX_ALIGNMENT=${FLATBUFFERS_MAX_ALIGNMENT}
5349
)
5450

5551
target_include_directories(

schema/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@
99
# cmake-format -i CMakeLists.txt
1010
# ~~~
1111

12-
if(NOT FLATC_EXECUTABLE)
13-
set(FLATC_EXECUTABLE flatc)
14-
endif()
15-
1612
# The include directory that will contain the generated schema headers.
1713
set(_program_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include")
1814
set(_program_schema__output_dir "${_program_schema__include_dir}/executorch/schema")
@@ -49,7 +45,7 @@ function(generate_program_schema _schema_srcs _schema_name)
4945
# and some users need an alignment larger than the default, which is typically
5046
# 32.
5147
target_compile_definitions(
52-
${_schema_name} INTERFACE FLATBUFFERS_MAX_ALIGNMENT=1024
48+
${_schema_name} INTERFACE FLATBUFFERS_MAX_ALIGNMENT=${FLATBUFFERS_MAX_ALIGNMENT}
5349
)
5450

5551
target_include_directories(

0 commit comments

Comments
 (0)