CMakeLists.txt:
add_definitions(-DSYSMONITER_VER="${VER}")
c++代码:
void displayVersion(){
#ifdef SYSMONITER_VER
std::cout << SYSMONITER_VER << std::endl;
#endif
}
编译命令:
cmake .. -DVER=$(date "+%Y%m%d%H%M%S")
这里的date用作示例,可以把git commit拿过来$(git log | awk -F' ' 'NR==1{print $2}')