Cmake List for Libtorch and ATen

I’m trying to make a OBS plugin using Libtorch. My CMake List runs fine and everything works, including the use of #include <torch/torch.h> , but when I add #include <variable_factories.h> (which has #include <ATen_fwd.h> in it), I get

D:\OBS Modding\obs-plugintemplate\src\tensor-handler.cpp(4): fatal error C1083: Datei (Include) kann nicht geöffnet werden: “ATen_fwd.h”: No such file or directory [D:\OBS Modding\obs-plugintemplate\build_x64\my-test-plugin.
vcxproj]

Here is my CmakeList.txt

cmake_minimum_required(VERSION 3.24...3.26)

set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/common/bootstrap.cmake" NO_POLICY_SCOPE)
include(CMakePrintHelpers)

project(${_name} VERSION ${_version})

option(ENABLE_FRONTEND_API "Use obs-frontend-api for UI functionality" ON)
option(ENABLE_QT "Use Qt functionality" OFF)

include(compilerconfig)
include(defaults)
include(helpers)



add_library(${CMAKE_PROJECT_NAME} MODULE)

find_package(libobs REQUIRED)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::libobs)

#if(ENABLE_FRONTEND_API)
find_package(obs-frontend-api REQUIRED)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE OBS::obs-frontend-api)
#endif()


#Cuda

set(CUDACXX "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8/bin")
include(CheckLanguage)
check_language(CUDA)
enable_language(CUDA)

cmake_print_variables(CMAKE_CXX_COMPILER_ID)
cmake_print_variables(CMAKE_CXX_COMPILER_VERSION)
cmake_print_variables(CUDA_TOOLKIT_ROOT)

find_package(CUDAToolkit REQUIRED)
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC CUDA::cudart)
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC CUDA::cuda_driver)


#Libtorch
list(APPEND CMAKE_PREFIX_PATH "D:/libtorch")


set(Torch_DIR D:/libtorch/share/cmake/Torch)

find_package(Torch REQUIRED CONFIG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${TORCH_LIBRARIES}")
if (MSVC)
  file(GLOB TORCH_DLLS "${TORCH_INSTALL_PREFIX}/lib/*.dll")
  add_custom_command(TARGET ${CMAKE_PROJECT_NAME}
                     POST_BUILD
                     COMMAND ${CMAKE_COMMAND} -E copy_if_different
                     ${TORCH_DLLS}
                     $<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>)
endif (MSVC)

#ATen
#I also tried with this block as uncommented, but it didn't change anything
#set(ATen_DIR D:/libtorch/share/cmake/Aten)
#find_package(ATen REQUIRED)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ATEN_CXX_FLAGS}")
#target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${ATEN_LIBRARIES}")

#set(Caffe2_DIR D:/libtorch/share/cmake/Caffe2)
#find_package(Caffe2 REQUIRED)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CAFFE2_CXX_FLAGS}")
#target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${Caffe2_LIBRARIES}")

#set(fbgemm_DIR D:/libtorch/share/cmake/fbgemm)
#find_library(fbgemm REQUIRED)
#target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${fbgemm_LIBRARIES}")

#set(fbjni_DIR D:/libtorch/share/cmake/fbjni)
#find_package(fbjni REQUIRED)
#target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${fbjni_LIBRARIES}")

#set(kineto_DIR D:/libtorch/share/cmake/kineto)
#find_package(kineto REQUIRED)
#target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE "${kineto_LIBRARIES}")


if(ENABLE_QT)
  find_package(Qt6 COMPONENTS Widgets Core)
  target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Qt6::Core Qt6::Widgets)
  target_compile_options(
    ${CMAKE_PROJECT_NAME} PRIVATE $<$<C_COMPILER_ID:Clang,AppleClang>:-Wno-quoted-include-in-framework-header
                                  -Wno-comma>)
  set_target_properties(
    ${CMAKE_PROJECT_NAME}
    PROPERTIES AUTOMOC ON
               AUTOUIC ON
               AUTORCC ON)
endif()

target_sources(${CMAKE_PROJECT_NAME} PRIVATE src/plugin-main.cpp src/frameGrabberFilter.cpp src/positioning-output.cpp src/tensor-handler.cpp)

set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name})


I also tried to find a way to add ATen seperately to my CMakeList.txt, but could’t make it work.

The problem were the imports. The correct imports are

#include <ATen/core/ATen_fwd.h>
#include <torch/csrc/autograd/generated/variable_factories.h>

It seems like the Libtorch headers are very well hidden. To find any import search the function (in C/C++ code aka with :: instead of .) on https://pytorch.org/, then click on “defined in [file_name].h” and look under “Definition”. There is the full import path.