cmake_minimum_required(VERSION 2.6)
project(projectName)
set(CMAKE_PREFIX_PATH "/home/pi/pytorch/torch") # Adding the directory where torch as been installed
set(CMAKE_CXX_STANDARD 14) # C14 required to compile Torch
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0) # Torch is compiled with CXX11_ABI, so your program needs to be also, or you may have conflicts in some libraries (such as GTest for example)
# Specifying we are using pthread for UNIX systems.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS} -pthread -Wall")
find_package(Torch REQUIRED)
if(NOT Torch_FOUND)
message(FATAL_ERROR "Pytorch Not Found!")
endif(NOT Torch_FOUND)
message(STATUS "Pytorch status :")
message(STATUS " libraries: ${TORCH_LIBRARIES}")
message(STATUS " Torch Flags: ${TORCH_CXX_FLAGS}")
# Program executable
add_executable(projectName <sources>)
target_link_libraries(projectName PRIVATE pthread dl util ${TORCH_LIBRARIES})