[CMake] Last minute build-date file.

william.crocker at analog.com william.crocker at analog.com
Fri Oct 15 10:14:06 EDT 2010


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

-------------------- CMake code --------------

# Note that this is a simplified version of the real thing
# and may contain syntax errors.

add_executable( myapp myapp.cc  )
target_link_libraries( myapp lib1 lib2 )
set_target_properties( myapp PROPERTIES LINK_FLAGS link_date.o )

add_custom_command(
     TARGET myapp PRE_LINK
     COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/create_link_date
     COMMAND gcc -m32 -c -I${UTILDIR} link_date.cc
     COMMENT "Make the link_date file"
     VERBATIM
)

------------- Contents of create_link_date ----------

#!/bin/csh

echo 'const char *link_date() { return("'`date`'"); }' > link_date.cc



More information about the CMake mailing list