Skip to content

Commit 0276385

Browse files
tarun292facebook-github-bot
authored andcommitted
Fix SDK CMake (#1271)
Summary: Pull Request resolved: #1271 Reviewed By: cccclai Differential Revision: D51512725 Pulled By: tarun292
1 parent cf17b67 commit 0276385

File tree

7 files changed

+84
-70
lines changed

7 files changed

+84
-70
lines changed

CMakeLists.txt

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ if(NOT EXECUTORCH_ENABLE_PROGRAM_VERIFICATION)
8787
add_definitions(-DET_ENABLE_PROGRAM_VERIFICATION=0)
8888
endif()
8989

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.
90+
# -O2: Moderate opt. -ffunction-sections -fdata-sections: breaks function and
91+
# data into sections so they can be properly gc'd. -s: strip symbol.
9292
# -fno-exceptions -fno-rtti: disables exceptions and runtime type.
9393
set(CMAKE_CXX_FLAGS_RELEASE
9494
"-O2 -ffunction-sections -fdata-sections -fno-exceptions -fno-rtti")
@@ -136,8 +136,8 @@ option(EXECUTORCH_BUILD_XTENSA_EXAMPLE
136136
"Build the example targeted for the Xtensa Hifi4 DSP" OFF)
137137

138138
# Build mps_executor_runner which depends on MPSGraph framework
139-
option(EXECUTORCH_BUILD_MPS
140-
"Build mps_executor_runner which depends on MPS" OFF)
139+
option(EXECUTORCH_BUILD_MPS "Build mps_executor_runner which depends on MPS"
140+
OFF)
141141

142142
if(NOT BUCK2)
143143
set(BUCK2 buck2)
@@ -198,17 +198,14 @@ endif()
198198
# libraries that it uses, like `gflags`. Disabling this can be helpful when
199199
# cross-compiling, but some required tools that would have been built need to be
200200
# 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-
201+
cmake_dependent_option(EXECUTORCH_BUILD_HOST_TARGETS "Build host-only targets."
202+
ON "NOT CMAKE_TOOLCHAIN_IOS" OFF)
205203

206204
#
207205
# flatc: Flatbuffer commandline tool to generate .h files from .fbs files
208206
#
209-
cmake_dependent_option(
210-
EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON
211-
"NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF)
207+
cmake_dependent_option(EXECUTORCH_BUILD_FLATC "Build the flatc executable." ON
208+
"NOT FLATC_EXECUTABLE;EXECUTORCH_BUILD_HOST_TARGETS" OFF)
212209

213210
if(EXECUTORCH_BUILD_FLATC)
214211
if(FLATC_EXECUTABLE)
@@ -274,26 +271,25 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/portable)
274271
# gflags: Commandline flag host library.
275272
#
276273
cmake_dependent_option(EXECUTORCH_BUILD_GFLAGS "Build the gflags library." ON
277-
EXECUTORCH_BUILD_HOST_TARGETS OFF)
274+
EXECUTORCH_BUILD_HOST_TARGETS OFF)
278275
if(EXECUTORCH_BUILD_GFLAGS)
279276
add_subdirectory(third-party/gflags)
280277
endif()
281278

282-
283-
# Install `executorch` library as well as `executorch-config.cmake`
284-
# under ${CMAKE_INSTALL_PREFIX}/
279+
# Install `executorch` library as well as `executorch-config.cmake` under
280+
# ${CMAKE_INSTALL_PREFIX}/
285281
install(
286282
TARGETS executorch
287283
DESTINATION lib
288-
INCLUDES DESTINATION ${_common_include_directories}
289-
)
284+
INCLUDES
285+
DESTINATION ${_common_include_directories})
290286
install(FILES build/executorch-config.cmake DESTINATION lib/cmake/ExecuTorch)
291287

