From 604aef47cbd1a67d917ba8d4d352cd38eb290dfe Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 10 Feb 2015 14:31:27 +0100 Subject: [PATCH] BuildInfo.sh replaced with custom cmake script --- BuildInfo.h.in | 7 +++++ BuildInfo.sh | 55 ----------------------------------- CMakeLists.txt | 7 ++++- cmake/EthDependencies.cmake | 8 +++++ cmake/scripts/buildinfo.cmake | 33 +++++++++++++++++++++ cmake/scripts/configure.cmake | 14 +++++++++ 6 files changed, 68 insertions(+), 56 deletions(-) create mode 100644 BuildInfo.h.in delete mode 100644 BuildInfo.sh create mode 100644 cmake/scripts/buildinfo.cmake create mode 100644 cmake/scripts/configure.cmake diff --git a/BuildInfo.h.in b/BuildInfo.h.in new file mode 100644 index 000000000..7d2bfc1c8 --- /dev/null +++ b/BuildInfo.h.in @@ -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@ + diff --git a/BuildInfo.sh b/BuildInfo.sh deleted file mode 100644 index 0370297df..000000000 --- a/BuildInfo.sh +++ /dev/null @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index a3adde425..e6b49bf72 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,12 @@ function(createBuildInfo) endif() # Generate header file containing useful build information - add_custom_target(BuildInfo.h ALL COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/BuildInfo.sh ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${_cmake_build_type} ${ETH_BUILD_PLATFORM}) + add_custom_target(BuildInfo.h ALL + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMAND cmake -DETH_SOURCE_DIR=${CMAKE_SOURCE_DIR} -DETH_DST_DIR=${CMAKE_BINARY_DIR} + -DETH_BUILD_TYPE=${_cmake_build_type} -DETH_BUILD_PLATFORM=${ETH_BUILD_PLATFORM} + -P ${ETH_SCRIPTS_DIR}/buildinfo.cmake + ) include_directories(${CMAKE_CURRENT_BINARY_DIR}) set(CMAKE_INCLUDE_CURRENT_DIR ON) diff --git a/cmake/EthDependencies.cmake b/cmake/EthDependencies.cmake index 8ff3d1460..00f99e7e3 100644 --- a/cmake/EthDependencies.cmake +++ b/cmake/EthDependencies.cmake @@ -7,6 +7,14 @@ string(TOLOWER ${CMAKE_SYSTEM_NAME} _system_name) set (ETH_DEPENDENCY_INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extdep/install/${_system_name}") set (CMAKE_PREFIX_PATH ${ETH_DEPENDENCY_INSTALL_DIR}) +# setup directory for cmake generated files and include it globally +# it's not used yet, but if we have more generated files, consider moving them to ETH_GENERATED_DIR +set(ETH_GENERATED_DIR "${PROJECT_BINARY_DIR}/gen") +include_directories(${ETH_GENERATED_DIR}) + +# custom cmake scripts +set(ETH_SCRIPTS_DIR ${CMAKE_SOURCE_DIR}/cmake/scripts) + # Qt5 requires opengl # TODO use proper version of windows SDK (32 vs 64) # TODO make it possible to use older versions of windows SDK (7.0+ should also work) diff --git a/cmake/scripts/buildinfo.cmake b/cmake/scripts/buildinfo.cmake new file mode 100644 index 000000000..870cbf4e1 --- /dev/null +++ b/cmake/scripts/buildinfo.cmake @@ -0,0 +1,33 @@ +# 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 + +execute_process( + COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} rev-parse HEAD + OUTPUT_VARIABLE ETH_COMMIT_HASH +) + +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 +) + +if (ETH_LOCAL_CHANGES) + set(ETH_CLEAN_REPO 0) +else() + set(ETH_CLEAN_REPO 1) +endif() + +configure_file("${ETH_SOURCE_DIR}/BuildInfo.h.in" "${ETH_DST_DIR}/BuildInfo.h") + diff --git a/cmake/scripts/configure.cmake b/cmake/scripts/configure.cmake new file mode 100644 index 000000000..76fb7b757 --- /dev/null +++ b/cmake/scripts/configure.cmake @@ -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}) +