stepcode/cmake/scl_version_string.cmake
Mark Pictor 13204e4027 change scl_version_string.cmake to fix parallel ctest issue
This replaces use of the system time command with __DATE__ and __TIME__

I think the following two errors are caused by fedex_plus being rebuilt for each test:

Linking CXX executable ../../bin/fedex_plus
CMakeFiles/fedex_plus.dir/__/express/fedex.c.o: file not recognized: File truncated

and

[ 87%] Running fedex_plus for AP214E3_2010...
/bin/sh: /opt/step/test-scl/build_ctest/bin/fedex_plus: Text file busy

fedex_plus is being rebuilt because the version string changes, since it contains the date and time.
2011-12-07 18:44:43 -05:00

48 lines
2.3 KiB
CMake

#use git for a pretty commit id
#uses 'git describe --tags', so tags are required in the repo
#create a tag with 'git tag <name>' and 'git push --tags'
# http://stackoverflow.com/questions/3780667
# http://www.cmake.org/pipermail/cmake/2009-February/027014.html
#scl_version_string.h defines scl_version() which returns a pretty commit description and a build timestamp.
set(VERS_FILE ${SOURCE_DIR}/SCL_VERSION.txt )
if( EXISTS ${SOURCE_DIR}/.git )
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags RESULT_VARIABLE res_var OUTPUT_VARIABLE GIT_COMMIT_ID )
if( NOT ${res_var} EQUAL 0 )
file( READ ${VERS_FILE} GIT_COMMIT_ID LIMIT 255 )
message( WARNING "Git failed (probably no tags in repo). Build will contain revision info from ${VERS_FILE}." )
endif()
else(GIT_FOUND)
file( READ ${VERS_FILE} GIT_COMMIT_ID LIMIT 255 )
message( WARNING "Git not found. Build will contain revision info from ${VERS_FILE}." )
endif(GIT_FOUND)
else()
file( READ ${VERS_FILE} GIT_COMMIT_ID LIMIT 255 )
message( WARNING "Git failed ('.git' not found). Build will contain revision info from ${VERS_FILE}." )
endif()
string( REPLACE "\n" "" GIT_COMMIT_ID ${GIT_COMMIT_ID} )
set( vstring "//scl_version_string.h - written by cmake. Changes will be lost!\n"
"#ifndef SCL_VERSION_STRING\n"
"#define SCL_VERSION_STRING\n\n"
"/*\n** Returns a string like \"test-1-g5e1fb47, built on <timestamp>\", where test is the\n"
"** name of the last tagged git revision, 1 is the number of commits since that tag,\n"
"** 'g' is unknown, 5e1fb47 is the first 7 chars of the git sha1 commit id, and\n"
"** <timestamp> is the output of your system's 'date' command.\n*/\n\n"
"const char* scl_version() {\n"
" return \"git commit id ${GIT_COMMIT_ID}, built at \"__TIME__\" on \"__DATE__\;\n"
"}\n\n"
"#endif\n"
)
file(WRITE scl_version_string.h.txt ${vstring} )
# copy the file to the final header only if the version changes
# reduces needless rebuilds
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
scl_version_string.h.txt ${BINARY_DIR}/include/scl_version_string.h)
message("-- scl_version_string.h is up-to-date.")