Skip to content

Commit 8933140

Browse files
committed
Fix SDK CMake
1 parent 002420e commit 8933140

File tree

7 files changed

+84
-76
lines changed

7 files changed

+84
-76
lines changed

CMakeLists.txt

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# Copyright (c) Meta Platforms, Inc. and affiliates.
2-
# All rights reserved.
1+
# Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
32
#
4-
# This source code is licensed under the BSD-style license found in the
5-
# LICENSE file in the root directory of this source tree.
3+
# This source code is licensed under the BSD-style license found in the LICENSE
4+
# file in the root directory of this source tree.
65

76
#
87
# Simple CMake build system for runtime components.
@@ -87,8 +86,8 @@ if(NOT EXECUTORCH_ENABLE_PROGRAM_VERIFICATION)
8786
add_definitions(-DET_ENABLE_PROGRAM_VERIFICATION=0)
8887
endif()
8988

90-
# -O2: Moderate opt. -ffunction-sections -fdata-sections: breaks function
91-
# and data into sections so they can be properly gc'd. -s: strip symbol.
89+
# -O2: Moderate opt. -ffunction-sections -fdata-sections: breaks function and
90+
# data into sections so they can be properly gc'd. -s: strip symbol.
9291
# -fno-exceptions -fno-rtti: disables exceptions and runtime type.
9392
set(CMAKE_CXX_FLAGS_RELEASE
9493
"-O2 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti")
@@ -136,8 +135,8 @@ option(EXECUTORCH_BUILD_XTENSA_EXAMPLE
136135
"Build the example targeted for the Xtensa Hifi4 DSP" OFF)
137136

138137
# Build mps_executor_runner which depends on MPSGraph framework
139-
option(EXECUTORCH_BUILD_MPS
140-
"Build mps_executor_runner which depends on MPS" OFF)
138+
option(EXECUTORCH_BUILD_MPS "Build mps_executor_runner which depends on MPS"
139+
OFF)
141140

142141
if(NOT BUCK2)
143142
set(BUCK2 buck2)
@@ -198,17 +197,14 @@ endif()
198197
# libraries that it uses, like `gflags`. Disabling this can be helpful when
199198
# cross-compiling, but some required tools that would have been built need to be
200199
# provided directly (via, for example, FLATC_EXECUTABLE).
201-
cmake_dependent_option(
202-
EXECUTORCH_BUILD_HOST_TARGETS "Build host-only targets." ON
203-
"NOT CMAKE_TOOLCHAIN_IOS" OFF)
204-
200+
cmake_dependent_option(EXECUTORCH_BUILD_HOST_TARGETS "Build host-only targets."
201+
ON "NOT CMAKE_TOOLCHAIN_IOS" OFF)
205202

206203
#
207204
# flatc: Flatbuffer commandline tool to generate .h files from .fbs files
208205
#
209-
cmake_dependent_option(
210-
EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON
211-
"NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF)
206+
cmake_dependent_option(EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON
207+
"NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF)
212208

213209
if(EXECUTORCH_BUILD_FLATC)
214210
if(FLATC_EXECUTABLE)
@@ -274,26 +270,25 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable)
274270
# gflags: Commandline flag host library.
275271
#
276272
cmake_dependent_option(EXECUTORCH_BUILD_GFLAGS "Build the gflags library." ON
277-
EXECUTORCH_BUILD_HOST_TARGETS OFF)
273+
EXECUTORCH_BUILD_HOST_TARGETS OFF)
278274
if(EXECUTORCH_BUILD_GFLAGS)
279275
add_subdirectory(third-party/gflags)
280276
endif()
281277

282-
283-
# Install `executorch` library as well as `executorch-config.cmake`
284-
# under ${CMAKE_INSTALL_PREFIX}/
278+
# Install `executorch` library as well as `executorch-config.cmake` under
279+
# ${CMAKE_INSTALL_PREFIX}/
285280
install(
286281
TARGETS executorch
287282
DESTINATION lib
288-
INCLUDES DESTINATION ${_common_include_directories}
289-
)
283+
INCLUDES
284+
DESTINATION ${_common_include_directories})
290285
install(FILES build/executorch-config.cmake DESTINATION lib/cmake/ExecuTorch)
291286

