How can I pass git SHA1 to compiler as definition using cmake?
问题 In a Makefile this would be done with something like: g++ -DGIT_SHA1="`git log -1 | head -n 1`" ... This is very useful, because the binary knows exact commit SHA1 so it can dump it in case of segfault. How can I achieve the same with CMake? 回答1: I've made some CMake modules that peer into a git repo for versioning and similar purposes - they're all in my repository at https://github.com/rpavlik/cmake-modules The good thing about these functions is, they will force a re-configure (a rerun of