How to build C++ extension with Cmake?

Is it possible to build Pytorch cpp extension for Python with Cmake? How can I do it?

I’m trying to use this example for writing cpp extension for Python

The problem is Pybind11:
if I don’t include Pybind, but use only Pytorch library, there is an error

third_party/libtorch/include/pybind11/detail/common.h:112:10: fatal error: ‘Python.h’ file not found

If I include pybind using add_subdirectory(third_party/pybind11) everything is compiled, but when I try to import library in python code, there is a strange error

Key already registered with the same priority: VariableHooks

Solved, everything works. I tried to use different versions of Pytorch with extension and when importing it.