From 8bec43d01e7cf5d092f893d5433c465105fbccfc Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 26 Dec 2018 15:17:00 +0100 Subject: [PATCH 1/9] Add new build scripts for windows The old build scripts used hard coded directory paths, didn't check if the paths actually existed and didn't differentiate between compiling, deploying libraries and packaging for release. The new build scripts are split into three different files. They are all longer than the old build scripts, but most of the extra lines are error checking, which the old one lacked. It was considered writing the build scripts in another language like Python or Powershell, but the relatively small size of the project and unlikelihood of the build systems needing to grow massively means that a very simple imperative language like the Microsoft scripting language is fine. --- build_scripts/win/build_windows.cmd | 105 +++++++++++++++++++++++ build_scripts/win/deploy_windows.cmd | 119 ++++++++++++++++++++++++++ build_scripts/win/package_windows.cmd | 70 +++++++++++++++ 3 files changed, 294 insertions(+) create mode 100644 build_scripts/win/build_windows.cmd create mode 100644 build_scripts/win/deploy_windows.cmd create mode 100644 build_scripts/win/package_windows.cmd diff --git a/build_scripts/win/build_windows.cmd b/build_scripts/win/build_windows.cmd new file mode 100644 index 0000000..46a9d72 --- /dev/null +++ b/build_scripts/win/build_windows.cmd @@ -0,0 +1,105 @@ +@echo off +REM Echo off to avoid spam. + +REM Non zero is failure, 0 is success. +SET exit_code_success=0 +SET exit_code_failure_build_apps=1 +SET exit_code_failure_build_locations=2 + +REM Used for echos. +SET current_activity=BUILD + +REM If scripts are chain called the original dirs should not be overwritten. +IF NOT DEFINED original_dir ( + SET original_dir=%CD% +) +IF NOT DEFINED project_dir ( + REM Arg 0 (called %0) is the full path to the file. + REM https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call#batch-parameters + REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. + SET folder_path=%~dp0 + REM Project dir is up two dirs from the file. + SET project_dir=%folder_path%\..\..\ +) + +REM Change dir to the project dir, otherwise qmake doesn't know where it is. +CD %project_dir% + +ECHO %current_activity%: Testing if all required build environment values are set: +IF NOT DEFINED QT_LOC ( + ECHO %current_activity%: QT_LOC not defined. Using default value. + SET QT_LOC="C:\Qt\5.11.1\msvc2017_64\bin\" +) +ECHO %current_activity%: QT_LOC set to '%QT_LOC%'. +IF EXIST %QT_LOC% ( + ECHO %current_activity%: QT_LOC exists. +) ELSE ( + ECHO %current_activity%: QT_LOC directory does not exist. Exiting. + EXIT /B %exit_code_failure_build_locations% +) + +IF NOT DEFINED VS_LOC ( + ECHO %current_activity%: VS_LOC not defined. Using default value. + SET VS_LOC="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" +) +ECHO %current_activity%: VS_LOC set to '%VS_LOC%'. +IF EXIST %VS_LOC% ( + ECHO %current_activity%: VS_LOC exists. +) ELSE ( + ECHO %current_activity%: VS_LOC directory does not exist. Exiting. + EXIT /B %exit_code_failure_build_locations% +) + +ECHO %current_activity%: All required build environment values are set. + +IF DEFINED BUILD_DEBUG ( + ECHO %current_activity%: BUILD_DEBUG var set. Compiling for debug. + SET compile_level=debug +) ELSE ( + ECHO %current_activity%: BUILD_DEBUG var not set. Compiling for release. + SET compile_level=release +) + +ECHO %current_activity%: Setting up environment with Visual Studio 'vcvarsall.bat'. +REM Currently only this platform is supported. +SET target_platform=AMD64 +REM Set up environment for qmake. +CALL %VS_LOC% %target_platform% + +IF DEFINED BUILD_VSPROJ ( + ECHO %current_activity%: BUILD_VSPROJ defined. Building Visual Studio project files. + %QT_LOC%\qmake -tp vc + ECHO %current_activity%: Building Visual Studio project files done. +) ELSE ( + ECHO %current_activity%: BUILD_VSPROJ not defined. Not building Visual Studio project files. +) + +ECHO %current_activity%: Running qmake for %compile_level%: +%QT_LOC%\qmake -spec win32-msvc CONFIG+=x86_64 CONFIG+=%compile_level% +ECHO %current_activity%: qmake done. + +IF NOT DEFINED JOM_LOC ( + ECHO %current_activity%: JOM_LOC not defined. Using default value. + SET JOM_LOC="C:\Qt\Tools\QtCreator\bin\jom.exe" +) +ECHO %current_activity%: JOM_LOC set to '%JOM_LOC%'. + +IF EXIST %JOM_LOC% ( + ECHO %current_activity%: JOM_LOC exists. + ECHO %current_activity%: Running jom: + %JOM_LOC% + REM jom will not exit with an error code. Leading to a passing build even with errors. + IF ERRORLEVEL 1 EXIT /B %exit_code_failure_build_apps% + ECHO %current_activity%: jom done. +) ELSE ( + ECHO JOM_LOC directory does not exist. Using nmake. + ECHO %current_activity%: Running nmake: + nmake + REM nmake will not exit with an error code. Leading to a passing build even with errors. + IF ERRORLEVEL 1 EXIT /B %exit_code_failure_build_apps% + ECHO %current_activity%: nmake done. +) + +CD %original_dir% + +ECHO %current_activity%: %current_activity% DONE. \ No newline at end of file diff --git a/build_scripts/win/deploy_windows.cmd b/build_scripts/win/deploy_windows.cmd new file mode 100644 index 0000000..3a78495 --- /dev/null +++ b/build_scripts/win/deploy_windows.cmd @@ -0,0 +1,119 @@ +@echo off +REM Echo off to avoid spam. + +REM Non zero is failure, 0 is success. +SET exit_code_success=0 +SET exit_code_failure_build_apps=1 +SET exit_code_failure_build_locations=2 + +SET output_dir="\bin\win64\" + +REM Used for echos. +SET current_activity=DEPLOY + +REM If scripts are chain called the original dirs should not be overwritten. +IF NOT DEFINED original_dir ( + SET original_dir=%CD% +) +IF NOT DEFINED project_dir ( + REM Arg 0 (called %0) is the full path to the file. + REM https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call#batch-parameters + REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. + SET folder_path=%~dp0 + REM Project dir is up two dirs from the file. + SET project_dir=%folder_path%\..\..\ +) + +ECHO %current_activity%: Testing if all required build environment values are set: +IF NOT DEFINED QT_LOC ( + ECHO %current_activity%: QT_LOC not defined. Using default value. + SET QT_LOC="C:\Qt\5.11.1\msvc2017_64\bin\" +) +ECHO %current_activity%: QT_LOC set to '%QT_LOC%'. +IF EXIST %QT_LOC% ( + ECHO %current_activity%: QT_LOC exists. +) ELSE ( + ECHO %current_activity%: QT_LOC directory does not exist. Exiting. + EXIT /B %exit_code_failure_build_locations% +) + +ECHO %current_activity%: All required build environment values are set. + +IF NOT EXIST %project_dir%\%output_dir% ( + ECHO %current_activity%: Output dir '%output_dir%' does not exist. Creating. + mkdir %project_dir%\%output_dir% + ECHO %current_activity%: Output dir created. +) + +cd %project_dir%\%output_dir% + +IF DEFINED BUILD_DEBUG ( + ECHO %current_activity%: BUILD_DEBUG var set. Compiling for debug. + SET compile_level=debug +) ELSE ( + ECHO %current_activity%: BUILD_DEBUG var not set. Compiling for release. + SET compile_level=release +) + +ECHO %current_activity%: Running windeployqt: + +REM windeployqt requires the QT\bin location to be in the path. +REM Changing the PATH var is not ideal, but windeployqt does not work otherwise. +set original_path=%PATH% +set PATH=%QT_LOC%;%PATH% + +REM Caret newline (^CFLR) splits a command over several lines. +REM This is done to avoid one ultra long line. + +windeployqt --dir AdvancedSettings\qtdata ^ +--libdir AdvancedSettings ^ +--plugindir AdvancedSettings\qtdata\plugins ^ +--no-system-d3d-compiler ^ +--no-opengl-sw ^ +--%compile_level% ^ +--qmldir ..\..\src\res\qml\ ^ +AdvancedSettings\AdvancedSettings.exe + +REM windeployqt does not exit on error by itself. +IF ERRORLEVEL 1 EXIT /B %exit_code_failure_build_apps% +REM Return the PATH to original as quickly as possible. +set PATH=%original_path% +ECHO %current_activity%: windeployqt done. + +REM Switches used for copy: +REM /V Verifies that files have been copied correctly. +REM /Q Suppresses xcopy spam. +REM /Y Skips the overwrite yes prompt. +REM /E Copies all subdirs, even if they are empty. +REM /I "If Source is a directory or contains wildcards and Destination does not exist, +REM xcopy assumes Destination specifies a directory name and creates a new directory. +REM Then, xcopy copies all specified files into the new directory. By default, +REM xcopy prompts you to specify whether Destination is a file or a directory." + +ECHO %current_activity%: Copying necessary files. +copy /V /Y "%project_dir%\Readme.md" "%project_dir%\%output_dir%\AdvancedSettings\Readme.md" +ECHO %current_activity%: README copied. + +REM All three licenses must be included in binary releases, as per the terms. +copy /V /Y "%project_dir%\LICENSE" "%project_dir%\%output_dir%\AdvancedSettings\LICENSE-GPL.txt" +copy /V /Y "%project_dir%\third-party\openvr\LICENSE" "%project_dir%\%output_dir%\AdvancedSettings\LICENSE-VALVE.txt" +copy /V /Y "%project_dir%\third-party\easylogging++\LICENSE" "%project_dir%\%output_dir%\AdvancedSettings\LICENSE-MIT.txt" +ECHO %current_activity%: LICENSE files copied. + +xcopy /Q /Y /E /I /V "%project_dir%\src\res" "%project_dir%\%output_dir%\AdvancedSettings\res\" +ECHO %current_activity%: Resource files copied. + +copy /V /Y "%project_dir%\src\restartvrserver.bat" "%project_dir%\%output_dir%\AdvancedSettings\restartvrserver.bat" +copy /V /Y "%project_dir%\src\startdesktopmode.bat" "%project_dir%\%output_dir%\AdvancedSettings\startdesktopmode.bat" +ECHO %current_activity%: Extra batch files copied. + +copy /V /Y "%project_dir%\src\qt.conf" "%project_dir%\%output_dir%\AdvancedSettings\qt.conf" +copy /V /Y "%project_dir%\src\manifest.vrmanifest" "%project_dir%\%output_dir%\AdvancedSettings\manifest.vrmanifest" +ECHO %current_activity%: VR specific configuration files copied. + +copy /V /Y "%project_dir%\third-party\openvr\bin\win64\openvr_api.dll" "%project_dir%\%output_dir%\AdvancedSettings\openvr_api.dll" +ECHO %current_activity%: OpenVR .dll copied. + +cd %original_dir% + +ECHO %current_activity%: %current_activity% DONE. \ No newline at end of file diff --git a/build_scripts/win/package_windows.cmd b/build_scripts/win/package_windows.cmd new file mode 100644 index 0000000..175e848 --- /dev/null +++ b/build_scripts/win/package_windows.cmd @@ -0,0 +1,70 @@ +@echo off +REM Echo off to avoid spam. + +REM Non zero is failure, 0 is success. +SET exit_code_success=0 +SET exit_code_failure_build_apps=1 +SET exit_code_failure_build_locations=2 + +SET output_dir="\bin\win64\" + +REM Used for echos. +SET current_activity=PACKAGE + +REM If scripts are chain called the original dirs should not be overwritten. +IF NOT DEFINED original_dir ( + SET original_dir=%CD% +) +IF NOT DEFINED project_dir ( + REM Arg 0 (called %0) is the full path to the file. + REM https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call#batch-parameters + REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. + SET folder_path=%~dp0 + REM Project dir is up two dirs from the file. + SET project_dir=%folder_path%\..\..\ +) + +REM ZIP_LOC can't be called 7Z_LOC because of Windows limitations. +ECHO %current_activity%: Testing if all required build environment values are set: +IF NOT DEFINED ZIP_LOC ( + ECHO %current_activity%: ZIP_LOC not defined. Using default value. + SET ZIP_LOC="C:\Program Files\7-Zip\7z.exe" +) +ECHO %current_activity%: ZIP_LOC set to '%ZIP_LOC%'. +IF EXIST %ZIP_LOC% ( + ECHO %current_activity%: ZIP_LOC exists. +) ELSE ( + ECHO %current_activity%: ZIP_LOC directory does not exist. Exiting. + EXIT /B %exit_code_failure_build_locations% +) + +ECHO %current_activity%: Testing if all required build environment values are set: +IF NOT DEFINED NSIS_LOC ( + ECHO %current_activity%: NSIS_LOC not defined. Using default value. + SET NSIS_LOC="C:\Program Files (x86)\NSIS\" +) +ECHO %current_activity%: NSIS_LOC set to '%NSIS_LOC%'. +IF EXIST %NSIS_LOC% ( + ECHO %current_activity%: NSIS_LOC exists. +) ELSE ( + ECHO %current_activity%: NSIS_LOC directory does not exist. Exiting. + EXIT /B %exit_code_failure_build_locations% +) + +ECHO %current_activity%: All required build environment values are set. + +ECHO %current_activity%: Running 7zip: +%ZIP_LOC% a %project_dir%\%output_dir%\AdvancedSettings.zip %project_dir%\%output_dir%\AdvancedSettings\* +ECHO %current_activity%: 7zip done. + +ECHO %current_activity%: Running NSIS: +REM Trying to launch makensis without CD into the dir does not work for some reason. +CD %NSIS_LOC% +REM /V2 is show warnings and errors, /WX is treat warnings as errors. +makensis /V2 /WX %project_dir%\installer\installer.nsi +IF ERRORLEVEL 1 EXIT /B %exit_code_failure_build_apps% +ECHO %current_activity%: NSIS done. + +CD %original_dir% + +ECHO %current_activity%: %current_activity% DONE. \ No newline at end of file From eee7148c00291b2f309db64df6feaf1079a7032f Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 26 Dec 2018 18:05:06 +0100 Subject: [PATCH 2/9] New build_windows.cmd Change names of build scripts --- .../win/{build_windows.cmd => build.cmd} | 0 .../win/{deploy_windows.cmd => deploy.cmd} | 0 .../win/{package_windows.cmd => package.cmd} | 8 ++++ build_windows.cmd | 44 +++++++++++-------- package.cmd | 22 ---------- 5 files changed, 33 insertions(+), 41 deletions(-) rename build_scripts/win/{build_windows.cmd => build.cmd} (100%) rename build_scripts/win/{deploy_windows.cmd => deploy.cmd} (100%) rename build_scripts/win/{package_windows.cmd => package.cmd} (86%) delete mode 100644 package.cmd diff --git a/build_scripts/win/build_windows.cmd b/build_scripts/win/build.cmd similarity index 100% rename from build_scripts/win/build_windows.cmd rename to build_scripts/win/build.cmd diff --git a/build_scripts/win/deploy_windows.cmd b/build_scripts/win/deploy.cmd similarity index 100% rename from build_scripts/win/deploy_windows.cmd rename to build_scripts/win/deploy.cmd diff --git a/build_scripts/win/package_windows.cmd b/build_scripts/win/package.cmd similarity index 86% rename from build_scripts/win/package_windows.cmd rename to build_scripts/win/package.cmd index 175e848..158937b 100644 --- a/build_scripts/win/package_windows.cmd +++ b/build_scripts/win/package.cmd @@ -53,6 +53,14 @@ IF EXIST %NSIS_LOC% ( ECHO %current_activity%: All required build environment values are set. +IF DEFINED BUILD_DEBUG ( + ECHO %current_activity%: BUILD_DEBUG var set. NOT PACKAGING TO AVOID SHIPPING DEBUG BUILDS. + ECHO %current_activity%: NOT PACKAGING TO AVOID SHIPPING DEBUG BUILDS. + ECHO %current_activity%: NOT PACKAGING TO AVOID SHIPPING DEBUG BUILDS. + ECHO %current_activity%: NOT PACKAGING TO AVOID SHIPPING DEBUG BUILDS. + EXIT /B %exit_code_failure_build_apps% +) + ECHO %current_activity%: Running 7zip: %ZIP_LOC% a %project_dir%\%output_dir%\AdvancedSettings.zip %project_dir%\%output_dir%\AdvancedSettings\* ECHO %current_activity%: 7zip done. diff --git a/build_windows.cmd b/build_windows.cmd index ffa19e3..e092cc8 100644 --- a/build_windows.cmd +++ b/build_windows.cmd @@ -1,25 +1,31 @@ -echo on +@echo off +REM Echo off to avoid spam. -SET project_dir="%cd%" +REM Used for echos. +SET top_level_activity=MASTER -echo Set up environment... -set original_path=%PATH% -set PATH=%QT%\bin\;C:\Qt\Tools\QtCreator\bin\;C:\Qt\QtIFW2.0.1\bin\;C:\Program Files (x86)\NSIS\;%PATH% -call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM% +REM If scripts are chain called the original dirs should not be overwritten. +IF NOT DEFINED original_dir ( + SET original_dir=%CD% +) +IF NOT DEFINED project_dir ( + REM Arg 0 (called %0) is the full path to the file. + REM https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call#batch-parameters + REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. + SET folder_path=%~dp0 + REM Project dir is up two dirs from the file. + SET project_dir=%folder_path%\..\..\ +) -cd "%project_dir% -echo Building AdvancedSettings... -qmake -spec win32-msvc CONFIG+=x86_64 CONFIG-=debug CONFIG+=release -nmake +ECHO %top_level_activity%: Calling build script. +CALL %project_dir%\build_scripts\win\build_windows.cmd -echo Packaging... -mkdir %project_dir%\bin\win64\ -cd %project_dir%\bin\win64\ -windeployqt --dir AdvancedSettings\qtdata --libdir AdvancedSettings --plugindir AdvancedSettings\qtdata\plugins --no-system-d3d-compiler --no-opengl-sw --release --qmldir ..\..\src\res\qml\ AdvancedSettings\AdvancedSettings.exe +ECHO %top_level_activity%: Calling deployment script. +CALL %project_dir%\build_scripts\win\deploy_windows.cmd -rd /s /q AdvancedSettings\moc\ -rd /s /q AdvancedSettings\obj\ -rd /s /q AdvancedSettings\qrc\ +ECHO %top_level_activity%: Calling packaging script. +CALL %project_dir%\build_scripts\win\package_windows.cmd -set PATH=%original_path% -cd %project_dir% +CD %original_dir% + +ECHO %top_level_activity%: MASTER DONE. \ No newline at end of file diff --git a/package.cmd b/package.cmd deleted file mode 100644 index 19a7a58..0000000 --- a/package.cmd +++ /dev/null @@ -1,22 +0,0 @@ -echo on - -SET project_dir="%cd%" - -cd %project_dir%\bin\win64\ - -echo Copying project files for archival... -copy "%project_dir%\Readme.md" "AdvancedSettings\Readme.md" -copy "%project_dir%\LICENSE" "AdvancedSettings\LICENSE.txt" -xcopy /Y /E /I "%project_dir%\src\res" "AdvancedSettings\res\" -copy "%project_dir%\src\restartvrserver.bat" "AdvancedSettings\restartvrserver.bat" -copy "%project_dir%\src\startdesktopmode.bat" "AdvancedSettings\startdesktopmode.bat" -copy "%project_dir%\src\qt.conf" "AdvancedSettings\qt.conf" -copy "%project_dir%\src\manifest.vrmanifest" "AdvancedSettings\manifest.vrmanifest" -copy "%project_dir%\third-party\openvr\bin\win64\openvr_api.dll" "AdvancedSettings\openvr_api.dll" - -echo Packaging portable archive... -7z a AdvancedSettings.zip AdvancedSettings - -echo Creating installer... -cd %project_dir%/installer -makensis installer.nsi From 43eafba7a75a2143b27754e8ec60dcd15946d6f8 Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 26 Dec 2018 18:20:13 +0100 Subject: [PATCH 3/9] Add error handling to master --- build_windows.cmd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/build_windows.cmd b/build_windows.cmd index e092cc8..1fe6045 100644 --- a/build_windows.cmd +++ b/build_windows.cmd @@ -14,17 +14,20 @@ IF NOT DEFINED project_dir ( REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. SET folder_path=%~dp0 REM Project dir is up two dirs from the file. - SET project_dir=%folder_path%\..\..\ + SET project_dir=%folder_path% ) ECHO %top_level_activity%: Calling build script. CALL %project_dir%\build_scripts\win\build_windows.cmd +IF ERRORLEVEL 1 EXIT /B 1 ECHO %top_level_activity%: Calling deployment script. CALL %project_dir%\build_scripts\win\deploy_windows.cmd +IF ERRORLEVEL 1 EXIT /B 1 ECHO %top_level_activity%: Calling packaging script. CALL %project_dir%\build_scripts\win\package_windows.cmd +IF ERRORLEVEL 1 EXIT /B 1 CD %original_dir% From 2085d0716b10ddcde74c8aff7e2bf5fb094861f7 Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 26 Dec 2018 19:04:17 +0100 Subject: [PATCH 4/9] Update appveyor, .gitignore and master build script --- .gitignore | 1 + appveyor.yml | 9 ++++++--- build_windows.cmd | 28 ++++++++++++++-------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 27860a8..17ae462 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ Makefile* *.stash *.appxmanifest *.user +installer/AdvancedSettings-Installer.exe \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 3c215a3..af3c294 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,10 +2,14 @@ image: Visual Studio 2017 environment: matrix: - - QT: C:\Qt\5.10.1\msvc2017_64 - PLATFORM: amd64 + - QT_LOC: C:\Qt\5.11.2\msvc2017_64\bin\ + VS_LOC: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"' + JOM_LOC: C:\Qt\Tools\QtCreator\bin\jom.exe + NSIS_LOC: C:\Program Files (x86)\NSIS\ + ZIP_LOC: 7z COMPILER: msvc VSVER: 14 + clone_depth: 1 @@ -14,7 +18,6 @@ init: build_script: - call "build_windows.cmd" - - call "package.cmd" artifacts: - path: bin\win64\AdvancedSettings.zip diff --git a/build_windows.cmd b/build_windows.cmd index 1fe6045..87afac4 100644 --- a/build_windows.cmd +++ b/build_windows.cmd @@ -5,28 +5,28 @@ REM Used for echos. SET top_level_activity=MASTER REM If scripts are chain called the original dirs should not be overwritten. -IF NOT DEFINED original_dir ( - SET original_dir=%CD% -) -IF NOT DEFINED project_dir ( - REM Arg 0 (called %0) is the full path to the file. - REM https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call#batch-parameters - REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. - SET folder_path=%~dp0 - REM Project dir is up two dirs from the file. - SET project_dir=%folder_path% -) + +SET original_dir=%CD% + + +REM Arg 0 (called %0) is the full path to the file. +REM https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call#batch-parameters +REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. +SET folder_path=%~dp0 +REM Project dir is up two dirs from the file. +SET project_dir=%folder_path% + ECHO %top_level_activity%: Calling build script. -CALL %project_dir%\build_scripts\win\build_windows.cmd +CALL %project_dir%\build_scripts\win\build.cmd IF ERRORLEVEL 1 EXIT /B 1 ECHO %top_level_activity%: Calling deployment script. -CALL %project_dir%\build_scripts\win\deploy_windows.cmd +CALL %project_dir%\build_scripts\win\deploy.cmd IF ERRORLEVEL 1 EXIT /B 1 ECHO %top_level_activity%: Calling packaging script. -CALL %project_dir%\build_scripts\win\package_windows.cmd +CALL %project_dir%\build_scripts\win\package.cmd IF ERRORLEVEL 1 EXIT /B 1 CD %original_dir% From fc103633fefb4ac9318e2aeacea8fd9ce9a01c6c Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 26 Dec 2018 20:04:55 +0100 Subject: [PATCH 5/9] Update package script to consider path vars --- build_scripts/win/package.cmd | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/build_scripts/win/package.cmd b/build_scripts/win/package.cmd index 158937b..59901fd 100644 --- a/build_scripts/win/package.cmd +++ b/build_scripts/win/package.cmd @@ -26,25 +26,38 @@ IF NOT DEFINED project_dir ( REM ZIP_LOC can't be called 7Z_LOC because of Windows limitations. ECHO %current_activity%: Testing if all required build environment values are set: + IF NOT DEFINED ZIP_LOC ( ECHO %current_activity%: ZIP_LOC not defined. Using default value. SET ZIP_LOC="C:\Program Files\7-Zip\7z.exe" ) ECHO %current_activity%: ZIP_LOC set to '%ZIP_LOC%'. -IF EXIST %ZIP_LOC% ( + +REM EXIST won't find items in the PATH. WHERE will. +SET ZIP_VALID=0 +IF EXIST %ZIP_LOC% SET ZIP_VALID=1 +WHERE /Q %ZIP_LOC% +IF NOT ERRORLEVEL 1 SET ZIP_VALID=1 + +IF %ZIP_VALID% EQU 1 ( ECHO %current_activity%: ZIP_LOC exists. ) ELSE ( ECHO %current_activity%: ZIP_LOC directory does not exist. Exiting. EXIT /B %exit_code_failure_build_locations% ) -ECHO %current_activity%: Testing if all required build environment values are set: IF NOT DEFINED NSIS_LOC ( ECHO %current_activity%: NSIS_LOC not defined. Using default value. SET NSIS_LOC="C:\Program Files (x86)\NSIS\" ) ECHO %current_activity%: NSIS_LOC set to '%NSIS_LOC%'. -IF EXIST %NSIS_LOC% ( + +SET NSIS_VALID=0 +IF EXIST %NSIS_LOC% SET NSIS_VALID=1 +WHERE /Q %NSIS_LOC% +IF NOT ERRORLEVEL 1 SET NSIS_VALID=1 + +IF %NSIS_VALID% EQU 1 ( ECHO %current_activity%: NSIS_LOC exists. ) ELSE ( ECHO %current_activity%: NSIS_LOC directory does not exist. Exiting. From 8d0277f6cf35b904f935a1b1fb9e6f442b06e120 Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 26 Dec 2018 20:11:02 +0100 Subject: [PATCH 6/9] Add quotes to all env vars in appveyor --- appveyor.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index af3c294..2f9978d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,10 +2,10 @@ image: Visual Studio 2017 environment: matrix: - - QT_LOC: C:\Qt\5.11.2\msvc2017_64\bin\ + - QT_LOC: '"C:\Qt\5.11.2\msvc2017_64\bin\"' VS_LOC: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"' - JOM_LOC: C:\Qt\Tools\QtCreator\bin\jom.exe - NSIS_LOC: C:\Program Files (x86)\NSIS\ + JOM_LOC: '"C:\Qt\Tools\QtCreator\bin\jom.exe"' + NSIS_LOC: '"C:\Program Files (x86)\NSIS\"' ZIP_LOC: 7z COMPILER: msvc VSVER: 14 From de8dffe40f781ab27fb3e9857f5c9ac4d0a740ec Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 26 Dec 2018 20:23:16 +0100 Subject: [PATCH 7/9] Add extra checks for environment vars --- build_scripts/win/build.cmd | 13 ++++++++++++- build_scripts/win/deploy.cmd | 1 + build_scripts/win/package.cmd | 14 ++++++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/build_scripts/win/build.cmd b/build_scripts/win/build.cmd index 46a9d72..c88a9f3 100644 --- a/build_scripts/win/build.cmd +++ b/build_scripts/win/build.cmd @@ -25,6 +25,7 @@ IF NOT DEFINED project_dir ( REM Change dir to the project dir, otherwise qmake doesn't know where it is. CD %project_dir% +REM QT_LOC is a directory, it can't be in the path, no reason to check using WHERE. ECHO %current_activity%: Testing if all required build environment values are set: IF NOT DEFINED QT_LOC ( ECHO %current_activity%: QT_LOC not defined. Using default value. @@ -43,7 +44,17 @@ IF NOT DEFINED VS_LOC ( SET VS_LOC="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" ) ECHO %current_activity%: VS_LOC set to '%VS_LOC%'. -IF EXIST %VS_LOC% ( + +REM EXIST won't find items in the PATH. WHERE will. +SET VS_VALID=0 +IF EXIST %VS_LOC% SET VS_VALID=1 +REM Prevents error message spam if it doesn't find it in PATH. +IF NOT %VS_VALID% EQU 1 ( + WHERE /Q %VS_LOC% + IF NOT ERRORLEVEL 1 SET VS_VALID=1 +) + +IF %VS_VALID% EQU 1 ( ECHO %current_activity%: VS_LOC exists. ) ELSE ( ECHO %current_activity%: VS_LOC directory does not exist. Exiting. diff --git a/build_scripts/win/deploy.cmd b/build_scripts/win/deploy.cmd index 3a78495..91fc32a 100644 --- a/build_scripts/win/deploy.cmd +++ b/build_scripts/win/deploy.cmd @@ -29,6 +29,7 @@ IF NOT DEFINED QT_LOC ( ECHO %current_activity%: QT_LOC not defined. Using default value. SET QT_LOC="C:\Qt\5.11.1\msvc2017_64\bin\" ) +REM QT_LOC is a directory, it can't be in the path, no reason to check using WHERE. ECHO %current_activity%: QT_LOC set to '%QT_LOC%'. IF EXIST %QT_LOC% ( ECHO %current_activity%: QT_LOC exists. diff --git a/build_scripts/win/package.cmd b/build_scripts/win/package.cmd index 59901fd..a1d7320 100644 --- a/build_scripts/win/package.cmd +++ b/build_scripts/win/package.cmd @@ -36,8 +36,10 @@ ECHO %current_activity%: ZIP_LOC set to '%ZIP_LOC%'. REM EXIST won't find items in the PATH. WHERE will. SET ZIP_VALID=0 IF EXIST %ZIP_LOC% SET ZIP_VALID=1 -WHERE /Q %ZIP_LOC% -IF NOT ERRORLEVEL 1 SET ZIP_VALID=1 +IF %ZIP_VALID% EQU 0 ( + WHERE /Q %ZIP_LOC% + IF NOT ERRORLEVEL 1 SET ZIP_VALID=1 +) IF %ZIP_VALID% EQU 1 ( ECHO %current_activity%: ZIP_LOC exists. @@ -52,10 +54,14 @@ IF NOT DEFINED NSIS_LOC ( ) ECHO %current_activity%: NSIS_LOC set to '%NSIS_LOC%'. +REM EXIST won't find items in the PATH. WHERE will. SET NSIS_VALID=0 IF EXIST %NSIS_LOC% SET NSIS_VALID=1 -WHERE /Q %NSIS_LOC% -IF NOT ERRORLEVEL 1 SET NSIS_VALID=1 +REM Prevents error message spam if it doesn't find it in PATH. +IF %NSIS_VALID% EQU 0 ( + WHERE /Q %NSIS_LOC% + IF NOT ERRORLEVEL 1 SET NSIS_VALID=1 +) IF %NSIS_VALID% EQU 1 ( ECHO %current_activity%: NSIS_LOC exists. From 2aa32bafad60072180d0f9b784590db47c1d797f Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 26 Dec 2018 21:58:03 +0100 Subject: [PATCH 8/9] Change variable expansion in build scripts Currently the variable expansion sometimes doesn't work when done over two variables. Inlining the ~dp0 call along with \..\..\ seems to work. Testing leads me to believe that the Windows command prompt caches things in a weird way. --- build_scripts/win/build.cmd | 3 +-- build_scripts/win/deploy.cmd | 3 +-- build_scripts/win/package.cmd | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/build_scripts/win/build.cmd b/build_scripts/win/build.cmd index c88a9f3..1118d41 100644 --- a/build_scripts/win/build.cmd +++ b/build_scripts/win/build.cmd @@ -17,9 +17,8 @@ IF NOT DEFINED project_dir ( REM Arg 0 (called %0) is the full path to the file. REM https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call#batch-parameters REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. - SET folder_path=%~dp0 REM Project dir is up two dirs from the file. - SET project_dir=%folder_path%\..\..\ + SET project_dir=%~dp0\..\..\ ) REM Change dir to the project dir, otherwise qmake doesn't know where it is. diff --git a/build_scripts/win/deploy.cmd b/build_scripts/win/deploy.cmd index 91fc32a..f19f1b9 100644 --- a/build_scripts/win/deploy.cmd +++ b/build_scripts/win/deploy.cmd @@ -19,9 +19,8 @@ IF NOT DEFINED project_dir ( REM Arg 0 (called %0) is the full path to the file. REM https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call#batch-parameters REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. - SET folder_path=%~dp0 REM Project dir is up two dirs from the file. - SET project_dir=%folder_path%\..\..\ + SET project_dir=%~dp0\..\..\ ) ECHO %current_activity%: Testing if all required build environment values are set: diff --git a/build_scripts/win/package.cmd b/build_scripts/win/package.cmd index a1d7320..b7b76ad 100644 --- a/build_scripts/win/package.cmd +++ b/build_scripts/win/package.cmd @@ -19,9 +19,8 @@ IF NOT DEFINED project_dir ( REM Arg 0 (called %0) is the full path to the file. REM https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/call#batch-parameters REM As per above link, %~dp0 expands the zeroth arg to a drive letter and path only. - SET folder_path=%~dp0 REM Project dir is up two dirs from the file. - SET project_dir=%folder_path%\..\..\ + SET project_dir=%~dp0\..\..\ ) REM ZIP_LOC can't be called 7Z_LOC because of Windows limitations. From b5877cd4e7e4cabf4bccc6fc7d05e2b4a787f251 Mon Sep 17 00:00:00 2001 From: Vasily Date: Wed, 26 Dec 2018 22:08:45 +0100 Subject: [PATCH 9/9] Update documentation for building on windows --- docs/building_for_windows.md | 57 ++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/docs/building_for_windows.md b/docs/building_for_windows.md index b6c7b51..960d5ba 100644 --- a/docs/building_for_windows.md +++ b/docs/building_for_windows.md @@ -4,6 +4,8 @@ > * [Requirements](#requirements) > * [Locations and Environment Variables](#locs_and_envs) > * [Building](#features) + > * [Using with QtCreator](#qt_creator) + > * [Using with Visual Studio](#visual_studio) ## Requirements @@ -14,21 +16,64 @@ For compiling: 2. Qt Framework (tested on 5.10 and 5.11) Additionally, for fully building portable and installer release versions: -3. 7zip Command Line +3. 7zip 4. Nullsoft Scriptable Install System (NSIS) ## Locations and Environment Variables -Visual Studio must be installed in the default location of `C:\Program Files (x86)\Microsoft Visual Studio\2017\Community`. +The following environmental variables are relevant for building the project. -The `QT` environment variable must be set to the location of your Qt installation (for example `C:\Qt\5.11.1\msvc2017_64`). +| Environment Variable | Purpose | +| -------------------- | ------------- | +| `QT_LOC` | Path to your Qt `\bin\` folder. | +| `VS_LOC` | Path to your Visual Studio `vcvarsall.bat` file. | +| `JOM_LOC` | Path to an `.exe` of `jom.exe`. Usually installed with Qt. `jom` is a wrapper around `nmake` allowing more threads to be used. It is not required, but using `nmake`is slower. If `JOM_LOC` isn't defined, or the `.exe` can't be found `nmake` will be used by default. | +| `ZIP_LOC` | Path to your 7zip `.exe`. Both portable and installer will work. | +| `NSIS_LOC` | Path to your installation of NSIS containing the `makensis` file. Both portable and installer will work. | -The `PLATFORM` environment variable must be set to `amd64`. +If an environment variable isn't set a default value will be provided. The default values are shown in the table below. -For building the portable and installer release versions, the locations of 7zip Command Line (`7z.exe`) and NSIS (`makensis.exe`) must be in the `PATH` environment variable. +| Environment Variable | Default Value | +| -------------------- | ------------- | +| `QT_LOC` | `"C:\Qt\5.11.1\msvc2017_64\bin\"` | +| `VS_LOC` | `"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"` | +| `JOM_LOC` | `"C:\Qt\Tools\QtCreator\bin\jom.exe"`| +| `ZIP_LOC` | `"C:\Program Files\7-Zip\7z.exe"` | +| `NSIS_LOC` | `"C:\Program Files (x86)\NSIS\"` | + +Additionally, these optional environment variables are supported. + +| Environment Variable | Purpose | +| -------------------- | ------------- | +| `BUILD_DEBUG` | If set, a debug version will be built. The packaging script will not run with this var set. | +| `BUILD_VSPROJ` | If set, Visual Studio project files will be built. | + +Remember that there's a difference between an unset variable and a variable set to an empty string. `SET BUILD_DEBUG=""` does not unset the variable. You need to write `SET BUILD_DEBUG=`. + +The `.dll` files necessary for a release build differ from those needed by a debug build. Therefore you need to make sure you run all scripts with `BUILD_DEBUG` either defined or undefined, depending on your needs. ## Building -With the programs above installed and environment variables set, go into the root folder of the repository and first run `build_windows.cmd` and then `package.cmd`. Compiled binaries along with everything needed to run portable will output to `.\bin\win64\AdvancedSettings\`. +With the programs above installed and environment variables set, go into the root folder of the repository and run `build_windows.cmd`. Compiled binaries along with everything needed to run portable will output to `.\bin\win64\AdvancedSettings\`. + + +## Using with QtCreator + +Run `build_windows.cmd` once and fully build (packaging not necessary) the application. Open the `.pro` file in Qt Creator. A build and toolchain option should be marked in Qt Creator, with all others unmarked. If it isn't, set the directory to be the root repo directory. You should now be able to compile and run in Qt Creator without issues. + +Notice that you may need to redeploy library files if you make large changes (run `build_scripts\win\deploy.cmd`). + +Additionally, you can set Qt Creator to run `build_scripts\win\deploy.cmd` on compilation in order to ensure that the correct libraries are present. Remember to set or unset `BUILD_DEBUG` depending on your needs. + + +## Using with Visual Studio + +Run `build_windows.cmd` once and fully build (packaging not necessary) the application with the `BUILD_VSPROJ` environment variable set. Open the newly created project file. If you compiled a release build (`BUILD_DEBUG` not set) change the build type to release in Visual Studio. You should be able to compile and run with Visual Studio without issues. + +Notice that any new files you add or compiler settings you change will not be backported to the `.pro` file. Hence it is necessary to manually change the `.pro` file. + +Notice that you may need to redeploy library files if you make large changes (run `build_scripts\win\deploy.cmd`). + +Additionally, you can set Visual Studio to run `build_scripts\win\deploy.cmd` on compilation in order to ensure that the correct libraries are present. Remember to set or unset `BUILD_DEBUG` depending on your needs. \ No newline at end of file