使用cmake编译日期和时间 [英] Compile date and time using cmake
问题描述
在使用make开发版本时,我想使用cmake将VERSION设置为发行版本的发行版本,否则为编译时间。编译时间很容易通过
-DVERSION =`date +%Y-%m-%d_%H:%M`
可以直接使用c / c ++源代码。不幸的是,我还没有找到在使用cmake时如何做到这一点。
string(TIMESTAMP VERSION%Y- %m-%d%H:%M)
add_definitions(-DVERSION =$ {VERSION})
将VERSION设置为执行cmake的时间。如何在使用cmake时将VERSION设置为编译时间(以避免在 __ DATE __
和 __ TIME __
没有RELEASE标志)
对于最近的CMake版本(> = 2.8.11):
string(TIMESTAMP {output variable} [{format string}] [UTC])
(请参阅http://www.cmake.org/cmake/help/v3.0/command/string.html)
I want to use cmake to set VERSION to a release version in case of release builds and to the compile time otherwise.
When using make for development builds, obtaining the compile time was easy via
-DVERSION=`date +%Y-%m-%d_%H:%M`
which could be used straight forward by c/c++ source code. Unfortunately, I haven't found out how the same can be achieved when using cmake.
string(TIMESTAMP VERSION "%Y-%m-%d %H:%M")
add_definitions(-DVERSION="${VERSION}")
sets VERSION to the time cmake was executed. How can I set VERSION to the compile time when using cmake (to avoid having to fiddle with __DATE__
and __TIME__
in the absence of a RELEASE flag)?
For relatively recent versions of CMake (>=2.8.11):
string(TIMESTAMP {output variable} [{format string}] [UTC])
(see http://www.cmake.org/cmake/help/v3.0/command/string.html)
这篇关于使用cmake编译日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!