292288
#
293289
# executor_runner: Host tool that demonstrates program execution.
294290
#
295-
cmake_dependent_option(EXECUTORCH_BUILD_EXECUTOR_RUNNER
296-
"Build the executor_runner executable" ON
291+
cmake_dependent_option(
292+
EXECUTORCH_BUILD_EXECUTOR_RUNNER "Build the executor_runner executable" ON
297293
EXECUTORCH_BUILD_HOST_TARGETS OFF)
298294
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
299295
# Baseline libraries that executor_runner will link against.
@@ -324,6 +320,15 @@ if(EXECUTORCH_BUILD_ANDROID_DEMO_APP_JNI)
324320
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/demo-apps/android/jni)
325321
endif()
326322

323+
if(EXECUTORCH_BUILD_SDK)
324+
set(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER
325+
ON
326+
CACHE BOOL "EXECUTORCH_BUILD_EXTENSION_DATA_LOADER" FORCE)
327+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/sdk)
328+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/util)
329+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/sdk)
330+
endif()
331+
327332
option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER
328333
"Build the extension/data_loader directory" OFF)
329334
if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
@@ -362,8 +367,7 @@ if(EXECUTORCH_BUILD_COREML)
362367
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/coreml)
363368
else()
364369
message(
365-
FATAL_ERROR "executorch: Building CoreML delegate requires iOS toolchain"
366-
)
370+
FATAL_ERROR "executorch: Building CoreML delegate requires iOS toolchain")
367371
endif()
368372
endif()
369373

@@ -377,12 +381,6 @@ if(EXECUTORCH_BUILD_SIZE_TEST)
377381
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test)
378382
endif()
379383

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-
386384
if(EXECUTORCH_BUILD_EXAMPLES)
387385
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples)
388386
endif()

backends/apple/mps/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
2-
# Copyright (c) 2023 Apple Inc. All rights reserved.
3-
# Provided subject to the LICENSE file in the top level directory.
2+
# Copyright (c) 2023 Apple Inc. All rights reserved. Provided subject to the
3+
# LICENSE file in the top level directory.
44
#
55

66
cmake_minimum_required(VERSION 3.19)
@@ -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})
29-
target_include_directories(mpsdelegate
30-
PUBLIC ${_common_include_directories})
28+
target_link_libraries(mpsdelegate PRIVATE baundled_program
29+
${_executor_runner_libs})
30+
target_include_directories(mpsdelegate 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: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,25 @@ if(NOT EXECUTORCH_ROOT)
3030
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..)
3131
endif()
3232

33+
if(NOT FLATC_EXECUTABLE)
34+
set(FLATC_EXECUTABLE flatc)
35+
endif()
36+
3337
# Paths to headers generated from the .fbs files. set(_etdump_schemas
3438
# etdump_schema_flatcc.fbs scalar_type.fbs)
3539

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-
40+
set(_etdump_schema_names "etdump_schema_flatcc.fbs" "scalar_type.fbs")
41+
set(_bundled_input_schema_names "bundled_program_schema.fbs" "scalar_type.fbs")
4042

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

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

4853
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/flatcc
4954
${CMAKE_BINARY_DIR}/third-party/flatcc)
@@ -53,6 +58,7 @@ include(ExternalProject)
5358

5459
# The include directory that will contain the generated schema headers.
5560
set(_program_schema__include_dir "${CMAKE_BINARY_DIR}/sdk/include")
61+
set(_bundled_schema__include_dir "${CMAKE_BINARY_DIR}/sdk/bundled_program")
5662

5763
# Add the host project
5864
# lint_cmake: -readability/wonkycase
@@ -65,30 +71,33 @@ ExternalProject_Add(
6571
)
6672

6773
set(_etdump_schema__outputs)
68-
foreach(fbs_file ${_etdump_schema__srcs})
69-
string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}")
74+
foreach(fbs_file ${_etdump_schema_names})
75+
string(REGEX REPLACE "[.]fbs$" "_reader.h" generated "${fbs_file}")
76+
list(APPEND _etdump_schema__outputs
77+
"${_program_schema__include_dir}/executorch/sdk/etdump/${generated}")
78+
string(REGEX REPLACE "[.]fbs$" "_builder.h" generated "${fbs_file}")
7079
list(APPEND _etdump_schema__outputs
71-
"${_program_schema__include_dir}/${generated}")
80+
"${_program_schema__include_dir}/executorch/sdk/etdump/${generated}")
7281
endforeach()
7382

