2016-08-01 05:25:37 +00:00
|
|
|
# generates BuildInfo.h
|
|
|
|
#
|
|
|
|
# this module expects
|
|
|
|
# ETH_SOURCE_DIR - main CMAKE_SOURCE_DIR
|
|
|
|
# ETH_DST_DIR - main CMAKE_BINARY_DIR
|
|
|
|
# ETH_BUILD_TYPE
|
|
|
|
# ETH_BUILD_PLATFORM
|
|
|
|
#
|
|
|
|
# example usage:
|
2016-08-23 14:04:50 +00:00
|
|
|
# cmake -DETH_SOURCE_DIR=. -DETH_DST_DIR=build -DETH_BUILD_TYPE=Debug -DETH_BUILD_PLATFORM=Darwin.appleclang -P scripts/buildinfo.cmake
|
|
|
|
#
|
|
|
|
# Its main output variables are SOL_VERSION_BUILDINFO and SOL_VERSION_PRERELEASE
|
2016-08-01 05:25:37 +00:00
|
|
|
|
|
|
|
if (NOT ETH_BUILD_TYPE)
|
|
|
|
set(ETH_BUILD_TYPE "unknown")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (NOT ETH_BUILD_PLATFORM)
|
|
|
|
set(ETH_BUILD_PLATFORM "unknown")
|
|
|
|
endif()
|
|
|
|
|
2016-08-23 14:04:50 +00:00
|
|
|
# Logic here: If prereleases.txt exists but is empty, it is a non-pre release.
|
|
|
|
# If it does not exist, create our own prerelease string
|
|
|
|
if (EXISTS ${ETH_SOURCE_DIR}/prerelease.txt)
|
|
|
|
file(READ ${ETH_SOURCE_DIR}/prerelease.txt SOL_VERSION_PRERELEASE)
|
2016-08-23 14:45:08 +00:00
|
|
|
string(STRIP ${SOL_VERSION_PRERELEASE} SOL_VERSION_PRERELEASE)
|
2016-08-23 14:04:50 +00:00
|
|
|
else()
|
|
|
|
string(TIMESTAMP SOL_VERSION_PRERELEASE "develop.%Y.%m.%d" UTC)
|
|
|
|
endif()
|
2016-08-01 05:25:37 +00:00
|
|
|
|
2016-08-23 14:04:50 +00:00
|
|
|
if (EXISTS ${ETH_SOURCE_DIR}/commit_hash.txt)
|
|
|
|
file(READ ${ETH_SOURCE_DIR}/commit_hash.txt SOL_COMMIT_HASH)
|
|
|
|
string(STRIP ${SOL_COMMIT_HASH} SOL_COMMIT_HASH)
|
|
|
|
else()
|
|
|
|
execute_process(
|
|
|
|
COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} rev-parse HEAD
|
|
|
|
OUTPUT_VARIABLE SOL_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
|
|
|
|
)
|
|
|
|
execute_process(
|
|
|
|
COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} diff HEAD --shortstat
|
|
|
|
OUTPUT_VARIABLE SOL_LOCAL_CHANGES OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET
|
|
|
|
)
|
2016-08-01 05:25:37 +00:00
|
|
|
endif()
|
|
|
|
|
2016-08-23 14:04:50 +00:00
|
|
|
if (SOL_COMMIT_HASH)
|
|
|
|
string(STRIP ${SOL_COMMIT_HASH} SOL_COMMIT_HASH)
|
|
|
|
string(SUBSTRING ${SOL_COMMIT_HASH} 0 8 SOL_COMMIT_HASH)
|
|
|
|
endif()
|
2016-08-01 05:25:37 +00:00
|
|
|
|
2016-08-23 14:04:50 +00:00
|
|
|
if (SOL_COMMIT_HASH AND SOL_LOCAL_CHANGES)
|
|
|
|
set(SOL_COMMIT_HASH "${SOL_COMMIT_HASH}-mod")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (NOT SOL_COMMIT_HASH)
|
|
|
|
message(FATAL_ERROR "Unable to determine commit hash. Either compile from within git repository or "
|
|
|
|
"supply a file called commit_hash.txt")
|
2016-08-01 05:25:37 +00:00
|
|
|
endif()
|
|
|
|
|
2016-08-23 14:04:50 +00:00
|
|
|
set(SOL_VERSION_BUILDINFO "commit.${SOL_COMMIT_HASH}.${ETH_BUILD_PLATFORM}")
|
|
|
|
|
2016-08-01 05:25:37 +00:00
|
|
|
set(TMPFILE "${ETH_DST_DIR}/BuildInfo.h.tmp")
|
|
|
|
set(OUTFILE "${ETH_DST_DIR}/BuildInfo.h")
|
|
|
|
|
|
|
|
configure_file("${ETH_BUILDINFO_IN}" "${TMPFILE}")
|
|
|
|
|
|
|
|
include("${ETH_CMAKE_DIR}/EthUtils.cmake")
|
|
|
|
replace_if_different("${TMPFILE}" "${OUTFILE}" CREATE)
|
|
|
|
|