Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multiple find_package(Torch) calls (#8407)
While debugging the build issue on #8322 w.r.t mkl, I undercover a complex interaction between #8322, #8248 (to install mkl), and https://github.com/pytorch/pytorch/blob/main/cmake/public/mkl.cmake from PyTorch. The error is as follows: ``` CMake Error at /opt/conda/envs/py_3.10/lib/cmake/mkl/MKLConfig.cmake:744 (add_library): <-- This file comes from conda mkl add_library cannot create imported target "MKL::MKL" because another target with the same name already exists. Call Stack (most recent call first): /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/share/cmake/Caffe2/public/mkl.cmake:1 (find_package) <-- this is from PyTorch /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/share/cmake/Caffe2/Caffe2Config.cmake:106 (include) /opt/conda/envs/py_3.10/lib/python3.10/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:68 (find_package) CMakeLists.txt:753 (find_package) ``` The conclusion is that, with mkl installed, there should be just one `find_package(Torch)` call because the mkl target is defined globally. The `torch` target, on the other hand, is only defined locally. So, this change adds `if(NOT TARGET torch)` check to only call `find_package(Torch)` if needed. ### Testing The change on top of #8322 looks like this f705b01 https://github.com/pytorch/executorch/actions/runs/13278590926?pr=8399
- Loading branch information