5
5
# This source code is licensed under the BSD-style license found in the
6
6
# LICENSE file in the root directory of this source tree.
7
7
8
- cmake_minimum_required (VERSION 3.19)
9
-
10
- project (executorch_coreml_backend)
11
-
12
- if (NOT CMAKE_CXX_STANDARD)
13
- set (CMAKE_CXX_STANDARD 17)
14
- endif ()
15
-
16
- # Source root directory for executorch.
17
- if (NOT EXECUTORCH_ROOT)
18
- set (EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR} /../../..)
8
+ if (APPLE )
9
+ find_library (FOUNDATION_FRAMEWORK Foundation REQUIRED)
10
+ find_library (ACCELERATE_FRAMEWORK Accelerate REQUIRED)
11
+ find_library (COREML_FRAMEWORK CoreML REQUIRED)
12
+ find_library (SQLITE_LIBRARY sqlite3 REQUIRED)
19
13
endif ()
20
14
21
15
if (EXECUTORCH_BUILD_DEVTOOLS)
22
16
# protobuf requires frtti
23
17
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -frtti" )
24
18
endif ()
25
19
26
- option (COREML_BUILD_EXECUTOR_RUNNER "Build CoreML executor runner." OFF )
27
-
28
- # inmemoryfs sources
29
- set (INMEMORYFS_SOURCES
30
- runtime/inmemoryfs/inmemory_filesystem.cpp
31
- runtime/inmemoryfs/inmemory_filesystem_utils.mm
32
- runtime/inmemoryfs/memory_buffer.cpp
33
- runtime/inmemoryfs/memory_stream.cpp
34
- runtime/inmemoryfs/reversed_memory_stream.cpp
35
- )
36
-
37
20
# kvstore sources
38
21
set (KVSTORE_SOURCES
39
22
runtime/kvstore/database.cpp runtime/kvstore/json_key_value_store.cpp
@@ -61,9 +44,6 @@ set(DELEGATE_SOURCES
61
44
runtime/delegate/serde_json.mm
62
45
)
63
46
64
- # util sources
65
- set (UTIL_SOURCES runtime/util/json_util.cpp runtime/util/objc_json_serde.mm)
66
-
67
47
# sdk sources
68
48
set (SDK_SOURCES
69
49
runtime/sdk/ETCoreMLModelAnalyzer.mm
@@ -116,12 +96,19 @@ set(PROTOBUF_SOURCES
116
96
runtime/sdk/format/WordTagger.pb.cc
117
97
)
118
98
119
- find_library (FOUNDATION_FRAMEWORK Foundation)
120
-
121
99
# CoreML util
100
+
101
+ set (UTIL_SOURCES runtime/util/json_util.cpp)
102
+ if (APPLE )
103
+ list (APPEND UTIL_SOURCES runtime/util/objc_json_serde.mm)
104
+ endif ()
105
+
122
106
add_library (coreml_util ${UTIL_SOURCES} )
123
107
target_include_directories (coreml_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /runtime/util)
124
- target_link_libraries (coreml_util PRIVATE ${FOUNDATION_FRAMEWORK} )
108
+ if (APPLE )
109
+ target_link_libraries (coreml_util PRIVATE ${FOUNDATION_FRAMEWORK} )
110
+ endif ()
111
+ target_compile_options (coreml_util PUBLIC -fPIC)
125
112
126
113
install (
127
114
TARGETS coreml_util
@@ -131,9 +118,24 @@ install(
131
118
)
132
119
133
120
# CoreML inmemoryfs
121
+
122
+ set (
123
+ INMEMORYFS_SOURCES
124
+ runtime/inmemoryfs/inmemory_filesystem.cpp
125
+ runtime/inmemoryfs/memory_buffer.cpp
126
+ runtime/inmemoryfs/memory_stream.cpp
127
+ runtime/inmemoryfs/reversed_memory_stream.cpp
128
+ )
129
+ if (APPLE )
130
+ list (APPEND INMEMORYFS_SOURCES runtime/inmemoryfs/inmemory_filesystem_utils.mm)
131
+ endif ()
132
+
134
133
add_library (coreml_inmemoryfs ${INMEMORYFS_SOURCES} )
135
134
target_include_directories (coreml_inmemoryfs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /runtime/inmemoryfs)
136
- target_link_libraries (coreml_inmemoryfs PRIVATE coreml_util ${FOUNDATION_FRAMEWORK} )
135
+ if (APPLE )
136
+ target_link_libraries (coreml_inmemoryfs PRIVATE coreml_util ${FOUNDATION_FRAMEWORK} )
137
+ endif ()
138
+ target_compile_options (coreml_inmemoryfs PUBLIC -fPIC)
137
139
138
140
install (
139
141
TARGETS coreml_inmemoryfs
@@ -142,104 +144,101 @@ install(
142
144
DESTINATION ${_common_include_directories}
143
145
)
144
146
145
- # Define the delegate library
146
- add_library (coremldelegate)
147
- target_sources (coremldelegate PRIVATE ${KVSTORE_SOURCES} ${DELEGATE_SOURCES} )
148
-
149
- target_include_directories (
150
- coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /runtime/include
151
- )
152
- target_include_directories (
153
- coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /runtime/kvstore
154
- )
155
- target_include_directories (
156
- coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /runtime/delegate
157
- )
158
- target_include_directories (coremldelegate PRIVATE ${EXECUTORCH_ROOT} /..)
159
- target_include_directories (coremldelegate PRIVATE ${EXECUTORCH_ROOT} /runtime/core/portable_type/c10)
160
- target_compile_definitions (coremldelegate PRIVATE C10_USING_CUSTOM_GENERATED_MACROS)
147
+ # executorchcoreml
161
148
162
- if (EXECUTORCH_BUILD_DEVTOOLS)
163
- target_sources (coremldelegate PRIVATE ${SDK_SOURCES} ${PROTOBUF_SOURCES} )
164
- target_include_directories (
165
- coremldelegate
166
- PRIVATE
167
- ${CMAKE_CURRENT_SOURCE_DIR} /runtime/sdk
168
- ${CMAKE_CURRENT_SOURCE_DIR} /third-party/coremltools/deps/protobuf/src
149
+ if (EXECUTORCH_BUILD_PYBIND)
150
+ pybind11_add_module(
151
+ executorchcoreml
152
+ SHARED
153
+ runtime/inmemoryfs/inmemory_filesystem_py.cpp
154
+ runtime/inmemoryfs/inmemory_filesystem_utils.cpp
169
155
)
170
- add_subdirectory (
171
- ${CMAKE_CURRENT_SOURCE_DIR} /third-party/coremltools/deps/protobuf/cmake
156
+ target_link_libraries (
157
+ executorchcoreml
158
+ PRIVATE
159
+ coreml_util
160
+ coreml_inmemoryfs
161
+ nlohmann_json::nlohmann_json
172
162
)
173
-
174
- target_link_options_shared_lib(libprotobuf-lite)
175
- target_link_libraries (coremldelegate PRIVATE libprotobuf-lite)
163
+ target_compile_options (executorchcoreml PUBLIC -fPIC)
176
164
endif ()
177
165
178
- find_library (ACCELERATE_FRAMEWORK Accelerate)
179
- find_library (COREML_FRAMEWORK CoreML)
180
- find_library (SQLITE_LIBRARY sqlite3)
181
-
182
- target_link_libraries (
183
- coremldelegate
184
- PUBLIC coreml_util
185
- coreml_inmemoryfs
186
- PRIVATE executorch_core
187
- ${ACCELERATE_FRAMEWORK}
188
- ${COREML_FRAMEWORK}
189
- ${FOUNDATION_FRAMEWORK}
190
- ${SQLITE_LIBRARY}
191
- )
166
+ # coremldelegate
192
167
193
- target_link_options_shared_lib(coremldelegate)
168
+ if (APPLE )
169
+ add_library (coremldelegate)
170
+ target_sources (coremldelegate PRIVATE ${KVSTORE_SOURCES} ${DELEGATE_SOURCES} )
194
171
195
- if (COREML_BUILD_EXECUTOR_RUNNER)
196
- target_link_libraries (
197
- coremldelegate PRIVATE portable_ops_lib portable_kernels
172
+ target_include_directories (
173
+ coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /runtime/include
198
174
)
199
- endif ()
200
-
201
- target_compile_options (coremldelegate PRIVATE "-fobjc-arc" )
202
- target_compile_options (coremldelegate PRIVATE "-fno-exceptions" )
203
-
204
- if (EXECUTORCH_BUILD_DEVTOOLS)
205
- target_compile_options (
206
- executorch_core PUBLIC -DET_EVENT_TRACER_ENABLED
175
+ target_include_directories (
176
+ coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /runtime/kvstore
207
177
)
208
- target_compile_options (coremldelegate PRIVATE "-frtti" )
209
- target_compile_options (libprotobuf-lite PRIVATE "-frtti" )
210
- else ()
211
- target_compile_options (coremldelegate PRIVATE "-fno-rtti" )
212
- endif ()
213
-
214
- set (TARGET coremldelegate APPEND_STRING PROPERTY COMPILE_FLAGS
215
- "-x objective-c++"
216
- )
217
-
218
- set (TARGET coremldelegate APPEND_STRING PROPERTY COMPILE_FLAGS
219
- "-Wno-null-character"
220
- )
178
+ target_include_directories (
179
+ coremldelegate PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} /runtime/delegate
180
+ )
181
+ target_include_directories (coremldelegate PRIVATE ${PROJECT_SOURCE_DIR} /..)
182
+ target_include_directories (coremldelegate PRIVATE ${PROJECT_SOURCE_DIR} /runtime/core/portable_type/c10)
183
+ target_compile_definitions (coremldelegate PRIVATE C10_USING_CUSTOM_GENERATED_MACROS)
184
+
185
+ if (EXECUTORCH_BUILD_DEVTOOLS)
186
+ target_sources (coremldelegate PRIVATE ${SDK_SOURCES} ${PROTOBUF_SOURCES} )
187
+ target_include_directories (
188
+ coremldelegate
189
+ PRIVATE
190
+ ${CMAKE_CURRENT_SOURCE_DIR} /runtime/sdk
191
+ ${CMAKE_CURRENT_SOURCE_DIR} /third-party/coremltools/deps/protobuf/src
192
+ )
193
+ add_subdirectory (
194
+ ${CMAKE_CURRENT_SOURCE_DIR} /third-party/coremltools/deps/protobuf/cmake
195
+ )
196
+
197
+ target_link_options_shared_lib(libprotobuf-lite)
198
+ target_link_libraries (coremldelegate PRIVATE libprotobuf-lite)
199
+ endif ()
221
200
222
- set (TARGET coremldelegate APPEND_STRING PROPERTY COMPILE_FLAGS
223
- "-Wno-receiver-expr"
224
- )
201
+ target_link_libraries (
202
+ coremldelegate
203
+ PUBLIC coreml_util
204
+ coreml_inmemoryfs
205
+ PRIVATE executorch_core
206
+ ${ACCELERATE_FRAMEWORK}
207
+ ${COREML_FRAMEWORK}
208
+ ${FOUNDATION_FRAMEWORK}
209
+ ${SQLITE_LIBRARY}
210
+ )
225
211
226
- install (
227
- TARGETS coremldelegate
228
- DESTINATION lib
229
- INCLUDES
230
- DESTINATION ${_common_include_directories}
231
- )
212
+ target_link_options_shared_lib(coremldelegate)
232
213
233
- # We only care about building the pybinding when building for macOS wheels.
234
- if (EXECUTORCH_BUILD_COREML AND EXECUTORCH_BUILD_PYBIND)
235
- if ( NOT TARGET pybind11::pybind11)
236
- add_subdirectory ( ${EXECUTORCH_ROOT} /third-party/pybind11 ${CMAKE_CURRENT_BINARY_DIR} /pybind11 )
214
+ if (EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER)
215
+ target_link_libraries (
216
+ coremldelegate PRIVATE portable_ops_lib portable_kernels
217
+ )
237
218
endif ()
238
219
239
- pybind11_add_module(executorchcoreml SHARED runtime/inmemoryfs/inmemory_filesystem_py.cpp)
220
+ target_compile_options (
221
+ coremldelegate
222
+ PRIVATE
223
+ -fobjc-arc
224
+ -fno-exceptions
225
+ -x objective-c++
226
+ -Wno-null-character
227
+ -Wno-receiver-expr
228
+ )
240
229
241
- if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
242
- target_compile_options (executorchcoreml PRIVATE -g)
230
+ if (EXECUTORCH_BUILD_DEVTOOLS)
231
+ target_compile_options (executorch_core PUBLIC -DET_EVENT_TRACER_ENABLED)
232
+ target_compile_options (coremldelegate PRIVATE "-frtti" )
233
+ target_compile_options (libprotobuf-lite PRIVATE "-frtti" )
234
+ else ()
235
+ target_compile_options (coremldelegate PRIVATE "-fno-rtti" )
243
236
endif ()
244
- target_link_libraries (executorchcoreml PRIVATE coreml_util coreml_inmemoryfs)
237
+
238
+ install (
239
+ TARGETS coremldelegate
240
+ DESTINATION lib
241
+ INCLUDES
242
+ DESTINATION ${_common_include_directories}
243
+ )
245
244
endif ()
0 commit comments