[CMake] Last minute build-date file.

fatman at crackmonkey.us fatman at crackmonkey.us
Fri Oct 15 12:28:10 EDT 2010


On Fri, 15 Oct 2010 12:00:02 -0400
cmake-request at cmake.org wrote:

> Hello:
> 
> If my app requires relinking, then at link time
> I would like to capture the current date and time and place it
> in a last-minute source file which is linked with the application.
> Following is my attempt at this with CMake.
> 
> The problems I can see are:
> 1 - It is not portable as it uses the OS date command.
> 2 - It is not portable as it calls gcc directly.
> 3 - It will not work with Debug or Release builds unless
>      I set additional target LINK_FLAGS_<type> properties.
> 4 - I wish the creation of the link_date.cc file could be
>      done inline of the add_custom_command instead of requiring
>      a separate file. (I got into quoting hell.)
> 5 - Sneaking link_date.o onto the link line with the LINK_FLAGS
>      property is kind of a hack.
> 
> Suggestions please.
> 
> Thanks in advance.
> 
> Bill

This is just OTTOMH, but could you have something like this:

#include <string>
const std::string link_date( __DATE__ );
const std::string link_time( __TIME__ );

in a separate blah.cc file? Then set the "blah" target to one of the
PHONYs in the Makefile (those are the ones that always recompile
regardless, right?), and make sure it's a requirement for every link.

Not sure how else you could accomplish this.


More information about the CMake mailing list