292287
#
293288
# executor_runner: Host tool that demonstrates program execution.
294289
#
295-
cmake_dependent_option(EXECUTORCH_BUILD_EXECUTOR_RUNNER
296-
"Build the executor_runner executable" ON
290+
cmake_dependent_option(
291+
EXECUTORCH_BUILD_EXECUTOR_RUNNER "Build the executor_runner executable" ON
297292
EXECUTORCH_BUILD_HOST_TARGETS OFF)
298293
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
299294
# Baseline libraries that executor_runner will link against.
@@ -324,6 +319,15 @@ if(EXECUTORCH_BUILD_ANDROID_DEMO_APP_JNI)
324319
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/demo-apps/android/jni)
325320
endif()
326321

322+
if(EXECUTORCH_BUILD_SDK)
323+
set(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER
324+
ON
325+
CACHE BOOL "EXECUTORCH_BUILD_EXTENSION_DATA_LOADER" FORCE)
326+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sdk)
327+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/util)
328+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/sdk)
329+
endif()
330+
327331
option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER
328332
"Build the extension/data_loader directory" OFF)
329333
if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
@@ -362,8 +366,7 @@ if(EXECUTORCH_BUILD_COREML)
362366
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/coreml)
363367
else()
364368
message(
365-
FATAL_ERROR "executorch: Building CoreML delegate requires iOS toolchain"
366-
)
369+
FATAL_ERROR "executorch: Building CoreML delegate requires iOS toolchain")
367370
endif()
368371
endif()
369372

@@ -377,12 +380,6 @@ if(EXECUTORCH_BUILD_SIZE_TEST)
377380
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
378381
endif()
379382

380-
if(EXECUTORCH_BUILD_SDK)
381-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sdk)
382-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/util)
383-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/sdk)
384-
endif()
385-
386383
if(EXECUTORCH_BUILD_EXAMPLES)
387384
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples)
388385
endif()

backends/apple/mps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ set(_common_include_directories ${EXECUTORCH_ROOT}/..)
2525

2626
list(TRANSFORM _mps_backend__srcs PREPEND "${EXECUTORCH_ROOT}/")
2727
add_library(mpsdelegate ${_mps_backend__srcs})
28-
target_link_libraries(mpsdelegate PRIVATE ${_executor_runner_libs})
28+
target_link_libraries(mpsdelegate PRIVATE baundled_program ${_executor_runner_libs})
2929
target_include_directories(mpsdelegate
3030
PUBLIC ${_common_include_directories})

backends/apple/mps/setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ python3 -m unittest backends.apple.mps.test.test_mps --verbose -k mv3
6262

6363
```bash
6464
# Build the mps_executor_runner
65-
rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_MPS=1 -DBUCK2=/tmp/buck2 —trace .. && cmake --build . && cd ..
65+
rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_MPS=1 -DEXECUTORCH_BUILD_SDK=ON -DBUCK2=/tmp/buck2 —trace .. && cmake --build . && cd ..
6666
```
6767

6868
***Step 2***. Run the model using the `mps_executor_runner`.

