Skip to content

Commit 71d6eb0

Browse files
committed
WIP: attempt to use CMake EXPORT
The CMake EXPORT feature seems like it's supposed to make target_compile_options etc. work nicely for both in-project builds and also projects that consume your project by installing it and finding it with find_package. Using EXPORT would make it easy to have similar behavior to Buck's exported_preprocessor_flags, for example. Unfortunately, I am currently stalled here by XNNPACK's lack of use of EXPORT. I tried working around dependencies that don't use EXPORT by re-installing them with EXPORT ourselves, but XNNPACK has rather a lot so I'm sending this out to highlight the problem and ask if there's another way. I found some similar issues in TFLite: tensorflow/tensorflow#57658 tensorflow/tensorflow#87172 ghstack-source-id: af3cc8d ghstack-comment-id: 2699501745 Pull Request resolved: #8954
1 parent e136252 commit 71d6eb0

File tree

22 files changed

+126
-203
lines changed

22 files changed

+126
-203
lines changed

CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@ if(NOT "${_repo_dir_name}" STREQUAL "executorch")
283283
)
284284
endif()
285285
set(_common_include_directories
286-
${CMAKE_CURRENT_SOURCE_DIR}/..
287-
${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10
288-
)
286+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
287+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/runtime/core/portable_type/c10>
288+
$<INSTALL_INTERFACE:include>
289+
$<INSTALL_INTERFACE:include/executorch/runtime/core/portable_type/c10>)
289290

