Gav Wood
10 years ago
8 changed files with 100 additions and 58 deletions
@ -0,0 +1,7 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#define ETH_COMMIT_HASH @ETH_COMMIT_HASH@ |
||||
|
#define ETH_CLEAN_REPO @ETH_CLEAN_REPO@ |
||||
|
#define ETH_BUILD_TYPE @ETH_BUILD_TYPE@ |
||||
|
#define ETH_BUILD_PLATFORM @ETH_BUILD_PLATFORM@ |
||||
|
|
@ -1,55 +0,0 @@ |
|||||
CURRENT_SOURCE_DIR=$1 |
|
||||
CURRENT_BINARY_DIR=$2 |
|
||||
BUILD_TYPE=$3 |
|
||||
BUILD_PLATFORM=$4 |
|
||||
|
|
||||
echo "Current source dir: $CURRENT_SOURCE_DIR" |
|
||||
echo "Current binary dir: $CURRENT_BINARY_DIR" |
|
||||
echo "Build type: $BUILD_TYPE" |
|
||||
echo "Build platform: $BUILD_PLATFORM" |
|
||||
|
|
||||
if [[ -e "$CURRENT_SOURCE_DIR/BuildInfo.h" ]] |
|
||||
then |
|
||||
echo "Using existing BuildInfo.h" |
|
||||
cp $CURRENT_SOURCE_DIR/BuildInfo.h $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
else |
|
||||
if [[ -e "$CURRENT_SOURCE_DIR/.git" ]] |
|
||||
then |
|
||||
ETH_COMMIT_HASH=$(git --git-dir=$CURRENT_SOURCE_DIR/.git --work-tree=$CURRENT_SOURCE_DIR rev-parse HEAD) |
|
||||
ETH_LOCAL_CHANGES=$(git --git-dir=$CURRENT_SOURCE_DIR/.git --work-tree=$CURRENT_SOURCE_DIR diff --shortstat) |
|
||||
if [[ -z "$ETH_LOCAL_CHANGES" ]] |
|
||||
then |
|
||||
ETH_CLEAN_REPO=1 |
|
||||
else |
|
||||
ETH_CLEAN_REPO=0 |
|
||||
fi |
|
||||
|
|
||||
echo "Commit hash: ${ETH_COMMIT_HASH} (Clean: ${ETH_CLEAN_REPO} - ${ETH_LOCAL_CHANGES})" |
|
||||
else |
|
||||
echo "Unknown repo." |
|
||||
ETH_COMMIT_HASH=0 |
|
||||
ETH_CLEAN_REPO=1 |
|
||||
fi |
|
||||
|
|
||||
echo "// This file was automatically generated by cmake" > $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
echo "" >> $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
echo "#pragma once" >> $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
echo "" >> $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
echo "#define ETH_COMMIT_HASH $ETH_COMMIT_HASH" >> $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
echo "#define ETH_CLEAN_REPO $ETH_CLEAN_REPO" >> $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
echo "#define ETH_BUILD_TYPE $BUILD_TYPE" >> $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
echo "#define ETH_BUILD_PLATFORM $BUILD_PLATFORM" >> $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
fi |
|
||||
|
|
||||
if [[ -e "$CURRENT_BINARY_DIR/BuildInfo.h" ]] |
|
||||
then |
|
||||
DIFF=$(diff $CURRENT_BINARY_DIR/BuildInfo.h $CURRENT_BINARY_DIR/BuildInfo.h.tmp) |
|
||||
if [[ -z "$DIFF" ]] |
|
||||
then |
|
||||
rm $CURRENT_BINARY_DIR/BuildInfo.h.tmp |
|
||||
else |
|
||||
mv $CURRENT_BINARY_DIR/BuildInfo.h.tmp $CURRENT_BINARY_DIR/BuildInfo.h |
|
||||
fi |
|
||||
else |
|
||||
mv $CURRENT_BINARY_DIR/BuildInfo.h.tmp $CURRENT_BINARY_DIR/BuildInfo.h |
|
||||
fi |
|
@ -0,0 +1,61 @@ |
|||||
|
# 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: |
||||
|
# cmake -DETH_SOURCE_DIR=. -DETH_DST_DIR=build -DETH_BUILD_TYPE=Debug -DETH_BUILD_PLATFORM=mac -P scripts/buildinfo.cmake |
||||
|
|
||||
|
if (NOT ETH_BUILD_TYPE) |
||||
|
set(ETH_BUILD_TYPE "unknown") |
||||
|
endif() |
||||
|
|
||||
|
if (NOT ETH_BUILD_PLATFORM) |
||||
|
set(ETH_BUILD_PLATFORM "unknown") |
||||
|
endif() |
||||
|
|
||||
|
execute_process( |
||||
|
COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} rev-parse HEAD |
||||
|
OUTPUT_VARIABLE ETH_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE |
||||
|
) |
||||
|
|
||||
|
if (NOT ETH_COMMIT_HASH) |
||||
|
set(ETH_COMMIT_HASH 0) |
||||
|
endif() |
||||
|
|
||||
|
execute_process( |
||||
|
COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} diff --shortstat |
||||
|
OUTPUT_VARIABLE ETH_LOCAL_CHANGES OUTPUT_STRIP_TRAILING_WHITESPACE |
||||
|
) |
||||
|
|
||||
|
if (ETH_LOCAL_CHANGES) |
||||
|
set(ETH_CLEAN_REPO 0) |
||||
|
else() |
||||
|
set(ETH_CLEAN_REPO 1) |
||||
|
endif() |
||||
|
|
||||
|
set(INFILE "${ETH_SOURCE_DIR}/BuildInfo.h.in") |
||||
|
set(TMPFILE "${ETH_DST_DIR}/BuildInfo.h.tmp") |
||||
|
set(OUTFILE "${ETH_DST_DIR}/BuildInfo.h") |
||||
|
|
||||
|
# create outfile if it doesn't exist |
||||
|
if (NOT (EXISTS "${OUTFILE}")) |
||||
|
execute_process(COMMAND touch "${OUTFILE}") |
||||
|
endif() |
||||
|
|
||||
|
configure_file("${INFILE}" "${TMPFILE}") |
||||
|
|
||||
|
execute_process( |
||||
|
COMMAND diff "${OUTFILE}" "${TMPFILE}" |
||||
|
OUTPUT_VARIABLE ETH_FILE_OUTDATED |
||||
|
) |
||||
|
|
||||
|
if (ETH_FILE_OUTDATED) |
||||
|
execute_process(COMMAND mv "${TMPFILE}" "${OUTFILE}") |
||||
|
else() |
||||
|
execute_process(COMMAND rm "${TMPFILE}") |
||||
|
endif() |
||||
|
|
@ -0,0 +1,14 @@ |
|||||
|
# adds possibility to run configure_file as buildstep |
||||
|
# reference: |
||||
|
# http://www.cmake.org/pipermail/cmake/2012-May/050227.html |
||||
|
# |
||||
|
# This module expects |
||||
|
# INFILE |
||||
|
# OUTFILE |
||||
|
# other custom vars |
||||
|
# |
||||
|
# example usage: |
||||
|
# cmake -DINFILE=blah.in -DOUTFILE=blah.out -Dvar1=value1 -Dvar2=value2 -P scripts/configure.cmake |
||||
|
|
||||
|
configure_file(${INFILE} ${OUTFILE}) |
||||
|
|
Loading…
Reference in new issue