Build standalone C++ program from sources

I have downloaded the source code for pytorch using
git clone --recursive https://github.com/pytorch/pytorch

The sources are downloaded to ~/pytorch

Now I have a very simple C++ app:

#include <torch/torch.h>
#include <iostream>

int main() {
  torch::Tensor tensor = torch::rand({2, 3});
  std::cout << tensor << std::endl;
}

Can I build this into a single standalone executable with cmake? I want to build an executable with -o3 that does not need the presence of libtorch.a. How can I do this?