290291
#
291292
# The `_<target>_srcs` lists are defined by including ${EXECUTORCH_SRCS_FILE}.
@@ -501,8 +502,9 @@ install(
501502
)
502503
install(
503504
TARGETS executorch executorch_core
505+
EXPORT ExecuTorchTargets
504506
INCLUDES
505-
DESTINATION ${_common_include_directories}
507+
DESTINATION include
506508
)
507509
install(FILES tools/cmake/Utils.cmake tools/cmake/executorch-config.cmake
508510
DESTINATION lib/cmake/ExecuTorch
@@ -683,6 +685,7 @@ if(EXECUTORCH_BUILD_PYBIND)
683685
target_link_libraries(portable_lib PRIVATE ${_dep_libs})
684686

685687
install(TARGETS portable_lib
688+
EXPORT ExecuTorchTargets
686689
LIBRARY DESTINATION executorch/extension/pybindings
687690
)
688691
endif()
@@ -765,3 +768,7 @@ if(EXECUTORCH_BUILD_ANDROID_JNI)
765768
endif()
766769

767770
include(Test.cmake)
771+
772+
install(EXPORT ExecuTorchTargets
773+
FILE ExecuTorchTargets.cmake
774+
DESTINATION lib/cmake/ExecuTorch)

backends/apple/coreml/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ endif()
105105

106106
add_library(coreml_util ${UTIL_SOURCES})
107107
target_include_directories(
108-
coreml_util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/util
108+
coreml_util PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/runtime/util> $<INSTALL_INTERFACE:include/executorch/backends/apple/coreml/runtime/util>
109109
)
110110
if(APPLE)
111111
target_link_libraries(coreml_util PRIVATE ${FOUNDATION_FRAMEWORK})
@@ -134,7 +134,7 @@ endif()
134134

135135
add_library(coreml_inmemoryfs ${INMEMORYFS_SOURCES})
136136
target_include_directories(
137-
coreml_inmemoryfs PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/runtime/inmemoryfs
137+
coreml_inmemoryfs PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/runtime/inmemoryfs> $<INSTALL_INTERFACE:include/executorch/backends/apple/coreml/runtime/inmemoryfs>
138138
)
139139
if(APPLE)
140140
target_link_libraries(
@@ -232,9 +232,10 @@ if(APPLE)
232232
endif()
233233

234234
install(
235-
TARGETS coremldelegate
235+
TARGETS coremldelegate coreml_util coreml_inmemoryfs
236+
EXPORT ExecuTorchTargets
236237
DESTINATION lib
237238
INCLUDES
238-
DESTINATION ${_common_include_directories}
239+
DESTINATION include
239240
)
240241
endif()

backends/apple/mps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ target_compile_options(mpsdelegate PRIVATE "-fno-objc-arc")
8181

8282
install(
8383
TARGETS mpsdelegate
84+
EXPORT ExecuTorchTargets
8485
DESTINATION lib
8586
INCLUDES
8687
DESTINATION ${_common_include_directories}

backends/mediatek/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ target_sources(
4242
)
4343
target_link_options_shared_lib(neuron_backend)
4444

45-
install(TARGETS neuron_backend DESTINATION lib)
45+
install(
46+
TARGETS neuron_backend
47+
EXPORT ExecuTorchTargets
48+
DESTINATION lib
49+
)

backends/qualcomm/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,11 @@ add_subdirectory(
229229
${QNN_EXECUTORCH_ROOT_DIR}/aot/ir
230230
${CMAKE_CURRENT_BINARY_DIR}/qnn_executorch/ir
231231
)
232-
install(TARGETS qnn_executorch_backend DESTINATION lib)
232+
install(
233+
TARGETS qnn_executorch_backend
234+
EXPORT ExecuTorchTargets
235+
DESTINATION lib
236+
)
233237

234238
# QNN pybind
235239
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64")

backends/vulkan/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ endif()
135135

136136
install(
137137
TARGETS vulkan_backend
138+
EXPORT ExecuTorchTargets
138139
DESTINATION lib
139140
INCLUDES
140141
DESTINATION ${COMMON_INCLUDES}

backends/xnnpack/CMakeLists.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ if(EXECUTORCH_XNNPACK_ENABLE_KLEIDI)
3535
add_definitions(-DENABLE_XNNPACK_KLEIDI)
3636
endif()
3737

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

4140
set(_xnnpack_schema__include_dir "${CMAKE_BINARY_DIR}/schema/include")
@@ -88,8 +87,10 @@ unset(MV_COMMAND)
8887
add_library(xnnpack_schema INTERFACE ${_xnnpack_schema__outputs})
8988
set_target_properties(xnnpack_schema PROPERTIES LINKER_LANGUAGE CXX)
9089
target_include_directories(
91-
xnnpack_schema INTERFACE ${_xnnpack_schema__include_dir}
92-
${EXECUTORCH_ROOT}/third-party/flatbuffers/include
90+
xnnpack_schema
91+
INTERFACE
92+
$<BUILD_INTERFACE:${_xnnpack_schema__include_dir}>
93+
$<BUILD_INTERFACE:${EXECUTORCH_ROOT}/third-party/flatbuffers/include>
9394
)
9495

9596
include(cmake/Dependencies.cmake)
@@ -101,24 +102,25 @@ target_link_libraries(
101102
xnnpack_backend PUBLIC ${xnnpack_third_party} executorch_core xnnpack_schema
102103
extension_threadpool
103104
)
104-
105105
target_include_directories(
106106
xnnpack_backend PUBLIC ${_common_include_directories}
107107
)
108-
target_include_directories(xnnpack_backend PUBLIC ${XNNPACK_INCLUDE_DIR})
108+
target_include_directories(xnnpack_backend PRIVATE ${XNNPACK_INCLUDE_DIR})
109109
target_include_directories(
110110
xnnpack_backend
111-
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third-party/pthreadpool/include
111+
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third-party/pthreadpool/include
112112
)
113113
target_include_directories(
114114
xnnpack_backend
115-
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/third-party/cpuinfo/include
115+
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/third-party/cpuinfo/include
116116
)
117117
target_compile_options(xnnpack_backend PUBLIC ${_common_compile_options})
118118
target_link_options_shared_lib(xnnpack_backend)
119119

120120
install(
121-
TARGETS xnnpack_backend
121+
TARGETS xnnpack_backend xnnpack_schema
122+
EXPORT ExecuTorchTargets
123+
DESTINATION lib
122124
INCLUDES
123125
DESTINATION ${_common_include_directories}
124126
)

configurations/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,9 @@ if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
6060
executorch_core
6161
)
6262

63-
install(TARGETS optimized_native_cpu_ops_lib DESTINATION lib)
63+
install(
64+
TARGETS optimized_native_cpu_ops_lib
65+
EXPORT ExecuTorchTargets
66+
DESTINATION lib
67+
)
6468
endif()

extension/data_loader/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ endif()
1919
list(TRANSFORM _extension_data_loader__srcs PREPEND "${EXECUTORCH_ROOT}/")
2020
add_library(extension_data_loader ${_extension_data_loader__srcs})
2121
target_link_libraries(extension_data_loader executorch_core)
22-
target_include_directories(extension_data_loader PUBLIC ${EXECUTORCH_ROOT}/..)
22+
target_include_directories(
23+
extension_data_loader PUBLIC ${_common_include_directories}
24+
)
2325
target_compile_options(extension_data_loader PUBLIC ${_common_compile_options})
2426

2527
# Install libraries
2628
install(
2729
TARGETS extension_data_loader
30+
EXPORT ExecuTorchTargets
2831
DESTINATION lib
2932
INCLUDES
3033
DESTINATION ${_common_include_directories}

extension/flat_tensor/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ add_library(extension_flat_tensor ${_extension_flat_tensor__srcs})
2121
target_link_libraries(extension_flat_tensor executorch_core)
2222
target_include_directories(
2323
extension_flat_tensor
24-
PUBLIC ${EXECUTORCH_ROOT}/..
25-
"${CMAKE_BINARY_DIR}/extension/flat_tensor/include"
26-
"${EXECUTORCH_ROOT}/third-party/flatbuffers/include"
24+
PUBLIC $<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/extension/flat_tensor/include>
25+
$<BUILD_INTERFACE:${EXECUTORCH_ROOT}/third-party/flatbuffers/include>
2726
${_common_include_directories}
2827
)
2928
target_compile_options(extension_flat_tensor PUBLIC ${_common_compile_options})
3029

3130
# Install libraries
3231
install(
3332
TARGETS extension_flat_tensor
33+
EXPORT ExecuTorchTargets
3434
DESTINATION lib
3535
INCLUDES
3636
DESTINATION ${_common_include_directories}

0 commit comments

Comments
 (0)