Skip to content

Commit 30d915a

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Add an option to specify an existing flatbuffers compiler for cmake build. (#365)
Summary: Pull Request resolved: #365 Cmake Xcode genrator creates an Xcode project for Executorch where some targets that require codegen steps become Run script build phases in Xcode, and some of them use `flatc` directly assuming it's available via $PATH, whereas it's not installed on MacOS by default. We can't use the one we build as a dependency either because there's no clear way to point to it for such Run script build phase (e.g. $<TARGET_FILE:flatc> provides a path that includes an Xcode own env var ${EFFECTIVE_PLATFORM_NAME} which is not possible to set when we generate the project with cmake). So here we'll follow the same approach as we already have for $PYTHON_EXCUTABLE and just pass a path to `flatc` binary too as one of the arguments to cmake. Reviewed By: digantdesai, dbort Differential Revision: D49324851 fbshipit-source-id: 2cdebb0404e4bfbbc610143fb00138ffcdd4fb82
1 parent e04d9ba commit 30d915a

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

CMakeLists.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,15 @@ option(EXECUTORCH_BUILD_XNNPACK
8787
"Build xnn_executor_runner which depends on XNNPACK" OFF)
8888

8989
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
90+
9091
if(NOT CMAKE_CXX_STANDARD)
9192
set(CMAKE_CXX_STANDARD 17)
9293
endif()
94+
9395
if(NOT BUCK2)
9496
set(BUCK2 buck2)
9597
endif()
98+
9699
if(NOT PYTHON_EXECUTABLE)
97100
set(PYTHON_EXECUTABLE python3)
98101
endif()
@@ -126,12 +129,15 @@ include(${EXECUTORCH_SRCS_FILE})
126129
# flatc: Flatbuffer commandline tool to generate .h files from .fbs files
127130
#
128131

129-
option(FLATBUFFERS_BUILD_FLATC "" ON)
130-
option(FLATBUFFERS_BUILD_FLATHASH "" OFF)
131-
option(FLATBUFFERS_BUILD_FLATLIB "" OFF)
132-
option(FLATBUFFERS_BUILD_TESTS "" OFF)
133-
option(FLATBUFFERS_INSTALL "" OFF)
134-
add_subdirectory(third-party/flatbuffers)
132+
if(NOT FLATC_EXECUTABLE)
133+
set(FLATC_EXECUTABLE flatc)
134+
option(FLATBUFFERS_BUILD_FLATC "" ON)
135+
option(FLATBUFFERS_BUILD_FLATHASH "" OFF)
136+
option(FLATBUFFERS_BUILD_FLATLIB "" OFF)
137+
option(FLATBUFFERS_BUILD_TESTS "" OFF)
138+
option(FLATBUFFERS_INSTALL "" OFF)
139+
add_subdirectory(third-party/flatbuffers)
140+
endif()
135141

136142
#
137143
# gflags: Commandline flag libgrary

backends/xnnpack/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212
cmake_minimum_required(VERSION 3.19)
1313

1414
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
15+
1516
if(NOT CMAKE_CXX_STANDARD)
1617
set(CMAKE_CXX_STANDARD 17)
1718
endif()
1819

1920
if(NOT PYTHON_EXECUTABLE)
2021
set(PYTHON_EXECUTABLE python3)
2122
endif()
23+
24+
if(NOT FLATC_EXECUTABLE)
25+
set(FLATC_EXECUTABLE flatc)
26+
endif()
27+
2228
# Source root directory for executorch.
2329
if(NOT EXECUTORCH_ROOT)
2430
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
@@ -43,7 +49,7 @@ endforeach()
4349
add_custom_command(
4450
OUTPUT ${_xnnpack_schema__outputs}
4551
COMMAND
46-
flatc --cpp --cpp-std c++11 --scoped-enums -o
52+
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --scoped-enums -o
4753
"${_xnnpack_schema__include_dir}/executorch/backends/xnnpack"
4854
${_xnnpack_schema__srcs}
4955
WORKING_DIRECTORY ${EXECUTORCH_ROOT}

build/Utils.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function(executorch_print_configuration_summary)
1818
message(STATUS " CMAKE_CXX_STANDARD : ${CMAKE_CXX_STANDARD}")
1919
message(STATUS " CMAKE_CXX_COMPILER_ID : ${CMAKE_CXX_COMPILER_ID}")
2020
message(STATUS " CMAKE_TOOLCHAIN_FILE : ${CMAKE_TOOLCHAIN_FILE}")
21+
message(STATUS " PYTHON_EXECUTABLE : ${PYTHON_EXECUTABLE}")
22+
message(STATUS " FLATC_EXECUTABLE : ${FLATC_EXECUTABLE}")
2123
message(STATUS " FLATBUFFERS_BUILD_FLATC : ${FLATBUFFERS_BUILD_FLATC}")
2224
message(
2325
STATUS " FLATBUFFERS_BUILD_FLATHASH : ${FLATBUFFERS_BUILD_FLATHASH}")

schema/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
# cmake-format --first-comment-is-literal=True CMakeLists.txt
1010
# ~~~
1111

12+
if(NOT FLATC_EXECUTABLE)
13+
set(FLATC_EXECUTABLE flatc)
14+
endif()
15+
1216
# The include directory that will contain the generated schema headers.
1317
set(_program_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include")
1418

@@ -31,13 +35,13 @@ endforeach()
3135
add_custom_command(
3236
OUTPUT ${_program_schema__outputs}
3337
COMMAND
34-
flatc --cpp --cpp-std c++11 --gen-mutable --scoped-enums
38+
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --gen-mutable --scoped-enums
3539
# Add a subdirectory to the include dir so the files can be included as
3640
# <executorch/schema/x_generated.h>
3741
-o "${_program_schema__include_dir}/executorch/schema"
3842
${_program_schema__srcs}
3943
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
40-
DEPENDS flatc ${_program_schema__srcs}
44+
DEPENDS ${FLATC_EXECUTABLE} ${_program_schema__srcs}
4145
COMMENT "Generating program_schema headers"
4246
VERBATIM)
4347

0 commit comments

Comments
 (0)