File tree Expand file tree Collapse file tree 3 files changed +19
-11
lines changed
Expand file tree Collapse file tree 3 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -321,3 +321,20 @@ function(resolve_python_executable)
321321 )
322322 endif ()
323323endfunction ()
324+
325+ # find_package(Torch CONFIG REQUIRED) replacement for targets that
326+ # have a header-only Torch dependency. Because find_package sets
327+ # variables in the parent scope, we use a macro to preserve this
328+ # rather than maintaining our own list of those variables.
329+ macro (find_package_torch_headers)
330+ # We cannot simply use CMAKE_FIND_ROOT_PATH_BOTH, because that does
331+ # not propagate into TorchConfig.cmake.
332+ foreach (mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE )
333+ set (OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} })
334+ set (CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} BOTH)
335+ endforeach ()
336+ find_package (Torch CONFIG REQUIRED)
337+ foreach (mode_kind IN ITEMS PACKAGE LIBRARY INCLUDE )
338+ set (CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} ${OLD_CMAKE_FIND_ROOT_PATH_MODE_${mode_kind} })
339+ endforeach ()
340+ endmacro ()
Original file line number Diff line number Diff line change @@ -68,9 +68,7 @@ target_compile_options(
6868install (TARGETS custom_ops DESTINATION lib)
6969
7070if (EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
71- # Use NO_CMAKE_FIND_ROOT_PATH to make sure this works even if cross-compiling.
72- # See note in kernels/optimized/CMakeLists.txt.
73- find_package (Torch CONFIG REQUIRED NO_CMAKE_FIND_ROOT_PATH )
71+ find_package_torch_headers()
7472 add_library (
7573 custom_ops_aot_lib SHARED
7674 ${_custom_ops__srcs}
Original file line number Diff line number Diff line change @@ -63,14 +63,7 @@ message("Generated files ${gen_command_sources}")
6363
6464list (TRANSFORM _optimized_kernels__srcs PREPEND "${EXECUTORCH_ROOT} /" )
6565add_library (optimized_kernels ${_optimized_kernels__srcs} )
66- # We require Torch headers, which setup.py puts in CMAKE_PREFIX_PATH
67- # for us. Toolchains that we might be using for cross-compiling could
68- # set CMAKE_FIND_ROOT_PATH, which prevents find_package from finding
69- # headers not rooted under CMAKE_FIND_ROOT_PATH. This is reasonable
70- # for binary dependencies because they probably aren't built for the
71- # target platform, but for our header-only use case, we should just
72- # ignore CMAKE_FIND_ROOT_PATH.
73- find_package (Torch CONFIG REQUIRED NO_CMAKE_FIND_ROOT_PATH )
66+ find_package_torch_headers()
7467target_include_directories (optimized_kernels PRIVATE ${TORCH_INCLUDE_DIRS} )
7568target_link_libraries (
7669 optimized_kernels PRIVATE executorch_core cpublas extension_threadpool
You can’t perform that action at this time.
0 commit comments