2012-03-06 13:21:23 +00:00
|
|
|
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3)
|
|
|
|
|
|
|
|
# ROOT_DIR should be set to root of the repository (where to find the .svn or .hg directory)
|
|
|
|
# SOURCE_DIR should be set to root of your code (where to find CMakeLists.txt)
|
|
|
|
|
2012-10-22 12:56:25 +00:00
|
|
|
IF(SOURCE_DIR)
|
|
|
|
# Replace spaces by semi-columns
|
|
|
|
IF(CMAKE_MODULE_PATH)
|
|
|
|
STRING(REPLACE " " ";" CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH})
|
|
|
|
ENDIF(CMAKE_MODULE_PATH)
|
2012-03-14 23:15:03 +00:00
|
|
|
|
2012-10-22 12:56:25 +00:00
|
|
|
SET(CMAKE_MODULE_PATH ${SOURCE_DIR}/CMakeModules ${CMAKE_MODULE_PATH})
|
2012-03-14 23:15:03 +00:00
|
|
|
|
2012-10-22 12:56:25 +00:00
|
|
|
IF(NOT ROOT_DIR AND SOURCE_DIR)
|
|
|
|
SET(ROOT_DIR ${SOURCE_DIR})
|
|
|
|
ENDIF(NOT ROOT_DIR AND SOURCE_DIR)
|
2012-03-14 23:15:03 +00:00
|
|
|
|
2012-10-22 12:56:25 +00:00
|
|
|
IF(NOT SOURCE_DIR AND ROOT_DIR)
|
|
|
|
SET(SOURCE_DIR ${ROOT_DIR})
|
|
|
|
ENDIF(NOT SOURCE_DIR AND ROOT_DIR)
|
|
|
|
ELSE(SOURCE_DIR)
|
|
|
|
SET(ROOT_DIR ${CMAKE_SOURCE_DIR})
|
|
|
|
ENDIF(SOURCE_DIR)
|
2012-03-06 13:21:23 +00:00
|
|
|
|
|
|
|
MACRO(NOW RESULT)
|
|
|
|
IF (WIN32)
|
2012-04-07 21:16:04 +00:00
|
|
|
EXECUTE_PROCESS(COMMAND "wmic" "os" "get" "localdatetime" OUTPUT_VARIABLE DATETIME)
|
2012-03-14 23:15:03 +00:00
|
|
|
IF(NOT DATETIME MATCHES "ERROR")
|
|
|
|
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}")
|
|
|
|
ENDIF(NOT DATETIME MATCHES "ERROR")
|
2012-03-06 13:21:23 +00:00
|
|
|
ELSEIF(UNIX)
|
2012-04-07 21:16:04 +00:00
|
|
|
EXECUTE_PROCESS(COMMAND "date" "+%Y-%m-%d %H:%M:%S" OUTPUT_VARIABLE DATETIME)
|
|
|
|
STRING(REGEX REPLACE "([0-9: -]+).*" "\\1" ${RESULT} "${DATETIME}")
|
2012-03-06 13:21:23 +00:00
|
|
|
ELSE (WIN32)
|
|
|
|
MESSAGE(SEND_ERROR "date not implemented")
|
2012-03-14 23:15:03 +00:00
|
|
|
SET(${RESULT} "0000-00-00 00:00:00")
|
2012-03-06 13:21:23 +00:00
|
|
|
ENDIF (WIN32)
|
|
|
|
ENDMACRO(NOW)
|
|
|
|
|
|
|
|
IF(EXISTS "${ROOT_DIR}/.svn/")
|
|
|
|
FIND_PACKAGE(Subversion)
|
|
|
|
|
|
|
|
IF(SUBVERSION_FOUND)
|
|
|
|
Subversion_WC_INFO(${ROOT_DIR} ER)
|
|
|
|
SET(REVISION ${ER_WC_REVISION})
|
|
|
|
ENDIF(SUBVERSION_FOUND)
|
|
|
|
ENDIF(EXISTS "${ROOT_DIR}/.svn/")
|
|
|
|
|
|
|
|
IF(EXISTS "${ROOT_DIR}/.hg/")
|
|
|
|
FIND_PACKAGE(Mercurial)
|
|
|
|
|
|
|
|
IF(MERCURIAL_FOUND)
|
|
|
|
Mercurial_WC_INFO(${ROOT_DIR} ER)
|
|
|
|
SET(REVISION ${ER_WC_REVISION})
|
2012-05-19 21:25:06 +00:00
|
|
|
SET(CHANGESET ${ER_WC_CHANGESET})
|
|
|
|
SET(BRANCH ${ER_WC_BRANCH})
|
2012-03-06 13:21:23 +00:00
|
|
|
ENDIF(MERCURIAL_FOUND)
|
|
|
|
ENDIF(EXISTS "${ROOT_DIR}/.hg/")
|
|
|
|
|
2012-10-22 12:56:25 +00:00
|
|
|
IF(SOURCE_DIR AND DEFINED REVISION)
|
2012-03-06 13:21:23 +00:00
|
|
|
IF(EXISTS ${SOURCE_DIR}/revision.h.in)
|
2012-10-22 12:56:25 +00:00
|
|
|
MESSAGE(STATUS "Revision: ${REVISION}")
|
2012-03-06 13:21:23 +00:00
|
|
|
NOW(BUILD_DATE)
|
|
|
|
CONFIGURE_FILE(${SOURCE_DIR}/revision.h.in revision.h.txt)
|
|
|
|
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy revision.h.txt revision.h) # copy_if_different
|
|
|
|
ENDIF(EXISTS ${SOURCE_DIR}/revision.h.in)
|
2012-10-22 12:56:25 +00:00
|
|
|
ENDIF(SOURCE_DIR AND DEFINED REVISION)
|