Skip to content

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 16 commits into
base: gh/swolchok/517/head
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
1 change: 1 addition & 0 deletions .ci/scripts/test_llama.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ cmake_install_executorch_libraries() {
echo "Installing libexecutorch.a, libextension_module.so, libportable_ops_lib.a"
rm -rf cmake-out
retry cmake --preset llm \
-DBUILD_TESTING=OFF \
-DCMAKE_INSTALL_PREFIX=cmake-out \
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
-DEXECUTORCH_BUILD_QNN="$QNN" \
Expand Down
2 changes: 2 additions & 0 deletions .ci/scripts/test_llama_torchao_lowbit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ cmake -DPYTHON_EXECUTABLE=python \
-DEXECUTORCH_ENABLE_LOGGING=1 \
-DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
-DEXECUTORCH_BUILD_EXTENSION_LLM=ON \
-DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON \
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
-DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
Expand Down
83 changes: 65 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ include(${PROJECT_SOURCE_DIR}/tools/cmake/common/preset.cmake)
include(${PROJECT_SOURCE_DIR}/tools/cmake/Utils.cmake)
include(CMakeDependentOption)
include(ExternalProject)
include(GNUInstallDirs)

if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -175,6 +176,7 @@ if(NOT DEFINED FXDIV_SOURCE_DIR)
)
set(FXDIV_SOURCE_DIR "backends/xnnpack/third-party/FXdiv")
add_subdirectory("${FXDIV_SOURCE_DIR}")
move_interface_include_directories_to_build_time_only(fxdiv)
set(CMAKE_POSITION_INDEPENDENT_CODE
${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG}
)
Expand All @@ -186,7 +188,9 @@ if(EXECUTORCH_BUILD_CPUINFO)
${CMAKE_POSITION_INDEPENDENT_CODE}
)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CPUINFO_SOURCE_DIR "backends/xnnpack/third-party/cpuinfo")
set(CPUINFO_SOURCE_DIR
"${CMAKE_CURRENT_LIST_DIR}/backends/xnnpack/third-party/cpuinfo"
)
set(CPUINFO_BUILD_TOOLS
OFF
CACHE BOOL ""
Expand Down Expand Up @@ -216,6 +220,14 @@ if(EXECUTORCH_BUILD_CPUINFO)
set(CMAKE_POSITION_INDEPENDENT_CODE
${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG}
)
add_prefix_to_public_headers(cpuinfo "${CPUINFO_SOURCE_DIR}/")
install(
TARGETS cpuinfo
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
)
endif()

if(EXECUTORCH_BUILD_PTHREADPOOL)
Expand Down Expand Up @@ -248,6 +260,15 @@ if(EXECUTORCH_BUILD_PTHREADPOOL)
)
endif()
add_subdirectory("${PTHREADPOOL_SOURCE_DIR}")
move_interface_include_directories_to_build_time_only(pthreadpool)
move_interface_include_directories_to_build_time_only(pthreadpool_interface)
install(
TARGETS pthreadpool pthreadpool_interface fxdiv
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
)
set(CMAKE_POSITION_INDEPENDENT_CODE
${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG}
)
Expand All @@ -271,8 +292,10 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch")
)
endif()
set(_common_include_directories
${CMAKE_CURRENT_SOURCE_DIR}/..
${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/core/portable_type/c10>
)

#
Expand Down Expand Up @@ -447,50 +470,51 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/configurations)
# ${CMAKE_INSTALL_PREFIX}/
install(
DIRECTORY runtime/core/
DESTINATION include/executorch/runtime/core
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/core
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY runtime/executor/
DESTINATION include/executorch/runtime/executor
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/executor
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY runtime/kernel/
DESTINATION include/executorch/runtime/kernel
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/kernel
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY runtime/platform/
DESTINATION include/executorch/runtime/platform
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/runtime/platform
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY extension/kernel_util/
DESTINATION include/executorch/extension/kernel_util
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/kernel_util
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY extension/tensor/
DESTINATION include/executorch/extension/tensor
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/tensor
FILES_MATCHING
PATTERN "*.h"
)
install(
DIRECTORY extension/threadpool/
DESTINATION include/executorch/extension/threadpool
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/threadpool
FILES_MATCHING
PATTERN "*.h"
)
install(
TARGETS executorch executorch_core
EXPORT ExecuTorchTargets
INCLUDES
DESTINATION ${_common_include_directories}
DESTINATION include
)
install(FILES tools/cmake/Utils.cmake tools/cmake/executorch-config.cmake
DESTINATION lib/cmake/ExecuTorch
Expand Down Expand Up @@ -556,24 +580,39 @@ if(EXECUTORCH_BUILD_EXTENSION_MODULE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/module)
install(
DIRECTORY extension/module/
DESTINATION include/executorch/extension/module
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/module
FILES_MATCHING
PATTERN "*.h"
)
endif()

if(EXECUTORCH_BUILD_EXTENSION_LLM)
if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER)
set(SUPPORT_REGEX_LOOKAHEAD ON)
# llama/runner/CMakeLists.txt builds a shared library libllama_runner.so
# that transitively depends on tokenizers. Need to build tokenizers with
# -fPIC.
set(ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG
${CMAKE_POSITION_INDEPENDENT_CODE}
)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/tokenizers)
endif()

if(EXECUTORCH_BUILD_EXTENSION_LLM_APPLE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/apple)
if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER)
set(CMAKE_POSITION_INDEPENDENT_CODE
${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG}
)
endif()
endif()

if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/runner)
endif()

if(EXECUTORCH_BUILD_EXTENSION_LLM_APPLE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/apple)
endif()

