Fix multiple find_package(Torch) calls #8407
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
The conclusion is that, with mkl installed, there should be just one
find_package(Torch)
call because the mkl target is defined globally. Thetorch
target, on the other hand, is only defined locally.So, this change adds
if(NOT TARGET torch)
check to only callfind_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