I want to add libtorch to two existing projects. So I add:
find_package(torch REQUIRED)
in both cmake files, which gives me the following error:
add_library cannot create target “torch_library” because another target
with the same name already exists. The existing target is an interface
library created in source directory
So the above hints at CMake seeing both find_package statements in one invocation.
If it’s in the same CMake project, I think you can use find_package once and then use the torch “environment” set up by CMake for both.
So you’re trying to make them work separately as well as “in combination”?
One thing you could try is to make the find_package conditional on if (NOT TARGET torch_library) or somesuch to have it executed exactly once.
If that doesn’t solve it, maybe it would help if you showed a bit about your CMake setup.
Thanks you, this can be marked as sloved.
Tried your suggestion but it did not work, this is a huge cmake-project with about 800 cpp different projects. However, I managed to get it working in the end.
Sorry for late reply but I won’t be able to help you with this issue as I did not solve it myself but rather got help from a colleague who specializes in cmake builds.