if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/runner_util)
endif()
Expand Down Expand Up @@ -674,8 +713,10 @@ if(EXECUTORCH_BUILD_PYBIND)
target_compile_options(portable_lib PUBLIC ${_pybind_compile_options})
target_link_libraries(portable_lib PRIVATE ${_dep_libs})

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

Expand Down Expand Up @@ -758,5 +799,11 @@ endif()

include(Test.cmake)

install(
EXPORT ExecuTorchTargets
FILE ExecuTorchTargets.cmake
DESTINATION lib/cmake/ExecuTorch
)

# Print all the configs that were called with announce_configured_options.
print_configured_options()
25 changes: 19 additions & 6 deletions backends/apple/coreml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ endif()

add_library(coreml_util ${UTIL_SOURCES})
target_include_directories(
coreml_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/util
coreml_util PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/runtime/util> $<INSTALL_INTERFACE:include/executorch/backends/apple/coreml/runtime/util>
)
if(APPLE)
target_link_libraries(coreml_util PRIVATE ${FOUNDATION_FRAMEWORK})
Expand All @@ -115,8 +115,13 @@ target_compile_options(coreml_util PUBLIC -fPIC)
install(
TARGETS coreml_util
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/runtime/util
DESTINATION include/executorch/backends/apple/coreml/runtime/util
FILES_MATCHING
PATTERN "*.h"
)

# CoreML inmemoryfs
Expand All @@ -134,7 +139,7 @@ endif()

add_library(coreml_inmemoryfs ${INMEMORYFS_SOURCES})
target_include_directories(
coreml_inmemoryfs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/inmemoryfs
coreml_inmemoryfs PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/runtime/inmemoryfs> $<INSTALL_INTERFACE:include/executorch/backends/apple/coreml/runtime/inmemoryfs>
)
if(APPLE)
target_link_libraries(
Expand All @@ -150,6 +155,13 @@ install(
DESTINATION ${_common_include_directories}
)

install(
DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/runtime/inmemoryfs
DESTINATION include/executorch/backends/apple/coreml/runtime/inmemoryfs
FILES_MATCHING
PATTERN "*.h"
)

# executorchcoreml

if(EXECUTORCH_BUILD_PYBIND)
Expand Down Expand Up @@ -232,9 +244,10 @@ if(APPLE)
endif()

install(
TARGETS coremldelegate
TARGETS coremldelegate coreml_util coreml_inmemoryfs
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
DESTINATION include
)
endif()
11 changes: 6 additions & 5 deletions backends/apple/mps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ endif()
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)

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

set(_mps_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include")

Expand Down Expand Up @@ -51,9 +50,10 @@ add_library(mps_schema INTERFACE ${_mps_schema__outputs})
set_target_properties(mps_schema PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(
mps_schema
INTERFACE ${_mps_schema__include_dir}
${EXECUTORCH_ROOT}/third-party/flatbuffers/include
${_common_include_directories}
INTERFACE
$<BUILD_INTERFACE:${_mps_schema__include_dir}>
$<BUILD_INTERFACE:${EXECUTORCH_ROOT}/third-party/flatbuffers/include>
${_common_include_directories}
)

list(TRANSFORM _mps_backend__srcs PREPEND "${EXECUTORCH_ROOT}/")
Expand All @@ -75,7 +75,8 @@ target_compile_options(mpsdelegate PUBLIC ${_common_compile_options})
target_compile_options(mpsdelegate PRIVATE "-fno-objc-arc")

install(
TARGETS mpsdelegate
TARGETS mpsdelegate mps_schema
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${_common_include_directories}
Expand Down
18 changes: 11 additions & 7 deletions backends/mediatek/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ target_link_libraries(
)
target_sources(
neuron_backend
INTERFACE ${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronBackend.h
${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronBufferAllocator.h
${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronExecutor.h
${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronLog.h
${CMAKE_CURRENT_LIST_DIR}/runtime/include/api/APUWareUtilsLib.h
${CMAKE_CURRENT_LIST_DIR}/runtime/include/api/NeuronAdapterShim.h
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronBackend.h>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronBufferAllocator.h>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronExecutor.h>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/runtime/include/NeuronLog.h>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/runtime/include/api/APUWareUtilsLib.h>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/runtime/include/api/NeuronAdapterShim.h>
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/runtime/NeuronBackend.cpp
${CMAKE_CURRENT_LIST_DIR}/runtime/NeuronExecutor.cpp
${CMAKE_CURRENT_LIST_DIR}/runtime/NeuronBufferAllocator.cpp
)
target_link_options_shared_lib(neuron_backend)

install(TARGETS neuron_backend DESTINATION lib)
install(
TARGETS neuron_backend
EXPORT ExecuTorchTargets
DESTINATION lib
)
6 changes: 5 additions & 1 deletion backends/qualcomm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ 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
6 changes: 3 additions & 3 deletions backends/qualcomm/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ target_sources(
# qnn_executorch_backend
target_sources(
qnn_executorch_backend
INTERFACE ${CMAKE_CURRENT_LIST_DIR}/QnnExecuTorchBackend.h
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/QnnExecuTorchBackend.h>
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/QnnExecuTorchBackend.cpp
)

# qnn_manager
target_sources(
qnn_manager
INTERFACE ${CMAKE_CURRENT_LIST_DIR}/QnnManager.h
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/QnnManager.h>
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/QnnManager.cpp
)

# logging
target_sources(
qnn_executorch_logging
PUBLIC ${CMAKE_CURRENT_LIST_DIR}/Logging.h
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/Logging.h>
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Logging.cpp
)

Expand Down
1 change: 1 addition & 0 deletions backends/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ endif()

install(
TARGETS vulkan_backend
EXPORT ExecuTorchTargets
DESTINATION lib
INCLUDES
DESTINATION ${COMMON_INCLUDES}
Expand Down
Loading
Loading