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)
|
2015-12-15 12:41:27 +00:00
|
|
|
# BINARY_DIR should be set to root of your build directory
|
2012-03-06 13:21:23 +00:00
|
|
|
|
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})
|
2015-11-29 13:06:05 +00:00
|
|
|
ENDIF()
|
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})
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
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})
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
|
|
|
ELSE()
|
2013-09-06 06:44:57 +00:00
|
|
|
SET(SOURCE_DIR ${CMAKE_SOURCE_DIR})
|
2015-11-29 13:11:17 +00:00
|
|
|
SET(ROOT_DIR ${CMAKE_SOURCE_DIR}/..)
|
|
|
|
|
|
|
|
# convert ROOT_DIR to absolute path
|
|
|
|
GET_FILENAME_COMPONENT(ROOT_DIR ${ROOT_DIR} ABSOLUTE)
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
2012-03-06 13:21:23 +00:00
|
|
|
|
|
|
|
MACRO(NOW RESULT)
|
2015-11-29 13:10:42 +00:00
|
|
|
IF(CMAKE_VERSION VERSION_GREATER "2.8.10")
|
|
|
|
STRING(TIMESTAMP ${RESULT} "%Y-%m-%d %H:%M:%S")
|
2015-02-14 12:47:37 +00:00
|
|
|
ELSE()
|
2015-11-29 13:10:42 +00:00
|
|
|
IF(WIN32)
|
|
|
|
EXECUTE_PROCESS(COMMAND "wmic" "os" "get" "localdatetime" OUTPUT_VARIABLE DATETIME)
|
|
|
|
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()
|
|
|
|
ELSEIF(UNIX)
|
|
|
|
EXECUTE_PROCESS(COMMAND "date" "+%Y-%m-%d %H:%M:%S" OUTPUT_VARIABLE DATETIME)
|
|
|
|
STRING(REGEX REPLACE "([0-9: -]+).*" "\\1" ${RESULT} "${DATETIME}")
|
|
|
|
ELSE()
|
|
|
|
MESSAGE(SEND_ERROR "date not implemented")
|
|
|
|
SET(${RESULT} "0000-00-00 00:00:00")
|
|
|
|
ENDIF()
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
2015-11-29 13:06:05 +00:00
|
|
|
ENDMACRO()
|
2012-03-06 13:21:23 +00:00
|
|
|
|
|
|
|
IF(EXISTS "${ROOT_DIR}/.svn/")
|
2015-02-14 12:47:37 +00:00
|
|
|
FIND_PACKAGE(Subversion QUIET)
|
2012-03-06 13:21:23 +00:00
|
|
|
|
|
|
|
IF(SUBVERSION_FOUND)
|
|
|
|
Subversion_WC_INFO(${ROOT_DIR} ER)
|
|
|
|
SET(REVISION ${ER_WC_REVISION})
|
2015-11-29 13:06:05 +00:00
|
|
|
ENDIF()
|
2015-02-14 12:47:37 +00:00
|
|
|
|
|
|
|
FIND_PACKAGE(TortoiseSVN QUIET)
|
|
|
|
|
|
|
|
IF(TORTOISESVN_FOUND)
|
|
|
|
TORTOISESVN_GET_REVISION(${ROOT_DIR} REVISION)
|
2015-11-29 13:06:05 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
2012-03-06 13:21:23 +00:00
|
|
|
|
|
|
|
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})
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
2012-03-06 13:21:23 +00:00
|
|
|
|
2019-05-09 22:49:30 +00:00
|
|
|
IF(EXISTS "${ROOT_DIR}/.git/")
|
|
|
|
FIND_PACKAGE(Git)
|
|
|
|
|
|
|
|
IF(GIT_FOUND)
|
|
|
|
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-list HEAD --count
|
|
|
|
WORKING_DIRECTORY ${ROOT_DIR}
|
|
|
|
RESULT_VARIABLE git_exit_code
|
|
|
|
OUTPUT_VARIABLE REVISION)
|
|
|
|
IF(NOT ${git_exit_code} EQUAL 0)
|
2019-05-10 21:56:18 +00:00
|
|
|
MESSAGE(WARNING "git rev-list failed, unable to include version.")
|
2019-05-11 00:39:12 +00:00
|
|
|
ELSE()
|
|
|
|
STRING(STRIP ${REVISION} REVISION)
|
2019-05-09 22:49:30 +00:00
|
|
|
ENDIF()
|
|
|
|
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse --short=8 HEAD
|
|
|
|
WORKING_DIRECTORY ${ROOT_DIR}
|
|
|
|
RESULT_VARIABLE git_exit_code
|
|
|
|
OUTPUT_VARIABLE CHANGESET)
|
|
|
|
IF(NOT ${git_exit_code} EQUAL 0)
|
2019-05-10 21:56:18 +00:00
|
|
|
MESSAGE(WARNING "git rev-parse failed, unable to include version.")
|
2019-05-11 00:39:12 +00:00
|
|
|
ELSE()
|
|
|
|
STRING(STRIP ${CHANGESET} CHANGESET)
|
2019-05-09 22:49:30 +00:00
|
|
|
ENDIF()
|
|
|
|
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
|
|
|
|
WORKING_DIRECTORY ${ROOT_DIR}
|
|
|
|
RESULT_VARIABLE git_exit_code
|
|
|
|
OUTPUT_VARIABLE BRANCH)
|
|
|
|
IF(NOT ${git_exit_code} EQUAL 0)
|
2019-05-10 21:56:18 +00:00
|
|
|
MESSAGE(WARNING "git rev-parse failed, unable to include git branch.")
|
2019-05-11 00:39:12 +00:00
|
|
|
ELSE()
|
|
|
|
STRING(STRIP ${BRANCH} BRANCH)
|
2019-05-10 21:56:18 +00:00
|
|
|
ENDIF()
|
|
|
|
EXECUTE_PROCESS(COMMAND ${GIT_EXECUTABLE} describe
|
|
|
|
WORKING_DIRECTORY ${ROOT_DIR}
|
|
|
|
RESULT_VARIABLE git_exit_code
|
|
|
|
OUTPUT_VARIABLE DESCRIBE)
|
|
|
|
IF(NOT ${git_exit_code} EQUAL 0)
|
|
|
|
MESSAGE(WARNING "git rev-parse failed, unable to include git branch.")
|
2019-05-11 00:39:12 +00:00
|
|
|
ELSE()
|
|
|
|
STRING(STRIP ${DESCRIBE} DESCRIBE)
|
2019-05-09 22:49:30 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
|
2013-09-06 06:44:57 +00:00
|
|
|
# if processing exported sources, use "revision" file if exists
|
|
|
|
IF(SOURCE_DIR AND NOT DEFINED REVISION)
|
|
|
|
SET(REVISION_FILE ${SOURCE_DIR}/revision)
|
|
|
|
IF(EXISTS ${REVISION_FILE})
|
|
|
|
FILE(STRINGS ${REVISION_FILE} REVISION LIMIT_COUNT 1)
|
|
|
|
MESSAGE(STATUS "Read revision ${REVISION} from file")
|
2015-02-14 12:47:37 +00:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
2015-11-29 13:35:55 +00:00
|
|
|
|
|
|
|
IF(DEFINED REVISION)
|
|
|
|
MESSAGE(STATUS "Found revision ${REVISION}")
|
2018-07-03 08:09:15 +00:00
|
|
|
ELSE()
|
|
|
|
SET(REVISION 0)
|
2015-11-29 13:35:55 +00:00
|
|
|
ENDIF()
|