You can follow this doc:
https://raw.githubusercontent.com/pytorch/pytorch/master/docs/libtorch.rst 63
You need to create a build dir and run the commands there.
The paths can be set as arguments of tools/build_pytorch_libs.sh