Hi devs.
I’m trying to make a cpp project that uses libtorch (C++ distributions of pytorch) using meson build.
It has one simple cpp file of about 50 lines that runs deep learning on images.
First, I confirmed that my project runs well in two environments.
- Since meson uses the pkg-config file, I made a simple pkg-config file for libtorch, and it works for a project running on the CPU.
- libtorch provides a TorchConfig.cmake file, so I used cmake to confirm that my project runs on the GPU version.
However, I don’t know how to build the GPU version of the project using meson.
The TorchConfig.cmake file is more complicated than I thought, so it was very difficult to make it manually with the pkg-config file.
(TorchConfig.cmake file references many cmake files in libtorch directories.)
I also tried to use libtorch_dep = dependency(‘Torch’, method : ‘cmake’), but it only found libtorch.so among many libtorch libraries that are for GPU APIs.
So, how can I build the project using libtorch with only cmake config file like this with meson?
Or is there a way to utilize the cmake config file to write a pkg-config file?
Any comments or suggestions would be appreciated.
P.S.
This is my CMakeLists.txt file for testing GPU version of my project.
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(custom_ops)
set(LIBTORCH "/usr/local/lib/libtorch")
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${LIBTORCH}")
find_package(Torch REQUIRED)
find_package(OpenCV REQUIRED)
add_executable(example-app example-app.cpp)
target_link_libraries(example-app "${TORCH_LIBRARIES}")
target_link_libraries(example-app "${OpenCV_LIBS}")
set_property(TARGET example-app PROPERTY CXX_STANDARD 14)
This is pytorch.pc file for CPU version of the project using meson build.
prefix=/usr/local/lib/libtorch
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
sharedlibdir=${prefix}/share
Name: libtorch
Description: libtorch library
Version: 1.8.0
Libs: -L${libdir} -L${sharedlibdir} -lc10 -ltorch -ltorch_cpu
Cflags: -I${includedir}
If these information alone are not enough, I can provide the cpp code for reproduction.
operating system: Ubuntu 18.04
meson version: 0.54.0
cmake version: 3.22.1
libtorch version: 1.8.0