2016-08-01 05:25:37 +00:00
|
|
|
# generates BuildInfo.h
|
2018-09-03 13:01:15 +00:00
|
|
|
#
|
2016-08-01 05:25:37 +00:00
|
|
|
# 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()
|
|
|
|
|
2018-05-22 15:28:17 +00:00
|
|
|
# Logic here: If prerelease.txt exists but is empty, it is a non-pre release.
|
2016-08-23 14:04:50 +00:00
|
|
|
# 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-09-08 12:36:31 +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)
|
2016-09-09 15:43:36 +00:00
|
|
|
string(REPLACE .0 . SOL_VERSION_PRERELEASE "${SOL_VERSION_PRERELEASE}")
|
2016-08-23 14:04:50 +00:00
|
|
|
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(
|
2016-09-14 23:47:16 +00:00
|
|
|
COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} rev-parse --short=8 HEAD
|
2016-08-23 14:04:50 +00:00
|
|
|
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 (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-09-15 15:34:12 +00:00
|
|
|
if (NOT SOL_COMMIT_HASH MATCHES [a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9])
|
2016-09-14 23:47:16 +00:00
|
|
|
message(FATAL_ERROR "Malformed commit hash \"${SOL_COMMIT_HASH}\". It has to consist of exactly 8 hex digits.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if (SOL_COMMIT_HASH AND SOL_LOCAL_CHANGES)
|
|
|
|
set(SOL_COMMIT_HASH "${SOL_COMMIT_HASH}.mod")
|
|
|
|
endif()
|
2016-08-01 05:25:37 +00:00
|
|
|
|
2017-01-17 12:35:13 +00:00
|
|
|
set(SOL_VERSION_COMMIT "commit.${SOL_COMMIT_HASH}")
|
|
|
|
set(SOl_VERSION_PLATFORM ETH_BUILD_PLATFORM)
|
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)
|
|
|
|
|