1- #use git for a pretty commit id
2- #uses 'git describe --tags', so tags are required in the repo
3- #create a tag with 'git tag <name>' and 'git push --tags'
1+ # creates sc_version_string.h, which defines sc_version()
2+ # sc_version() returns a pretty commit description and a build timestamp.
43
54# http://stackoverflow.com/questions/3780667
65# http://www.cmake.org/pipermail/cmake/2009-February/027014.html
76
8- #sc_version_string.h defines sc_version() which returns a pretty commit description and a build timestamp.
97
108set (SC_IS_SUBBUILD "@SC_IS_SUBBUILD@" )
119
12- #---------- find version ------------------
10+ #---------- find commit id ------------------
11+ #use git for a pretty commit id
12+ #uses 'git describe --tags', so tags are required in the repo
13+ #create a tag with 'git tag <name>' and 'git push --tags'
14+ #if git can't be found, uses contents of SC_VERSION.txt
15+
1316set (VERS_FILE ${SOURCE_DIR} /SC_VERSION.txt )
1417if ( EXISTS ${SOURCE_DIR} /.git )
1518 find_package (Git QUIET )
3639endif ()
3740string ( REPLACE "\n " "" GIT_COMMIT_ID ${GIT_COMMIT_ID} )
3841
39- #-------------- Date and time ---------------
40- #cmake 2.8.11 and up only
42+ #-------------- date and time ---------------
43+ #once cmake_minimum_required is >= 2.8.11, we can use TIMESTAMP:
4144#string( TIMESTAMP date_time_string )
4245
4346if ( UNIX )
@@ -56,13 +59,14 @@ endif()
5659set ( header_string "/* sc_version_string.h - written by cmake. Changes will be lost! */\n "
5760 "#ifndef SC_VERSION_STRING\n "
5861 "#define SC_VERSION_STRING\n\n "
59- "/*\n ** Returns a string like \" test-1-g5e1fb47, build timestamp <timestamp> \" , where test is the\n "
62+ "/*\n ** The git commit id looks like \" test-1-g5e1fb47\" , where test is the\n "
6063 "** name of the last tagged git revision, 1 is the number of commits since that tag,\n "
61- "** 'g' is unknown, 5e1fb47 is the first 7 chars of the git sha1 commit id, and <timestamp>\n "
62- "** is a string on known platforms and preprocessor macros elsewhere.\n */\n\n "
63- "const char* sc_version() {\n "
64- " return \" git commit id ${GIT_COMMIT_ID} , build timestamp ${date_time_string} \"\;\n "
65- "}\n\n "
64+ "** 'g' is unknown, and 5e1fb47 is the first 7 chars of the git sha1 commit id.\n "
65+ "** timestamp is created from date/time commands on known platforms, and uses\n "
66+ "** preprocessor macros elsewhere.\n */\n\n "
67+ "static char sc_version[512] = {\n "
68+ " \" git commit id: ${GIT_COMMIT_ID} , build timestamp ${date_time_string} \"\n "
69+ "}\;\n\n "
6670 "#endif\n "
6771 )
6872
0 commit comments