From e3f0a91e9c6c171b4460f4ff0eab02013cb88b30 Mon Sep 17 00:00:00 2001 From: Tim Hughes Date: Fri, 21 Feb 2014 17:31:46 +0000 Subject: [PATCH] Upgraded build script supporting automatic fetch/compile of Qt. Alethzero now compiles with static linking under VS 2013. --- alethzero/MainWin.cpp | 23 +++- windows/Alethzero.vcxproj | 45 ++++---- windows/Alethzero.vcxproj.filters | 3 +- windows/CopyBinary.props | 18 +++ windows/Ethereum.vcxproj | 2 + windows/LibEthereum.props | 18 ++- windows/UseQt.props | 38 +++++++ windows/bootstrap.sh | 180 ++++++++++++++++++++++++------ windows/compile_ethereum.bat | 14 +++ windows/compile_qt.bat | 41 +++++++ windows/qt_plugin_import.cpp | 2 +- 11 files changed, 314 insertions(+), 70 deletions(-) create mode 100644 windows/CopyBinary.props create mode 100644 windows/UseQt.props create mode 100644 windows/compile_ethereum.bat create mode 100644 windows/compile_qt.bat diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 7f3406894..1251b76f3 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -655,8 +655,29 @@ void Main::on_create_triggered() m_keysChanged = true; } -// include moc file on VS, ofuscated to hide from automoc +// extra bits needed to link on VS #ifdef _MSC_VER + +// include moc file, ofuscated to hide from automoc #include\ "moc_MainWin.cpp" + +// specify library dependencies, it's easier to do here than in the project since we can control the "d" debug suffix +#ifdef _DEBUG +#define QTLIB(x) x"d.lib" +#else +#define QTLIB(x) x".lib" +#endif + +#pragma comment(lib, QTLIB("Qt5PlatformSupport")) +#pragma comment(lib, QTLIB("Qt5Core")) +#pragma comment(lib, QTLIB("Qt5GUI")) +#pragma comment(lib, QTLIB("Qt5Widgets")) +#pragma comment(lib, QTLIB("Qt5Network")) +#pragma comment(lib, QTLIB("qwindows")) +#pragma comment(lib, "Imm32.lib") +#pragma comment(lib, "opengl32.lib") +#pragma comment(lib, "winmm.lib") + + #endif diff --git a/windows/Alethzero.vcxproj b/windows/Alethzero.vcxproj index aab2ef67b..7d2983949 100644 --- a/windows/Alethzero.vcxproj +++ b/windows/Alethzero.vcxproj @@ -53,18 +53,24 @@ + + + + + + @@ -84,15 +90,12 @@ WIN32;_DEBUG;%(PreprocessorDefinitions) MultiThreadedDebug true - $(IntDir);..;$(QT_PATH)/$(Platform)/include;%(AdditionalIncludeDirectories) stdafx.h Windows true true - $(QT_PATH)/$(Platform)/lib;%(AdditionalLibraryDirectories) - Qt5Cored.lib;Qt5GUId.lib;Qt5Widgetsd.lib;Qt5Networkd.lib;%(AdditionalDependencies) @@ -102,14 +105,11 @@ WIN32;_DEBUG;%(PreprocessorDefinitions) MultiThreadedDebug true - $(IntDir);..;$(QT_PATH)/$(Platform)/include;%(AdditionalIncludeDirectories) stdafx.h Windows true - $(QT_PATH)/$(Platform)/lib;%(AdditionalLibraryDirectories) - Qt5Cored.lib;Qt5GUId.lib;Qt5Widgetsd.lib;Qt5Networkd.lib;%(AdditionalDependencies) @@ -122,7 +122,6 @@ MultiThreaded true AnySuitable - $(IntDir);..;$(QT_PATH)/$(Platform)/include;%(AdditionalIncludeDirectories) stdafx.h @@ -131,8 +130,6 @@ true true true - $(QT_PATH)/$(Platform)/lib;%(AdditionalLibraryDirectories) - Qt5Core.lib;Qt5GUI.lib;Qt5Widgets.lib;Qt5Network.lib;%(AdditionalDependencies) @@ -145,7 +142,6 @@ MultiThreaded true AnySuitable - $(IntDir);..;$(QT_PATH)/$(Platform)/include;%(AdditionalIncludeDirectories) stdafx.h @@ -153,8 +149,6 @@ true true true - $(QT_PATH)/$(Platform)/lib;%(AdditionalLibraryDirectories) - Qt5Core.lib;Qt5GUI.lib;Qt5Widgets.lib;Qt5Network.lib;%(AdditionalDependencies) @@ -165,27 +159,28 @@ - + Create Create Create Create + - ..\..\bin\lua52 moc.lua "$(QT_PATH)/$(Platform)/bin/moc" "$(IntDir)moc_%(FileName).cpp" "@(ClCompile->'%(AdditionalIncludeDirectories)');$(IncludePath)" "@(ClCompile->'%(PreprocessorDefinitions)');_MSC_VER=1800" "%(FullPath)" + "$(Lua)" moc.lua "$(QtBin)/moc" "$(IntDir)moc_%(FileName).cpp" "@(ClCompile->'%(AdditionalIncludeDirectories)');$(IncludePath)" "@(ClCompile->'%(PreprocessorDefinitions)');_MSC_VER=1800" "%(FullPath)" $(IntDir)moc_%(FileName).cpp - ..\..\bin\lua52 moc.lua "$(QT_PATH)/$(Platform)/bin/moc" "$(IntDir)moc_%(FileName).cpp" "@(ClCompile->'%(AdditionalIncludeDirectories)');$(IncludePath)" "@(ClCompile->'%(PreprocessorDefinitions)');_MSC_VER=1800" "%(FullPath)" + "$(Lua)" moc.lua "$(QtBin)/moc" "$(IntDir)moc_%(FileName).cpp" "@(ClCompile->'%(AdditionalIncludeDirectories)');$(IncludePath)" "@(ClCompile->'%(PreprocessorDefinitions)');_MSC_VER=1800" "%(FullPath)" - ..\..\bin\lua52 moc.lua "$(QT_PATH)/$(Platform)/bin/moc" "$(IntDir)moc_%(FileName).cpp" "@(ClCompile->'%(AdditionalIncludeDirectories)');$(IncludePath)" "@(ClCompile->'%(PreprocessorDefinitions)');_MSC_VER=1800" "%(FullPath)" + "$(Lua)" moc.lua "$(QtBin)/moc" "$(IntDir)moc_%(FileName).cpp" "@(ClCompile->'%(AdditionalIncludeDirectories)');$(IncludePath)" "@(ClCompile->'%(PreprocessorDefinitions)');_MSC_VER=1800" "%(FullPath)" - ..\..\bin\lua52 moc.lua "$(QT_PATH)/$(Platform)/bin/moc" "$(IntDir)moc_%(FileName).cpp" "@(ClCompile->'%(AdditionalIncludeDirectories)');$(IncludePath)" "@(ClCompile->'%(PreprocessorDefinitions)');_MSC_VER=1800" "%(FullPath)" + "$(Lua)" moc.lua "$(QtBin)/moc" "$(IntDir)moc_%(FileName).cpp" "@(ClCompile->'%(AdditionalIncludeDirectories)');$(IncludePath)" "@(ClCompile->'%(PreprocessorDefinitions)');_MSC_VER=1800" "%(FullPath)" $(IntDir)moc_%(FileName).cpp @@ -197,17 +192,17 @@ Document - "$(QT_PATH)/$(Platform)/bin/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" - "$(QT_PATH)/$(Platform)/bin/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" + "$(QtBin)/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" + "$(QtBin)/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" $(IntDir)ui_%(FileName).h - "$(QT_PATH)/$(Platform)/bin/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" - "$(QT_PATH)/$(Platform)/bin/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" + "$(QtBin)/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" + "$(QtBin)/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" $(IntDir)ui_%(FileName).h - "$(QT_PATH)/$(Platform)/bin/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" - "$(QT_PATH)/$(Platform)/bin/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" + "$(QtBin)/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" + "$(QtBin)/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" $(IntDir)ui_%(FileName).h - "$(QT_PATH)/$(Platform)/bin/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" - "$(QT_PATH)/$(Platform)/bin/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" + "$(QtBin)/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" + "$(QtBin)/uic" -o "$(IntDir)ui_%(FileName).h" "%(FullPath)" $(IntDir)ui_%(FileName).h diff --git a/windows/Alethzero.vcxproj.filters b/windows/Alethzero.vcxproj.filters index 5ecab5b85..ecf9afee0 100644 --- a/windows/Alethzero.vcxproj.filters +++ b/windows/Alethzero.vcxproj.filters @@ -6,9 +6,10 @@ Windows - + Windows + diff --git a/windows/CopyBinary.props b/windows/CopyBinary.props new file mode 100644 index 000000000..3f94f615a --- /dev/null +++ b/windows/CopyBinary.props @@ -0,0 +1,18 @@ + + + + + + + + xcopy /F /Y $(OutDir)$(TargetName)$(TargetExt) ..\..\_binaries\$(Platform)\ + + + + + + + + + + \ No newline at end of file diff --git a/windows/Ethereum.vcxproj b/windows/Ethereum.vcxproj index dd10aadd2..023424879 100644 --- a/windows/Ethereum.vcxproj +++ b/windows/Ethereum.vcxproj @@ -61,10 +61,12 @@ + + diff --git a/windows/LibEthereum.props b/windows/LibEthereum.props index 21b046821..87dd41533 100644 --- a/windows/LibEthereum.props +++ b/windows/LibEthereum.props @@ -1,10 +1,12 @@  - + + ../../boost + - ..\..\build\$(ProjectName)\$(Platform)_$(Configuration)\ - ..\..\build\$(ProjectName)\$(Platform)_$(Configuration)\ + ..\..\_build\$(ProjectName)\$(Platform)_$(Configuration)\ + ..\..\_build\$(ProjectName)\$(Platform)_$(Configuration)\ @@ -12,14 +14,18 @@ Level4 true false - include/$(ProjectName);../libethereum;../../boost;../../leveldb/include;../../cryptopp;../secp256k1;../../miniupnp + include/$(ProjectName);../libethereum;$(BoostDir);../../leveldb/include;../../cryptopp;../secp256k1;../../miniupnp ETH_VERSION=0.3.3;ETH_BUILD_PLATFORM=Windows/VS2013;ETH_BUILD_TYPE=$(Configuration)-$(Platform);STATICLIB;LEVELDB_PLATFORM_WINDOWS;USE_NUM_BOOST;USE_FIELD_10X26;USE_FIELD_INV_BUILTIN;_WIN32_WINNT=0x0501;WIN32;%(PreprocessorDefinitions) true true - ../../boost/stage/$(Platform) + $(BoostDir)/stage/$(Platform) - + + + $(BoostDir) + + \ No newline at end of file diff --git a/windows/UseQt.props b/windows/UseQt.props new file mode 100644 index 000000000..9ced7563f --- /dev/null +++ b/windows/UseQt.props @@ -0,0 +1,38 @@ + + + + + ../../Qt/$(Platform) + $(QtDir)/qtbase/bin + $(QtDir)/qtbase/include;../../Qt/Src/qtbase/include + $(QtDir)/qtbase/lib;$(QtDir)/qtbase/plugins/platforms + ../../lua/lua + + + + + + ..;$(IntDir);$(QtInclude);%(AdditionalIncludeDirectories) + + + $(QtLib);%(AdditionalLibraryDirectories) + + + + + $(QtDir) + + + $(QtBin) + + + $(QtInclude) + + + $(QtLib) + + + $(Lua) + + + \ No newline at end of file diff --git a/windows/bootstrap.sh b/windows/bootstrap.sh index 397b4ce12..12935a91f 100644 --- a/windows/bootstrap.sh +++ b/windows/bootstrap.sh @@ -1,39 +1,147 @@ #!/bin/bash - -# Setup script for building Ethereum using Visual Studio Express 2013. -# Execute once in directory only containing cpp-ethereum +# @file bootstrap.sh +# @author Tim Hughes +# @date 2014 +# Script to fetch and compile depdencies for building Ethereum using Visual Studio Express 2013. # Prerequisites: # - Visual Studio Express 2013 for Desktop -# - On PATH: git, git-svn, wget, 7z - -# stop on errors -set -e - -# fetch CryptoPP-5.6.2 -git svn clone -r 541:541 svn://svn.code.sf.net/p/cryptopp/code/trunk/c5 cryptopp - -# fetch MiniUPnP-1.8 -git clone git@github.com:miniupnp/miniupnp.git -cd miniupnp -git checkout tags/miniupnpd_1_8 -cd .. - -# fetch LevelDB (windows branch) -git clone https://code.google.com/p/leveldb/ -cd leveldb -git checkout origin/windows -cd .. - -# fetch and unpack boost-1.55 -wget -O boost_1_55_0.7z http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.7z/download -7z x boost_1_55_0.7z -mv boost_1_55_0 boost - -# compile boost for x86 and x64 -cd boost -cmd /c bootstrap.bat -./b2 --build-type=complete link=static runtime-link=static variant=debug,release threading=multi stage -mv stage/lib stage/Win32 -./b2 --build-type=complete link=static runtime-link=static variant=debug,release threading=multi address-model=64 stage -mv stage/lib stage/x64 -cd .. +# - On PATH: bash, git, git-svn, curl, sed, 7z + +if [[ ! $@ ]] || [ $1 == "fetch" ]; then + # fetch ethereum (develop branch) + if [ ! -d cpp-ethereum ]; then + (set -x; git clone https://github.com/ethereum/cpp-ethereum.git) + cd cpp-ethereum + (set -x; git checkout origin/develop) + cd .. + echo + fi + + # fetch CryptoPP-5.6.2 + if [ ! -d cryptopp ]; then + (set -x; git svn clone -r 541:541 http://svn.code.sf.net/p/cryptopp/code/trunk/c5 cryptopp) + echo + fi + + # fetch MiniUPnP-1.8 + if [ ! -d miniupnp ]; then + (set -x; git clone https://github.com/miniupnp/miniupnp.git) + cd miniupnp + (set -x; git checkout tags/miniupnpd_1_8) + cd .. + echo + fi + + # fetch LevelDB (windows branch) + if [ ! -d leveldb ]; then + (set -x; git clone https://code.google.com/p/leveldb/) + cd leveldb + (set -x; git checkout origin/windows) + cd .. + echo + fi + + # fetch and unpack boost-1.55 source + if [ ! -d boost ]; then + if [ ! -f _download/boost_1_55_0.7z ]; then + (set -x; mkdir -p _download) + (set -x; curl -o _download/boost_1_55_0.7z -L http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.7z/download) + fi + (set -x; 7z x _download/boost_1_55_0.7z) + (set -x; mv boost_1_55_0 boost) + echo + fi + + # fetch and unpack Qt 5.1.2 source + if [ ! -d Qt ]; then + if [ ! -f _download/qt-everywhere-opensource-src-5.2.1.zip ]; then + (set -x; mkdir -p _download) + (set -x; curl -o _download/qt-everywhere-opensource-src-5.2.1.zip -L http://download.qt-project.org/official_releases/qt/5.2/5.2.1/single/qt-everywhere-opensource-src-5.2.1.zip) + fi + (set -x; mkdir Qt) + cd Qt + (set -x; 7z x ../_download/qt-everywhere-opensource-src-5.2.1.zip) + (set -x; mv qt-everywhere-opensource-src-5.2.1 Src) + # patch qmake.conf to use the static CRT + (set -x; sed -i -e 's/-MD/-MT/g' Src/qtbase/mkspecs/win32-msvc2013/qmake.conf) + cd .. + echo + fi + + # fetch jom + if [ ! -f "Qt/jom/jom.exe" ]; then + if [ ! -f "_download/jom.zip" ]; then + (set -x; mkdir -p _download) + (set -x; curl -o "_download/jom.zip" -L http://download.qt-project.org/official_releases/jom/jom.zip) + fi + (set -x; mkdir -p Qt/jom) + cd Qt/jom + (set -x; 7z x ../../_download/jom.zip) + cd ../.. + echo + fi + + # fetch and unpack Lua binaries + if [ ! -d lua ]; then + if [ ! -f _download/lua-5.2.1_Win32_bin.zip ]; then + (set -x; mkdir -p _download) + (set -x; curl -o _download/lua-5.2.1_Win32_bin.zip -L http://sourceforge.net/projects/luabinaries/files/5.2.1/Executables/lua-5.2.1_Win32_bin.zip/download) + fi + (set -x; mkdir lua) + cd lua + (set -x; 7z x ../_download/lua-5.2.1_Win32_bin.zip lua52.exe lua52.dll) + (set -x; mv lua52.exe lua.exe) + cd .. + echo + fi +fi + +compile_boost() +{ + if [ $platform == "x64" ]; then + addressModel="address-model=64" + else + addressModel="" + fi + + if [ ! -d "stage/$platform" ]; then + targets="--with-filesystem --with-system --with-thread --with-date_time --with-regex" + (set -x; ./b2 -j4 --build-type=complete link=static runtime-link=static variant=debug,release threading=multi $addressModel $targets stage) + (set -x; mv stage/lib stage/$platform) + fi +} + +if [[ ! $@ ]] || [ $1 == "compile-boost" ]; then + # bootstrap if b2 is missing + cd boost + if [ ! -f "b2.exe" ]; then + (set -x; cmd.exe /c bootstrap.bat) + fi + + # compile boost for x86 and x64 + platform="x64"; compile_boost + platform="Win32"; compile_boost + cd .. + echo +fi + +compile_qt() +{ + if [ ! -d $platform ]; then + (set -x; cmd.exe /c "..\\cpp-ethereum\\windows\\compile_qt.bat $platform") + fi +} + +if [[ ! $@ ]] || [ $1 == "compile-qt" ]; then + # compile Qt for x86 and x64 + cd Qt + platform="x64"; compile_qt + platform="Win32"; compile_qt + cd .. + echo +fi + +# finally run MS build +cd cpp-ethereum/windows +cmd.exe /c "compile_ethereum.bat" +cd .. \ No newline at end of file diff --git a/windows/compile_ethereum.bat b/windows/compile_ethereum.bat new file mode 100644 index 000000000..ee51f0a89 --- /dev/null +++ b/windows/compile_ethereum.bat @@ -0,0 +1,14 @@ +@echo off +rem @file compileqt.bat +rem @author Tim Hughes +rem @date 2014 +echo on + +rem : import VC environment +call "%VS120COMNTOOLS%\VsDevCmd.bat" + +rem : build for x64 +msbuild /maxcpucount /p:Configuration=Release;Platform=x64 Ethereum.sln + +rem : build for Win32 +msbuild /maxcpucount /p:Configuration=Release;Platform=Win32 Ethereum.sln diff --git a/windows/compile_qt.bat b/windows/compile_qt.bat new file mode 100644 index 000000000..c9f0d4ef5 --- /dev/null +++ b/windows/compile_qt.bat @@ -0,0 +1,41 @@ +@echo off +rem @file compileqt.bat +rem @author Tim Hughes +rem @date 2014 + +rem : enable use prefix if we want to produce standalone Qt binaries +rem : off by default since this takes longer and duplicates all the headers +set USE_PREFIX=0 + +rem : echo commands so we can see what's going on +echo on + +rem : select platform and toolset from first argument +IF %1%==x64 (set PLATFORM=x64&set TOOLSET=x86_amd64) ELSE (set PLATFORM=Win32&set TOOLSET=x86) + +rem : import VC environment vars +call "%VS120COMNTOOLS%\..\..\VC\vcvarsall.bat" %TOOLSET% + +rem : assume our root Qt dir is the current dir +set QT=%CD% + +rem : create the build folder and add the qtbase/bin folder to the PATH +if not exist %QT%\%PLATFORM% mkdir %QT%\%PLATFORM% +if %USE_PREFIX%==1 ( + if not exist %QT%\%PLATFORM%-Build mkdir %QT%\%PLATFORM%-Build + if not exist %QT%\%PLATFORM%\qtbase mkdir %QT%\%PLATFORM%\qtbase + cd %QT%\%PLATFORM%-Build + set QT_PREFIX=-prefix %Qt%\%PLATFORM%\qtbase + set QT_TARGETS=module-qtbase-install_subtargets +) else ( + cd %QT%\%PLATFORM% + set QT_PREFIX= + set QT_TARGETS=module-qtbase +) +set PATH=%CD%\qtbase\bin;%PATH% + +rem : run Qt configure with desired settings +call %QT%\Src\configure.bat -opensource -confirm-license %QT_PREFIX% -mp -opengl desktop -static -debug-and-release -platform win32-msvc2013 -nomake examples -nomake tests + +rem : compile and install module-qtbase +%QT%\jom\jom %QT_TARGETS% diff --git a/windows/qt_plugin_import.cpp b/windows/qt_plugin_import.cpp index 39acb25c9..b3afd8a4e 100644 --- a/windows/qt_plugin_import.cpp +++ b/windows/qt_plugin_import.cpp @@ -1,4 +1,4 @@ // This file is autogenerated by qmake. It imports static plugin classes for // static plugins specified using QTPLUGIN and QT_PLUGIN_CLASS. variables. -#include +#include Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin)