2011-02-25 04:02:58 +00:00
|
|
|
# This is called by cmake as an extermal process from
|
2011-02-24 17:57:35 +00:00
|
|
|
# ./source/creator/CMakeLists.txt to write ./source/creator/buildinfo.h
|
|
|
|
|
2011-02-25 04:02:58 +00:00
|
|
|
# Extract working copy information for SOURCE_DIR into MY_XXX variables
|
|
|
|
# with a default in case anything fails, for examble when using git-svn
|
2013-11-16 18:00:02 +00:00
|
|
|
set(MY_WC_HASH "unknown")
|
|
|
|
set(MY_WC_BRANCH "unknown")
|
2013-11-15 11:11:59 +00:00
|
|
|
set(MY_WC_COMMIT_TIMESTAMP 0)
|
2013-11-04 13:21:39 +00:00
|
|
|
|
2011-02-25 04:02:58 +00:00
|
|
|
# Guess if this is a SVN working copy and then look up the revision
|
2013-11-27 20:05:06 +00:00
|
|
|
if(EXISTS ${SOURCE_DIR}/.git)
|
2013-11-27 19:41:53 +00:00
|
|
|
# The FindGit.cmake module is part of the standard distribution
|
2013-11-16 13:40:26 +00:00
|
|
|
include(FindGit)
|
|
|
|
if(GIT_FOUND)
|
2013-11-27 19:41:53 +00:00
|
|
|
message("-- Found Git: ${GIT_EXECUTABLE}")
|
|
|
|
|
2013-11-25 10:25:35 +00:00
|
|
|
execute_process(COMMAND git rev-parse --short @{u}
|
2013-11-27 20:05:06 +00:00
|
|
|
WORKING_DIRECTORY ${SOURCE_DIR}
|
2013-11-16 13:40:26 +00:00
|
|
|
OUTPUT_VARIABLE MY_WC_HASH
|
2013-11-29 12:19:42 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_QUIET)
|
2013-11-16 13:40:26 +00:00
|
|
|
|
2013-11-27 20:25:09 +00:00
|
|
|
if (MY_WC_HASH STREQUAL "")
|
|
|
|
# Local branch, not set to upstream.
|
|
|
|
# Well, let's use HEAD for now
|
|
|
|
execute_process(COMMAND git rev-parse --short HEAD
|
|
|
|
WORKING_DIRECTORY ${SOURCE_DIR}
|
|
|
|
OUTPUT_VARIABLE MY_WC_HASH
|
2013-11-29 12:19:42 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2013-11-27 20:25:09 +00:00
|
|
|
endif()
|
|
|
|
|
2013-11-16 13:40:26 +00:00
|
|
|
execute_process(COMMAND git rev-parse --abbrev-ref HEAD
|
2013-11-27 20:05:06 +00:00
|
|
|
WORKING_DIRECTORY ${SOURCE_DIR}
|
2013-11-16 13:40:26 +00:00
|
|
|
OUTPUT_VARIABLE MY_WC_BRANCH
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
execute_process(COMMAND git log -1 --format=%ct
|
2013-11-27 20:05:06 +00:00
|
|
|
WORKING_DIRECTORY ${SOURCE_DIR}
|
2013-11-16 13:40:26 +00:00
|
|
|
OUTPUT_VARIABLE MY_WC_COMMIT_TIMESTAMP
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
# Update GIT index before getting dirty files
|
|
|
|
execute_process(COMMAND git update-index -q --refresh
|
2013-11-27 20:05:06 +00:00
|
|
|
WORKING_DIRECTORY ${SOURCE_DIR}
|
2013-11-16 13:40:26 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
execute_process(COMMAND git diff-index --name-only HEAD --
|
2013-11-27 20:05:06 +00:00
|
|
|
WORKING_DIRECTORY ${SOURCE_DIR}
|
2013-11-16 13:40:26 +00:00
|
|
|
OUTPUT_VARIABLE _git_changed_files
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
|
|
|
|
|
|
if(NOT _git_changed_files STREQUAL "")
|
2013-11-19 16:01:43 +00:00
|
|
|
set(MY_WC_BRANCH "${MY_WC_BRANCH} (modified)")
|
|
|
|
else()
|
|
|
|
# Unpushed commits are also considered local odifications
|
|
|
|
execute_process(COMMAND git log @{u}..
|
2013-11-27 20:05:06 +00:00
|
|
|
WORKING_DIRECTORY ${SOURCE_DIR}
|
2013-11-19 16:01:43 +00:00
|
|
|
OUTPUT_VARIABLE _git_unpushed_log
|
2013-11-29 12:19:42 +00:00
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
ERROR_QUIET)
|
2013-11-19 16:01:43 +00:00
|
|
|
if(NOT _git_unpushed_log STREQUAL "")
|
|
|
|
set(MY_WC_BRANCH "${MY_WC_BRANCH} (modified)")
|
|
|
|
endif()
|
|
|
|
unset(_git_unpushed_log)
|
2013-11-04 13:21:39 +00:00
|
|
|
endif()
|
2013-11-16 13:40:26 +00:00
|
|
|
|
|
|
|
unset(_git_changed_files)
|
2013-11-04 13:21:39 +00:00
|
|
|
endif()
|
2011-02-24 17:57:35 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# BUILD_PLATFORM and BUILD_PLATFORM are taken from CMake
|
2011-02-25 04:02:58 +00:00
|
|
|
# but BUILD_DATE and BUILD_TIME are plataform dependant
|
2011-02-24 17:57:35 +00:00
|
|
|
if(UNIX)
|
|
|
|
execute_process(COMMAND date "+%Y-%m-%d" OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2011-02-25 00:02:08 +00:00
|
|
|
execute_process(COMMAND date "+%H:%M:%S" OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2011-02-24 17:57:35 +00:00
|
|
|
endif()
|
|
|
|
if(WIN32)
|
|
|
|
execute_process(COMMAND cmd /c date /t OUTPUT_VARIABLE BUILD_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2011-02-25 00:02:08 +00:00
|
|
|
execute_process(COMMAND cmd /c time /t OUTPUT_VARIABLE BUILD_TIME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
2011-02-24 17:57:35 +00:00
|
|
|
endif()
|
|
|
|
|
2011-02-25 04:02:58 +00:00
|
|
|
# Write a file with the SVNVERSION define
|
2011-02-24 17:57:35 +00:00
|
|
|
file(WRITE buildinfo.h.txt
|
2013-11-04 13:21:39 +00:00
|
|
|
"#define BUILD_HASH \"${MY_WC_HASH}\"\n"
|
2013-11-15 11:11:59 +00:00
|
|
|
"#define BUILD_COMMIT_TIMESTAMP ${MY_WC_COMMIT_TIMESTAMP}\n"
|
2013-11-04 13:21:39 +00:00
|
|
|
"#define BUILD_BRANCH \"${MY_WC_BRANCH}\"\n"
|
2011-08-22 12:24:14 +00:00
|
|
|
"#define BUILD_DATE \"${BUILD_DATE}\"\n"
|
|
|
|
"#define BUILD_TIME \"${BUILD_TIME}\"\n"
|
2011-02-24 17:57:35 +00:00
|
|
|
)
|
|
|
|
|
2011-02-25 04:02:58 +00:00
|
|
|
# Copy the file to the final header only if the version changes
|
|
|
|
# and avoid needless rebuilds
|
2011-02-25 06:03:01 +00:00
|
|
|
# TODO: verify this comment is true, as BUILD_TIME probably changes
|
2011-02-24 17:57:35 +00:00
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
|
|
|
buildinfo.h.txt buildinfo.h)
|