Skip to content

Commit ed63fb1

Browse files
committed
WIP: start using install again
1 parent 65eb28d commit ed63fb1

File tree

4 files changed

+76
-28
lines changed

4 files changed

+76
-28
lines changed

CMakeLists.txt

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ project(executorch)
4545
include(build/Utils.cmake)
4646
include(CMakeDependentOption)
4747

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+
4854
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
4955

5056
if(NOT CMAKE_CXX_STANDARD)
@@ -174,6 +180,11 @@ option(EXECUTORCH_BUILD_GTESTS
174180
option(EXECUTORCH_BUILD_EXTENSION_AOT_UTIL
175181
"Build the extension/aot_util directory" OFF)
176182

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+
177188
if(NOT BUCK2)
178189
set(BUCK2 buck2)
179190
endif()
@@ -185,7 +196,8 @@ endif()
185196
# TODO(dbort): Fix these warnings and remove this flag.
186197
set(_common_compile_options -Wno-deprecated-declarations -fPIC)
187198

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".
189201
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/..)
190202

191203
#
@@ -264,6 +276,13 @@ if(EXECUTORCH_BUILD_FLATC)
264276
set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "")
265277
set(FLATBUFFERS_INSTALL OFF CACHE BOOL "")
266278
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})
267286
endif()
268287
if(NOT FLATC_EXECUTABLE)
269288
message(
@@ -301,6 +320,16 @@ if(MAX_KERNEL_NUM)
301320
PRIVATE MAX_KERNEL_NUM=${MAX_KERNEL_NUM})
302321
endif()
303322

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+
304333
#
305334
# portable_ops_lib: A library to register core ATen ops using portable kernels,
306335
# see kernels/portable/CMakeLists.txt.
@@ -322,15 +351,6 @@ if(EXECUTORCH_BUILD_GFLAGS)
322351
add_subdirectory(third-party/gflags)
323352
endif()
324353

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-
334354
#
335355
# executor_runner: Host tool that demonstrates program execution.
336356
#
@@ -454,22 +474,26 @@ if(EXECUTORCH_BUILD_PYBIND)
454474
PATHS "${TORCH_INSTALL_PREFIX}/lib")
455475

456476
# compile options for pybind
457-
458477
set(_pybind_compile_options -Wno-deprecated-declarations -fPIC -frtti
459478
-fexceptions)
460-
# util lib
479+
480+
# Utilities needed by the pybindings extension.
461481
add_library(
462-
util
482+
extension_pybindings_util
463483
${CMAKE_CURRENT_SOURCE_DIR}/extension/evalue_util/print_evalue.cpp
464484
${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.
473497
pybind11_add_module(portable_lib extension/pybindings/pybindings.cpp)
474498
target_compile_definitions(portable_lib
475499
PUBLIC EXECUTORCH_PYTHON_MODULE_NAME=portable_lib)
@@ -482,8 +506,8 @@ if(EXECUTORCH_BUILD_PYBIND)
482506
etdump
483507
executorch
484508
extension_data_loader
509+
extension_pybindings_util
485510
portable_ops_lib
486-
util
487511
torch
488512
${PYBIND_LINK_COREML}
489513
${PYBIND_LINK_MPS}

build/executorch-config.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
cmake_minimum_required(VERSION 3.19)
1414

15+
# This file (which lives in CMAKE_CURRENT_LIST_DIR) should have been installed
16+
# in "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}". Get the path to
17+
# CMAKE_INSTALL_LIBDIR, which should contain all static and dynamic libraries.
1518
set(_root "${CMAKE_CURRENT_LIST_DIR}/../..")
19+
1620
add_library(executorch STATIC IMPORTED)
1721
find_library(
1822
EXECUTORCH_LIBRARY_PATH executorch
@@ -36,13 +40,13 @@ set_target_properties(
3640
target_include_directories(portable_kernels INTERFACE ${_root})
3741

3842
if(CMAKE_BUILD_TYPE MATCHES "Debug")
39-
set(FLATCC_LIB flatcc_d)
43+
set(FLATCCRT_LIB flatccrt_d)
4044
else()
41-
set(FLATCC_LIB flatcc)
45+
set(FLATCCRT_LIB flatccrt)
4246
endif()
4347

4448
set(lib_list
45-
etdump bundled_program extension_data_loader ${FLATCC_LIB} mpsdelegate
49+
etdump bundled_program extension_data_loader ${FLATCCRT_LIB} mpsdelegate
4650
qnn_executorch_backend portable_ops_lib extension_module xnnpack_backend
4751
XNNPACK cpuinfo pthreadpool
4852
)
@@ -57,7 +61,7 @@ foreach(lib ${lib_list})
5761
if("${lib}" STREQUAL "extension_module" AND (NOT CMAKE_TOOLCHAIN_IOS))
5862
add_library(${lib} SHARED IMPORTED)
5963
else()
60-
# Building a share library on iOS requires code signing, so it's
64+
# Building a shared library on iOS requires code signing, so it's
6165
# easier to keep all libs as static when CMAKE_TOOLCHAIN_IOS is
6266
# used
6367
add_library(${lib} STATIC IMPORTED)

sdk/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,5 +174,4 @@ target_include_directories(
174174
install(
175175
TARGETS bundled_program etdump flatccrt
176176
DESTINATION ${CMAKE_INSTALL_LIBDIR}
177-
INCLUDES
178-
DESTINATION ${_common_include_directories})
177+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

setup.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,27 @@ def run(self):
338338
# Build the system.
339339
self.spawn(["cmake", "--build", cmake_cache_dir, *build_args])
340340

341+
# Install some files to a common spot under cmake-out. This will make
342+
# them available install via BuiltExtension with a source under
343+
# `_installed/`.
344+
# TODO(dbort): Add --strip for release builds.
345+
cmake_install_dir = os.path.join(cmake_cache_dir, "_installed")
346+
self.spawn(
347+
[
348+
"cmake",
349+
"--install",
350+
cmake_cache_dir,
351+
"--prefix",
352+
cmake_install_dir,
353+
]
354+
)
355+
356+
# Copy all installed files into the package, under data/. If names or
357+
# locations need to change, handle that in the CMake config instead of
358+
# adding a mapping here.
359+
data_root = os.path.join(self.build_lib, "executorch", "data")
360+
self.copy_tree(cmake_install_dir, data_root)
361+
341362
# Finally, run the underlying subcommands like build_py, build_ext.
342363
build.run(self)
343364

0 commit comments

Comments
 (0)