Skip to content

WIP: attempt to use CMake EXPORT #8954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch")
"fix for this restriction."
)
endif()
set(_common_include_directories ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10)
set(_common_include_directories $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..,${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10> $<INSTALL_INTERFACE:include,include/executorch/runtime/core/portable_type/c10>)

#
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}.
Expand Down Expand Up @@ -653,6 +653,7 @@ install(DIRECTORY extension/tensor/ DESTINATION include/executorch/extension/te
install(DIRECTORY extension/threadpool/ DESTINATION include/executorch/extension/threadpool FILES_MATCHING PATTERN "*.h")
install(
TARGETS executorch executorch_core
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down Expand Up @@ -835,6 +836,7 @@ if(EXECUTORCH_BUILD_PYBIND)
target_link_libraries(portable_lib PRIVATE ${_dep_libs})

install(TARGETS portable_lib
EXPORT ExecuTorchTargets
LIBRARY DESTINATION executorch/extension/pybindings
)

Expand Down Expand Up @@ -863,6 +865,7 @@ if(EXECUTORCH_BUILD_PYBIND)
target_link_libraries(_training_lib PRIVATE ${_pybind_training_dep_libs})

install(TARGETS _training_lib
EXPORT ExecuTorchTargets
LIBRARY DESTINATION executorch/extension/training/pybindings
)
endif()
Expand Down Expand Up @@ -921,5 +924,8 @@ endif()

include(Test.cmake)

install(EXPORT ExecuTorchTargets
FILE ExecuTorchTargets.cmake
DESTINATION lib/cmake/ExecuTorch)
# Print all summary
executorch_print_configuration_summary()
1 change: 1 addition & 0 deletions backends/apple/coreml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ set(TARGET coremldelegate APPEND_STRING PROPERTY COMPILE_FLAGS

install(
TARGETS coremldelegate
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
1 change: 1 addition & 0 deletions backends/apple/mps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ target_compile_options(mpsdelegate PRIVATE "-fno-objc-arc")

install(
TARGETS mpsdelegate
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
2 changes: 1 addition & 1 deletion backends/mediatek/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ target_sources(
)
target_link_options_shared_lib(neuron_backend)

install(TARGETS neuron_backend DESTINATION lib)
install(TARGETS neuron_backend EXPORT ExecuTorchTargets DESTINATION lib)
2 changes: 1 addition & 1 deletion backends/qualcomm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ add_subdirectory(
${QNN_EXECUTORCH_ROOT_DIR}/aot/ir
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/ir
)
install(TARGETS qnn_executorch_backend DESTINATION lib)
install(TARGETS qnn_executorch_backend EXPORT ExecuTorchTargets DESTINATION lib)

# QNN pybind
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")
Expand Down
1 change: 1 addition & 0 deletions backends/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ endif()

install(
TARGETS vulkan_backend
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${COMMON_INCLUDES}
Expand Down
17 changes: 9 additions & 8 deletions backends/xnnpack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI)
add_definitions(-DENABLE_XNNPACK_KLEIDI)
endif()

set(_common_include_directories ${EXECUTORCH_ROOT}/..)
set(_common_compile_options -Wno-deprecated-declarations -fPIC)

set(_xnnpack_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include")
Expand Down Expand Up @@ -89,10 +88,9 @@ add_custom_command(
add_library(xnnpack_schema INTERFACE ${_xnnpack_schema__outputs})
set_target_properties(xnnpack_schema PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(
xnnpack_schema INTERFACE ${_xnnpack_schema__include_dir}
${EXECUTORCH_ROOT}/third-party/flatbuffers/include
xnnpack_schema INTERFACE $<BUILD_INTERFACE:${_xnnpack_schema__include_dir}>
)

target_link_libraries(xnnpack_schema INTERFACE flatbuffers)
set(xnnpack_third_party pthreadpool cpuinfo)

include(cmake/Dependencies.cmake)
Expand All @@ -106,14 +104,14 @@ target_link_libraries(
target_include_directories(
xnnpack_backend PUBLIC ${_common_include_directories}
)
target_include_directories(xnnpack_backend PUBLIC ${XNNPACK_INCLUDE_DIR})
target_include_directories(xnnpack_backend PRIVATE ${XNNPACK_INCLUDE_DIR})
target_include_directories(
xnnpack_backend
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third-party/pthreadpool/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third-party/pthreadpool/include
)
target_include_directories(
xnnpack_backend
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third-party/cpuinfo/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third-party/cpuinfo/include
)
target_compile_options(xnnpack_backend PUBLIC ${_common_compile_options})
target_link_options_shared_lib(xnnpack_backend)
Expand Down Expand Up @@ -155,7 +153,10 @@ if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$")
endif()

install(
TARGETS xnnpack_backend
# XNNPACK doesn't export the XNNPACK and following targets,
# so we need to export them ourselves.
TARGETS xnnpack_backend xnnpack_schema XNNPACK fxdiv
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
2 changes: 2 additions & 0 deletions backends/xnnpack/cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,15 @@ add_subdirectory("${XNNPACK_SOURCE_DIR}")
include_directories(SYSTEM ${XNNPACK_INCLUDE_DIR})
list(APPEND xnnpack_third_party XNNPACK)
install(TARGETS microkernels-prod
EXPORT ExecuTorchTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})


if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI)
install(TARGETS kleidiai
EXPORT ExecuTorchTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
Expand Down
2 changes: 1 addition & 1 deletion configurations/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
executorch
)

install(TARGETS optimized_native_cpu_ops_lib DESTINATION lib)
install(TARGETS optimized_native_cpu_ops_lib EXPORT ExecuTorchTargets DESTINATION lib)
endif()
3 changes: 2 additions & 1 deletion extension/data_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ endif()
list(TRANSFORM _extension_data_loader__srcs PREPEND "${EXECUTORCH_ROOT}/")
add_library(extension_data_loader ${_extension_data_loader__srcs})
target_link_libraries(extension_data_loader executorch)
target_include_directories(extension_data_loader PUBLIC ${EXECUTORCH_ROOT}/..)
target_include_directories(extension_data_loader PUBLIC ${_common_include_directories})
target_compile_options(extension_data_loader PUBLIC ${_common_compile_options})

# Install libraries
install(
TARGETS extension_data_loader
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
6 changes: 3 additions & 3 deletions extension/flat_tensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ add_library(extension_flat_tensor ${_extension_flat_tensor__srcs})
target_link_libraries(extension_flat_tensor executorch extension_data_loader)
target_include_directories(
extension_flat_tensor
PUBLIC ${EXECUTORCH_ROOT}/..
"${CMAKE_BINARY_DIR}/extension/flat_tensor/include"
"${EXECUTORCH_ROOT}/third-party/flatbuffers/include"
PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/extension/flat_tensor/include>
$<BUILD_INTERFACE:${EXECUTORCH_ROOT}/third-party/flatbuffers/include>
${_common_include_directories}
)
target_compile_options(extension_flat_tensor PUBLIC ${_common_compile_options})

# Install libraries
install(
TARGETS extension_flat_tensor
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
9 changes: 5 additions & 4 deletions extension/llm/custom_ops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extract_sources(${EXECUTORCH_SRCS_FILE})
include(${EXECUTORCH_SRCS_FILE})

# Let files say "include <executorch/path/to/header.h>".
set(_common_include_directories ${EXECUTORCH_ROOT}/..)
set(_common_include_directories $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..,${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10> $<INSTALL_INTERFACE:include,include/executorch/runtime/core/portable_type/c10>)

# Custom op libraries
set(custom_ops_libs pthreadpool)
Expand Down Expand Up @@ -73,15 +73,15 @@ add_library(custom_ops ${_custom_ops__srcs})

target_include_directories(custom_ops PUBLIC "${_common_include_directories}")
target_include_directories(
custom_ops PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../include"
custom_ops PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../../../include>
)
target_link_libraries(custom_ops PUBLIC ${custom_ops_libs} executorch_core)

target_compile_options(
custom_ops PUBLIC ${_common_compile_options} -DET_USE_THREADPOOL
)

install(TARGETS custom_ops DESTINATION lib)
install(TARGETS custom_ops EXPORT ExecuTorchTargets DESTINATION lib)

if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
# Add a AOT library
Expand All @@ -98,7 +98,7 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
custom_ops_aot_lib PUBLIC "${_common_include_directories}"
)
target_include_directories(
custom_ops_aot_lib PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../../../include"
custom_ops_aot_lib PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/../../../include>
)
# TODO: This only works if we install portable_lib.so to
# <site-packages>/executorch/extension/pybindings/.
Expand Down Expand Up @@ -134,6 +134,7 @@ if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
)

install(TARGETS custom_ops_aot_lib
EXPORT ExecuTorchTargets
LIBRARY DESTINATION executorch/extension/llm/custom_ops
)
endif()
Expand Down
1 change: 1 addition & 0 deletions extension/llm/tokenizer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ target_compile_options(
# Install libraries
install(
TARGETS extension_llm_tokenizer
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
5 changes: 3 additions & 2 deletions extension/module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ else()
add_library(extension_module SHARED ${_extension_module__srcs})
endif()
target_link_libraries(extension_module PRIVATE executorch extension_data_loader extension_flat_tensor)
target_include_directories(extension_module PUBLIC ${EXECUTORCH_ROOT}/..)
target_include_directories(extension_module PUBLIC ${_common_include_directories})
target_compile_options(
extension_module PUBLIC -Wno-deprecated-declarations -fPIC
)
Expand All @@ -39,14 +39,15 @@ add_library(extension_module_static STATIC ${_extension_module__srcs})
target_link_libraries(
extension_module_static PRIVATE executorch extension_data_loader extension_flat_tensor
)
target_include_directories(extension_module_static PUBLIC ${EXECUTORCH_ROOT}/..)
target_include_directories(extension_module_static PUBLIC ${_common_include_directories})
target_compile_options(
extension_module_static PUBLIC -Wno-deprecated-declarations -fPIC
)

# Install libraries
install(
TARGETS extension_module extension_module_static
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
3 changes: 2 additions & 1 deletion extension/runner_util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ endif()
list(TRANSFORM _extension_runner_util__srcs PREPEND "${EXECUTORCH_ROOT}/")
add_library(extension_runner_util ${_extension_runner_util__srcs})
target_link_libraries(extension_runner_util executorch)
target_include_directories(extension_runner_util PUBLIC ${EXECUTORCH_ROOT}/..)
target_include_directories(extension_runner_util PUBLIC ${_common_include_directories})
target_compile_options(extension_runner_util PUBLIC ${_common_compile_options})

# Install libraries
install(
TARGETS extension_runner_util
EXPORT ExecuTorchTargets
DESTINATION ${CMAKE_BINARY_DIR}/lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
3 changes: 2 additions & 1 deletion extension/tensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ endif()
list(TRANSFORM _extension_tensor__srcs PREPEND "${EXECUTORCH_ROOT}/")
add_library(extension_tensor ${_extension_tensor__srcs})
target_link_libraries(extension_tensor executorch_core)
target_include_directories(extension_tensor PUBLIC ${EXECUTORCH_ROOT}/..)
target_include_directories(extension_tensor PUBLIC ${_common_include_directories})
target_compile_options(extension_tensor PUBLIC ${_common_compile_options})

# Install libraries
install(
TARGETS extension_tensor
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
10 changes: 6 additions & 4 deletions extension/threadpool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ add_library(
target_link_libraries(
extension_threadpool PUBLIC executorch_core cpuinfo pthreadpool
)
target_include_directories(extension_threadpool PUBLIC ${EXECUTORCH_ROOT}/..)
target_include_directories(extension_threadpool PUBLIC ${_common_include_directories})
target_include_directories(
extension_threadpool
PUBLIC ${EXECUTORCH_ROOT}/backends/xnnpack/third-party/cpuinfo/include
${EXECUTORCH_ROOT}/backends/xnnpack/third-party/pthreadpool/include
PUBLIC $<BUILD_INTERFACE:${EXECUTORCH_ROOT}/backends/xnnpack/third-party/cpuinfo/include>
$<BUILD_INTERFACE:${EXECUTORCH_ROOT}/backends/xnnpack/third-party/pthreadpool/include>
)
target_compile_options(extension_threadpool PUBLIC ${_common_compile_options})

# Install libraries
install(
TARGETS extension_threadpool
# pthreadpool doesn't export itself, so we have to do our own install to export it.
TARGETS pthreadpool pthreadpool_interface extension_threadpool
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
1 change: 1 addition & 0 deletions extension/training/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ target_compile_options(train_xor PUBLIC ${_common_compile_options})
# Install libraries
install(
TARGETS extension_training
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
6 changes: 3 additions & 3 deletions kernels/optimized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ gen_operators_lib(
)

install(
TARGETS cpublas optimized_kernels optimized_ops_lib
# eigen_blas doesn't export itself, so we have to do our own install to export it.
TARGETS cpublas optimized_kernels optimized_ops_lib eigen_blas
EXPORT ExecuTorchTargets
DESTINATION lib
PUBLIC_HEADER DESTINATION include/executorch/kernels/optimized/
)

install(TARGETS cpublas DESTINATION lib)
1 change: 1 addition & 0 deletions kernels/portable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ gen_operators_lib(

install(
TARGETS portable_kernels portable_ops_lib
EXPORT ExecuTorchTargets
DESTINATION lib
PUBLIC_HEADER DESTINATION include/executorch/kernels/portable/
)
1 change: 1 addition & 0 deletions kernels/quantized/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ gen_operators_lib(

install(
TARGETS quantized_kernels quantized_ops_lib
EXPORT ExecuTorchTargets
DESTINATION lib
PUBLIC_HEADER DESTINATION include/executorch/kernels/quantized/
)
11 changes: 10 additions & 1 deletion schema/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ function(generate_program_schema _schema_srcs _schema_name)
target_include_directories(
${_schema_name}
INTERFACE ${_program_schema__include_dir}
${EXECUTORCH_ROOT}/third-party/flatbuffers/include
$<BUILD_INTERFACE:${EXECUTORCH_ROOT}/third-party/flatbuffers/include>
)
target_link_libraries(${_schema_name} INTERFACE flatbuffers)

endfunction()

# Generate common schema
Expand All @@ -67,3 +69,10 @@ generate_program_schema("${common_schema_srcs}" "common_schema")
set(program_schema_srcs program.fbs)
generate_program_schema("${program_schema_srcs}" "program_schema")
add_dependencies(program_schema common_schema)

install(
TARGETS common_schema program_schema
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories})
Loading