examples/apple/mps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ add_executable(mps_executor_runner ${_mps_executor_runner__srcs})
4646
target_include_directories(
4747
mps_executor_runner INTERFACE ${CMAKE_BINARY_DIR}/schema/include/
4848
${EXECUTORCH_ROOT}/third-party/flatbuffers/include)
49-
target_link_libraries(mps_executor_runner program_schema
49+
target_link_libraries(mps_executor_runner bundled_program program_schema
5050
${_executor_runner_libs}
5151
${mps_executor_runner_libs})
5252
target_compile_options(mps_executor_runner PUBLIC ${_common_compile_options})

examples/apple/mps/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Once we have the model binary file, then let's run it with the ExecuTorch runtim
2828

2929
```bash
3030
# Build the mps_executor_runner
31-
(rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_MPS=1 -DBUCK2=/tmp/buck2 —trace .. && cd ..)
31+
(rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_MPS=1 -DEXECUTORCH_BUILD_SDK=ON -DBUCK2=/tmp/buck2 —trace .. && cd ..)
3232
cmake --build cmake-out -j9
3333

3434
# Run the mv2 generated model using the mps_executor_runner

sdk/CMakeLists.txt

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# Copyright (c) Meta Platforms, Inc. and affiliates.
2-
# All rights reserved.
1+
# Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved.
32
#
4-
# This source code is licensed under the BSD-style license found in the
5-
# LICENSE file in the root directory of this source tree.
3+
# This source code is licensed under the BSD-style license found in the LICENSE
4+
# file in the root directory of this source tree.
65

76
# Please this file formatted by running:
87
# ~~~
@@ -30,20 +29,25 @@ if(NOT EXECUTORCH_ROOT)
3029
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)
3130
endif()
3231

32+
if(NOT FLATC_EXECUTABLE)
33+
set(FLATC_EXECUTABLE flatc)
34+
endif()
35+
3336
# Paths to headers generated from the .fbs files. set(_etdump_schemas
3437
# etdump_schema_flatcc.fbs scalar_type.fbs)
3538

36-
set(_etdump_schema__srcs
37-
${CMAKE_CURRENT_SOURCE_DIR}/etdump/etdump_schema_flatcc.fbs
38-
${CMAKE_CURRENT_SOURCE_DIR}/etdump/scalar_type.fbs)
39-
39+
set(_etdump_schema_names "etdump_schema_flatcc.fbs" "scalar_type.fbs")
40+
set(_bundled_input_schema_names "bundled_program_schema.fbs" "scalar_type.fbs")
4041

41-
set(_bundled_program_schema_dir
42-
${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/schema)
42+
foreach(schema_file ${_etdump_schema_names})
43+
list(APPEND _etdump_schema__srcs
44+
"${CMAKE_CURRENT_SOURCE_DIR}/etdump/${schema_file}")
45+
endforeach()
4346

44-
set(_bundled_program_schema__srcs
45-
${_bundled_program_schema_dir}/bundled_program_schema.fbs
46-
${_bundled_program_schema_dir}/scalar_type.fbs)
47+
foreach(schema_file ${_bundled_input_schema_names})
48+
list(APPEND _bundled_program_schema__srcs
49+
"${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/schema/${schema_file}")
50+
endforeach()
4751

4852
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc
4953
${CMAKE_BINARY_DIR}/third-party/flatcc)
@@ -53,9 +57,9 @@ include(ExternalProject)
5357

5458
# The include directory that will contain the generated schema headers.
5559
set(_program_schema__include_dir "${CMAKE_BINARY_DIR}/sdk/include")
60+
set(_bundled_schema__include_dir "${CMAKE_BINARY_DIR}/sdk/bundled_program")
5661

57-
# Add the host project
58-
# lint_cmake: -readability/wonkycase
62+
# Add the host project lint_cmake: -readability/wonkycase
5963
ExternalProject_Add(
6064
flatcc_project
6165
PREFIX ${CMAKE_BINARY_DIR}/_host_build
@@ -65,30 +69,32 @@ ExternalProject_Add(
6569
)
6670

6771
set(_etdump_schema__outputs)
68-
foreach(fbs_file ${_etdump_schema__srcs})
69-
string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}")
72+
foreach(fbs_file ${_etdump_schema_names})
73+
string(REGEX REPLACE "[.]fbs$" "_reader.h" generated "${fbs_file}")
74+
list(APPEND _etdump_schema__outputs
75+
"${_program_schema__include_dir}/executorch/sdk/etdump/${generated}")
76+
string(REGEX REPLACE "[.]fbs$" "_builder.h" generated "${fbs_file}")
7077
list(APPEND _etdump_schema__outputs
71-
"${_program_schema__include_dir}/${generated}")
78+
"${_program_schema__include_dir}/executorch/sdk/etdump/${generated}")
7279
endforeach()
7380

7481
set(_bundled_program_schema__outputs)
75-
foreach(fbs_file ${_bundled_program_schema__srcs})
82+
foreach(fbs_file ${_bundled_input_schema_names})
7683
string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}")
77-
list(APPEND _bundled_program_schema__outputs
78-
"${_program_schema__include_dir}/${generated}")
84+
list(
85+
APPEND
86+
_bundled_program_schema__outputs
87+
"${_bundled_schema__include_dir}/executorch/sdk/bundled_program/schema/${generated}"
88+
)
7989
endforeach()
8090

8191
add_library(etdump_schema INTERFACE ${_etdump_schema__outputs})
82-
add_library(bundled_program_schema
83-
INTERFACE ${_bundled_program_schema__outputs})
92+
add_library(bundled_program_schema INTERFACE
93+
${_bundled_program_schema__outputs})
8494

8595
# Ensure the host tool is built before the main project
8696
add_dependencies(etdump_schema flatcc_cli)
8797

88-
message("Debug _etdump_schema__outputs: ${_etdump_schema__outputs}")
89-
message("Debug _bundled_program_schema__outputs:\
90-
${_bundled_program_schema__outputs}")
91-
9298
file(MAKE_DIRECTORY ${_program_schema__include_dir}/executorch/sdk/etdump)
9399
file(MAKE_DIRECTORY
94100
${_program_schema__include_dir}/executorch/sdk/bundled_program)
@@ -104,23 +110,33 @@ add_custom_command(
104110
COMMENT "Generating etdump headers"
105111
VERBATIM)
106112

113+
add_library(etdump ${CMAKE_CURRENT_SOURCE_DIR}/etdump/etdump_flatcc.cpp)
114+
target_link_libraries(
115+
etdump
116+
PUBLIC etdump_schema
117+
PRIVATE executorch)
118+
107119
add_custom_command(
108120
OUTPUT ${_bundled_program_schema__outputs}
109121
COMMAND
110-
${CMAKE_SOURCE_DIR}/third-party/flatcc/bin/flatcc -cwr -o
111-
${_program_schema__include_dir}/executorch/sdk/bundled_program
122+
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --gen-mutable --scoped-enums -o
123+
"${_bundled_schema__include_dir}/executorch/sdk/bundled_program/schema"
112124
${_bundled_program_schema__srcs}
113125
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/sdk
114-
DEPENDS flatcc_project
126+
DEPENDS ${FLATC_EXECUTABLE} ${_bundled_program_schema__srcs}
115127
COMMENT "Generating bundled_program headers"
116128
VERBATIM)
117129

118-
target_include_directories(
119-
etdump PUBLIC ${_program_schema__include_dir}
120-
${CMAKE_SOURCE_DIR}/third-party/flatcc/include)
130+
# add_library(bundled_program INTERFACE ${_bundled_program_schema__outputs})
131+
add_library(bundled_program
132+
${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/bundled_program.cpp)
133+
target_link_libraries(bundled_program executorch bundled_program_schema)
121134

122135
set_target_properties(bundled_program PROPERTIES LINKER_LANGUAGE CXX)
123136
target_include_directories(
124-
bundled_program
125-
INTERFACE ${_program_schema__include_dir}
126-
${EXECUTORCH_ROOT}/third-party/flatbuffers/include)
137+
bundled_program PUBLIC ${_bundled_schema__include_dir}
138+
${EXECUTORCH_ROOT}/third-party/flatbuffers/include)
139+
140+
target_include_directories(
141+
etdump PUBLIC ${_program_schema__include_dir}
142+
${CMAKE_SOURCE_DIR}/third-party/flatcc/include)

util/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,3 @@
33
#
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
6-
7-
add_library(bundled_program
8-
${CMAKE_CURRENT_SOURCE_DIR}/bundled_program_verification.cpp)
9-
10-
target_link_libraries(bundled_program executorch bundled_schema)

0 commit comments

Comments
 (0)