83+
# lint_cmake: -linelength
7484
set(_bundled_program_schema__outputs)
75-
foreach(fbs_file ${_bundled_program_schema__srcs})
85+
foreach(fbs_file ${_bundled_input_schema_names})
7686
string(REGEX REPLACE "[.]fbs$" "_generated.h" generated "${fbs_file}")
77-
list(APPEND _bundled_program_schema__outputs
78-
"${_program_schema__include_dir}/${generated}")
87+
list(
88+
APPEND
89+
_bundled_program_schema__outputs
90+
"${_bundled_schema__include_dir}/executorch/sdk/bundled_program/schema/${generated}"
91+
)
7992
endforeach()
8093

8194
add_library(etdump_schema INTERFACE ${_etdump_schema__outputs})
82-
add_library(bundled_program_schema
83-
INTERFACE ${_bundled_program_schema__outputs})
95+
add_library(bundled_program_schema INTERFACE
96+
${_bundled_program_schema__outputs})
8497

8598
# Ensure the host tool is built before the main project
8699
add_dependencies(etdump_schema flatcc_cli)
87100

88-
message("Debug _etdump_schema__outputs: ${_etdump_schema__outputs}")
89-
message("Debug _bundled_program_schema__outputs:\
90-
${_bundled_program_schema__outputs}")
91-
92101
file(MAKE_DIRECTORY ${_program_schema__include_dir}/executorch/sdk/etdump)
93102
file(MAKE_DIRECTORY
94103
${_program_schema__include_dir}/executorch/sdk/bundled_program)
@@ -104,23 +113,35 @@ add_custom_command(
104113
COMMENT "Generating etdump headers"
105114
VERBATIM)
106115

116+
add_library(etdump ${CMAKE_CURRENT_SOURCE_DIR}/etdump/etdump_flatcc.cpp
117+
${CMAKE_CURRENT_SOURCE_DIR}/etdump/emitter.cpp)
118+
119+
target_link_libraries(
120+
etdump
121+
PUBLIC etdump_schema
122+
PRIVATE executorch)
123+
107124
add_custom_command(
108125
OUTPUT ${_bundled_program_schema__outputs}
109126
COMMAND
110-
${CMAKE_SOURCE_DIR}/third-party/flatcc/bin/flatcc -cwr -o
111-
${_program_schema__include_dir}/executorch/sdk/bundled_program
127+
${FLATC_EXECUTABLE} --cpp --cpp-std c++11 --gen-mutable --scoped-enums -o
128+
"${_bundled_schema__include_dir}/executorch/sdk/bundled_program/schema"
112129
${_bundled_program_schema__srcs}
113130
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/sdk
114-
DEPENDS flatcc_project
131+
DEPENDS ${FLATC_EXECUTABLE} ${_bundled_program_schema__srcs}
115132
COMMENT "Generating bundled_program headers"
116133
VERBATIM)
117134

118-
target_include_directories(
119-
etdump PUBLIC ${_program_schema__include_dir}
120-
${CMAKE_SOURCE_DIR}/third-party/flatcc/include)
135+
# add_library(bundled_program INTERFACE ${_bundled_program_schema__outputs})
136+
add_library(bundled_program
137+
${CMAKE_CURRENT_SOURCE_DIR}/bundled_program/bundled_program.cpp)
138+
target_link_libraries(bundled_program executorch bundled_program_schema)
121139

122140
set_target_properties(bundled_program PROPERTIES LINKER_LANGUAGE CXX)
123141
target_include_directories(
124-
bundled_program
125-
INTERFACE ${_program_schema__include_dir}
126-
${EXECUTORCH_ROOT}/third-party/flatbuffers/include)
142+
bundled_program PUBLIC ${_bundled_schema__include_dir}
143+
${EXECUTORCH_ROOT}/third-party/flatbuffers/include)
144+
145+
target_include_directories(
146+
etdump PUBLIC ${_program_schema__include_dir}
147+
${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)