Unknown CMake command "cuda_select_nvcc_arch_flags"

I am using cmake in my application and it results in the following errors:

CMake Error at /home/divyansh/Documents/libtorch-cxx11-abi-shared-with-deps-2.0.1+cu118/libtorch/share/cmake/Caffe2/public/utils.cmake:401 (cuda_select_nvcc_arch_flags):
  Unknown CMake command "cuda_select_nvcc_arch_flags".
Call Stack (most recent call first):
  /home/divyansh/Documents/libtorch-cxx11-abi-shared-with-deps-2.0.1+cu118/libtorch/share/cmake/Caffe2/public/cuda.cmake:362 (torch_cuda_get_nvcc_gencode_flag)
  /home/divyansh/Documents/libtorch-cxx11-abi-shared-with-deps-2.0.1+cu118/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:88 (include)
  /home/divyansh/.local/lib/python3.10/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:290 (find_package)

My cmake version is 3.27.0

Double post from here.

That issue is 5 years old, the assignees might not respond, so I opened an issue here. Sorry for the repetition.

Based on a few related issues, such as this one, it seems updating cmake to >=3.9 fixes the issue. However, I’m unsure why it’s not working with your newer version, as I’m also using 3.27.4 and haven’t seen the error.

Thank you for your response! Do you have any suggestions on how I can know what the issue is?

Update: Specifying the path of the torch configuration files using -DCMAKE_PREFIX_PATH resolved the issue.