How do I specify the path to libtorch folder in a camke script?

Hello!

How do I set the path for my torch files? When I use find_package(Torch REQUIRED) it rather finds the packages installed by pip in AppData than the folder of libtorch that I have downloaded? I tried setting TORCH_HOME to the folder I downloaded but it did not help?

So far I have been using libtorch with CPU only. However, it’s time to changed that so I have downloaded the libtorch-cuda package. Following the Minimal Example-guide works fine and I threw in:

if (torch::cuda::is_available()) {
std::cout << “CUDA available! Training on GPU.” << std::endl;
} else {
std::cout << “Training on CPU.” << std::endl;

which confirms that cuda is working.

Now I want to implement this in my project, the current way I build torch with my C++ project is that I:
set TORCH_LIBRARIES=C:\Users\a3772\Documents\libtorch\include

and then in my project cmake-file I use find_package(Torch REQUIRED). However when I later check if cuda is available in my project (after rebuilding), its not?..

It seems like that find_package(Torch REQUIRED) finds the one I installed with pip half a year ago?..

Stupid me forgot to set set CMAKE_PREFIX_PATH=%TORCH_HOME% this early in the morning.