Old answer, but I've made a VM detection library in C++ that is meant to do exactly this.
https://github.com/kernelwernel/VMAware
All the techniques mentioned in this post are included in the library.