@@ -45,6 +45,12 @@ project(executorch)
45
45
include (build /Utils.cmake )
46
46
include (CMakeDependentOption )
47
47
48
+ # Set CMAKE_INSTALL_* vars to values recommended by the GNU Coding Standards.
49
+ # It's important we do this here because many of the third-party projects also
50
+ # include this, and it can change the values of CMAKE_INSTALL_* vars on some
51
+ # systems (e.g., from `lib` to `lib64`).
52
+ include (GNUInstallDirs )
53
+
48
54
set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
49
55
50
56
if (NOT CMAKE_CXX_STANDARD )
@@ -174,6 +180,11 @@ option(EXECUTORCH_BUILD_GTESTS
174
180
option (EXECUTORCH_BUILD_EXTENSION_AOT_UTIL
175
181
"Build the extension/aot_util directory" OFF )
176
182
183
+ # Conventional installation location for CMake config files; see
184
+ # https://stackoverflow.com/q/71725037.
185
+ set (EXECUTORCH_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME} "
186
+ CACHE STRING "Install path for ${PROJECT_NAME} CMake files" )
187
+
177
188
if (NOT BUCK2 )
178
189
set (BUCK2 buck2 )
179
190
endif ()
@@ -185,7 +196,8 @@ endif()
185
196
# TODO(dbort): Fix these warnings and remove this flag.
186
197
set (_common_compile_options -Wno-deprecated-declarations -fPIC )
187
198
188
- # Let files say "include <executorch/path/to/header.h>".
199
+ # Let files say "include <executorch/path/to/header.h>". Assumes that the repo
200
+ # lives in a directory named "executorch".
189
201
set (_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR} /.. )
190
202
191
203
#
@@ -264,6 +276,13 @@ if(EXECUTORCH_BUILD_FLATC)
264
276
set (FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "" )
265
277
set (FLATBUFFERS_INSTALL OFF CACHE BOOL "" )
266
278
add_subdirectory (third-party/flatbuffers )
279
+
280
+ # Install flatc ourselves, even though third-party/flatbuffers/CMakeLists.txt
281
+ # has an option for it. Setting FLATBUFFERS_INSTALL would also install its
282
+ # CMake config files, which we do not want to publish.
283
+ install (
284
+ TARGETS flatc
285
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
267
286
endif ()
268
287
if (NOT FLATC_EXECUTABLE )
269
288
message (
@@ -301,6 +320,16 @@ if(MAX_KERNEL_NUM)
301
320
PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM} )
302
321
endif ()
303
322
323
+ install (
324
+ TARGETS executorch
325
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
326
+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
327
+
328
+ # Install CMake config along with library files.
329
+ install (
330
+ FILES build /executorch-config.cmake
331
+ DESTINATION ${EXECUTORCH_INSTALL_CMAKEDIR} )
332
+
304
333
#
305
334
# portable_ops_lib: A library to register core ATen ops using portable kernels,
306
335
# see kernels/portable/CMakeLists.txt.
@@ -322,15 +351,6 @@ if(EXECUTORCH_BUILD_GFLAGS)
322
351
add_subdirectory (third-party/gflags )
323
352
endif ()
324
353
325
- # Install `executorch` library as well as `executorch-config.cmake` under
326
- # ${CMAKE_INSTALL_PREFIX}/
327
- install (
328
- TARGETS executorch
329
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
330
- INCLUDES
331
- DESTINATION ${_common_include_directories} )
332
- install (FILES build /executorch-config.cmake DESTINATION share/cmake/executorch )
333
-
334
354
#
335
355
# executor_runner: Host tool that demonstrates program execution.
336
356
#
@@ -454,22 +474,26 @@ if(EXECUTORCH_BUILD_PYBIND)
454
474
PATHS "${TORCH_INSTALL_PREFIX} /lib" )
455
475
456
476
# compile options for pybind
457
-
458
477
set (_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
459
478
-fexceptions )
460
- # util lib
479
+
480
+ # Utilities needed by the pybindings extension.
461
481
add_library (
462
- util
482
+ extension_pybindings_util
463
483
${CMAKE_CURRENT_SOURCE_DIR} /extension/evalue_util/print_evalue.cpp
464
484
${CMAKE_CURRENT_SOURCE_DIR} /extension/aten_util/aten_bridge.cpp
465
- ${CMAKE_CURRENT_SOURCE_DIR} /util/read_file.cpp
466
- )
467
- target_include_directories (util PUBLIC ${_common_include_directories}
468
- ${TORCH_INCLUDE_DIRS} )
469
- target_compile_options (util PUBLIC ${_pybind_compile_options} )
470
- target_link_libraries (util PRIVATE torch c10 executorch )
471
-
472
- # pybind portable_lib
485
+ ${CMAKE_CURRENT_SOURCE_DIR} /util/read_file.cpp )
486
+ target_include_directories (
487
+ extension_pybindings_util
488
+ PUBLIC
489
+ ${_common_include_directories}
490
+ ${TORCH_INCLUDE_DIRS} )
491
+ target_compile_options (extension_pybindings_util
492
+ PUBLIC ${_pybind_compile_options} )
493
+ target_link_libraries (extension_pybindings_util PRIVATE torch c10 executorch )
494
+
495
+ # Pybindings extension for the executorch.extension.pybindings.portable_lib
496
+ # module.
473
497
pybind11_add_module (portable_lib extension/pybindings/pybindings.cpp )
474
498
target_compile_definitions (portable_lib
475
499
PUBLIC EXECUTORCH_PYTHON_MODULE_NAME=portable_lib )
@@ -482,8 +506,8 @@ if(EXECUTORCH_BUILD_PYBIND)
482
506
etdump
483
507
executorch
484
508
extension_data_loader
509
+ extension_pybindings_util
485
510
portable_ops_lib
486
- util
487
511
torch
488
512
${PYBIND_LINK_COREML}
489
513
${PYBIND_LINK_MPS}
0 commit comments