1 CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3)
\r
3 # ROOT_DIR should be set to root of the repository (where to find the .svn or .hg directory)
\r
4 # SOURCE_DIR should be set to root of your code (where to find CMakeLists.txt)
\r
5 # BINARY_DIR should be set to root of your build directory
\r
8 # Replace spaces by semi-columns
\r
9 IF(CMAKE_MODULE_PATH)
\r
10 STRING(REPLACE " " ";" CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
\r
13 SET(CMAKE_MODULE_PATH ${SOURCE_DIR}/CMakeModules ${CMAKE_MODULE_PATH})
\r
15 IF(NOT ROOT_DIR AND SOURCE_DIR)
\r
16 SET(ROOT_DIR ${SOURCE_DIR})
\r
19 IF(NOT SOURCE_DIR AND ROOT_DIR)
\r
20 SET(SOURCE_DIR ${ROOT_DIR})
\r
23 SET(SOURCE_DIR ${CMAKE_SOURCE_DIR})
\r
24 SET(ROOT_DIR ${CMAKE_SOURCE_DIR}/..)
\r
26 # convert ROOT_DIR to absolute path
\r
27 GET_FILENAME_COMPONENT(ROOT_DIR ${ROOT_DIR} ABSOLUTE)
\r
31 IF(CMAKE_VERSION VERSION_GREATER "2.8.10")
\r
32 STRING(TIMESTAMP ${RESULT} "%Y-%m-%d %H:%M:%S")
\r
35 EXECUTE_PROCESS(COMMAND "wmic" "os" "get" "localdatetime" OUTPUT_VARIABLE DATETIME)
\r
36 IF(NOT DATETIME MATCHES "ERROR")
\r
37 STRING(REGEX REPLACE ".*\n([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9]).*" "\\1-\\2-\\3 \\4:\\5:\\6" ${RESULT} "${DATETIME}")
\r
40 EXECUTE_PROCESS(COMMAND "date" "+%Y-%m-%d %H:%M:%S" OUTPUT_VARIABLE DATETIME)
\r
41 STRING(REGEX REPLACE "([0-9: -]+).*" "\\1" ${RESULT} "${DATETIME}")
\r
43 MESSAGE(SEND_ERROR "date not implemented")
\r
44 SET(${RESULT} "0000-00-00 00:00:00")
\r
49 IF(EXISTS "${ROOT_DIR}/.svn/")
\r
50 FIND_PACKAGE(Subversion QUIET)
\r
52 IF(SUBVERSION_FOUND)
\r
53 Subversion_WC_INFO(${ROOT_DIR} ER)
\r
54 SET(REVISION ${ER_WC_REVISION})
\r
57 FIND_PACKAGE(TortoiseSVN QUIET)
\r
59 IF(TORTOISESVN_FOUND)
\r
60 TORTOISESVN_GET_REVISION(${ROOT_DIR} REVISION)
\r
64 IF(EXISTS "${ROOT_DIR}/.hg/")
\r
65 FIND_PACKAGE(Mercurial)
\r
68 Mercurial_WC_INFO(${ROOT_DIR} ER)
\r
69 SET(REVISION ${ER_WC_REVISION})
\r
70 SET(CHANGESET ${ER_WC_CHANGESET})
\r
71 SET(BRANCH ${ER_WC_BRANCH})
\r
75 IF(EXISTS "${ROOT_DIR}/.git/")
\r
79 EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
\r
80 WORKING_DIRECTORY ${ROOT_DIR}
\r
81 RESULT_VARIABLE git_exit_code
\r
82 OUTPUT_VARIABLE REVISION)
\r
83 IF(NOT ${git_exit_code} EQUAL 0)
\r
84 MESSAGE(WARNING "git rev-list failed, unable to include version.")
\r
86 STRING(STRIP ${REVISION} REVISION)
\r
88 EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
\r
89 WORKING_DIRECTORY ${ROOT_DIR}
\r
90 RESULT_VARIABLE git_exit_code
\r
91 OUTPUT_VARIABLE CHANGESET)
\r
92 IF(NOT ${git_exit_code} EQUAL 0)
\r
93 MESSAGE(WARNING "git rev-parse failed, unable to include version.")
\r
95 STRING(STRIP ${CHANGESET} CHANGESET)
\r
97 EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
\r
98 WORKING_DIRECTORY ${ROOT_DIR}
\r
99 RESULT_VARIABLE git_exit_code
\r
100 OUTPUT_VARIABLE BRANCH)
\r
101 IF(NOT ${git_exit_code} EQUAL 0)
\r
102 MESSAGE(WARNING "git rev-parse failed, unable to include git branch.")
\r
104 STRING(STRIP ${BRANCH} BRANCH)
\r
106 EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe
\r
107 WORKING_DIRECTORY ${ROOT_DIR}
\r
108 RESULT_VARIABLE git_exit_code
\r
109 OUTPUT_VARIABLE DESCRIBE)
\r
110 IF(NOT ${git_exit_code} EQUAL 0)
\r
111 MESSAGE(WARNING "git rev-parse failed, unable to include git branch.")
\r
113 STRING(STRIP ${DESCRIBE} DESCRIBE)
\r
118 # if processing exported sources, use "revision" file if exists
\r
119 IF(SOURCE_DIR AND NOT DEFINED REVISION)
\r
120 SET(REVISION_FILE ${SOURCE_DIR}/revision)
\r
121 IF(EXISTS ${REVISION_FILE})
\r
122 FILE(STRINGS ${REVISION_FILE} REVISION LIMIT_COUNT 1)
\r
123 MESSAGE(STATUS "Read revision ${REVISION} from file")
\r
127 IF(DEFINED REVISION)
\r
128 MESSAGE(STATUS "Found revision ${REVISION}")
\r