Skip to content

Commit 2718dd4

Browse files
authored
cmake flatcc build issue
Differential Revision: D60940355 Pull Request resolved: #4541
1 parent 91252e7 commit 2718dd4

File tree

2 files changed

+28
-46
lines changed

2 files changed

+28
-46
lines changed

examples/apple/coreml/scripts/build_executor_runner.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rm -rf "$CMAKE_BUILD_DIR_PATH"
2929
# Build executorch
3030
echo "ExecuTorch: Building executorch"
3131
cmake "$EXECUTORCH_ROOT_PATH" -B"$CMAKE_BUILD_DIR_PATH" \
32+
-DCMAKE_BUILD_TYPE=Release \
3233
-DCMAKE_TOOLCHAIN_FILE="$IOS_TOOLCHAIN_PATH" \
3334
-DPLATFORM=MAC_UNIVERSAL \
3435
-DDEPLOYMENT_TARGET=13.0 \

sdk/CMakeLists.txt

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,37 @@ if(EXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT)
8787
# Add the host project. We build this separately so that we can generate
8888
# headers on the host during the build, even if we're cross-compiling the
8989
# flatcc runtime to a different architecture.
90-
91-
# lint_cmake: -readability/wonkycase
92-
ExternalProject_Add(
93-
flatcc_project
94-
PREFIX ${CMAKE_BINARY_DIR}/_host_build
95-
SOURCE_DIR ${_flatcc_source_dir}
96-
BINARY_DIR ${CMAKE_BINARY_DIR}/_host_build
97-
CMAKE_CACHE_ARGS
98-
-DFLATCC_TEST:BOOL=OFF -DFLATCC_REFLECTION:BOOL=OFF
99-
# See above comment about POSITION_INDEPENDENT_CODE.
100-
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=ON
101-
INSTALL_COMMAND "" # Prevent the install step
90+
execute_process(
91+
COMMAND ${CMAKE_COMMAND} ${_flatcc_source_dir}
92+
-DFLATCC_TEST=OFF -DFLATCC_REFLECTION=OFF
93+
# See above comment about POSITION_INDEPENDENT_CODE.
94+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
95+
-B${CMAKE_BINARY_DIR}/_host_build
96+
)
97+
execute_process(
98+
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/_host_build
99+
)
100+
set(_etdump_schema_gen_dep)
101+
# TODO(dbort): flatcc installs its files directly in its source directory
102+
# instead of under CMAKE_BINARY_DIR, and it has no options to avoid doing
103+
# this. We build flatcc twice in the executorch build: once to get the
104+
# `flatcc` host commandline tool, and once to get the (potentially
105+
# cross-compiled) target runtime library. The host build will put its outputs
106+
# in the source tree, making the cross-compiling target build think that the
107+
# outputs have already been built. It will then try to link against the
108+
# host-architecture libraries, failing when cross-compiling. To work around
109+
# this, delete the host outputs after running this command (which only runs
110+
# when setting up the cmake files, not when actually building). This leaves
111+
# room for the target build to put its own files in the source tree. We should
112+
# try to remove this hack, ideally by submitting an upstream PR that adds an
113+
# option to change the installation location.
114+
set(_etdump_schema_cleanup_paths ${_flatcc_source_dir}/bin/*
115+
${_flatcc_source_dir}/lib/*
102116
)
103-
set(_etdump_schema_gen_dep flatcc_project)
104117
else()
105118
# If we're not cross-compiling, we can just use the plain commandline target.
106119
set(_etdump_schema_gen_dep flatcc_cli)
120+
set(_etdump_schema_cleanup_paths "")
107121
endif()
108122

109123
set(_etdump_schema__outputs)
@@ -134,42 +148,11 @@ add_library(
134148
bundled_program_schema INTERFACE ${_bundled_program_schema__outputs}
135149
)
136150

137-
# Ensure the host tool is built before the main project
138-
add_dependencies(etdump_schema flatcc_cli)
139-
140151
file(MAKE_DIRECTORY ${_program_schema__include_dir}/executorch/sdk/etdump)
141152
file(MAKE_DIRECTORY
142153
${_program_schema__include_dir}/executorch/sdk/bundled_program
143154
)
144155

145-
if(EXECUTORCH_SEPARATE_FLATCC_HOST_PROJECT)
146-
# If we cross-compiling, we need to use the version of the commandline tool
147-
# built for the host.
148-
set(_etdump_schema_gen_dep flatcc_project)
149-
150-
# TODO(dbort): flatcc installs its files directly in its source directory
151-
# instead of under CMAKE_BINARY_DIR, and it has no options to avoid doing
152-
# this. We build flatcc twice in the executorch build: once to get the
153-
# `flatcc` host commandline tool, and once to get the (potentially
154-
# cross-compiled) target runtime library. The host build will put its outputs
155-
# in the source tree, making the cross-compiling target build think that the
156-
# outputs have already been built. It will then try to link against the
157-
# host-architecture libraries, failing when cross-compiling. To work around
158-
# this, delete the host outputs after running this command (which only runs
159-
# when setting up the cmake files, not when actually building). This leaves
160-
# room for the target build to put its own files in the source tree. We should
161-
# try to remove this hack, ideally by submitting an upstream PR that adds an
162-
# option to change the installation location.
163-
set(_etdump_schema_cleanup_paths ${_flatcc_source_dir}/bin/*
164-
${_flatcc_source_dir}/lib/*
165-
)
166-
else()
167-
# If we're not cross-compiling we can use the plain commandline target, and we
168-
# don't need to delete any files.
169-
set(_etdump_schema_gen_dep flatcc_cli)
170-
set(_etdump_schema_cleanup_paths "")
171-
endif()
172-
173156
add_custom_command(
174157
OUTPUT ${_etdump_schema__outputs}
175158
COMMAND
@@ -180,10 +163,8 @@ add_custom_command(
180163
${_program_schema__include_dir}/executorch/sdk/etdump
181164
${_etdump_schema__srcs}
182165
COMMAND rm -f ${_etdump_schema_cleanup_paths}
183-
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/sdk
184166
DEPENDS ${_etdump_schema_gen_dep}
185167
COMMENT "Generating etdump headers"
186-
VERBATIM
187168
)
188169

189170
add_library(

0 commit comments

Comments
 (0)