make-lrc.bat 4.65 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
:: Ring - native Windows LRC project generator

@echo off
if "%1" == "/?" goto Usage
if "%~1" == "" goto Usage

set doGen=N
set doBuild=N

set SCRIPTNAME=%~nx0

if "%1"=="gen" (
    set doGen=Y
14
    set command=Generate
15
16
) else if "%1"=="build" (
    set doBuild=Y
17
    set command=Build
18
19
20
21
) else (
    goto Usage
)

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if "%doGen%"=="Y" (
    if NOT "%4"=="" goto Version_New
    goto Default_version
) else (
    goto StartLocal
)

:Version_New
set QtDir=C:\\Qt\\%4%
set Version=%4%
if not exist "%QtDir%" echo This Qt path does not exist, using default version.
if exist "%QtDir%" goto StartLocal
:Default_version
set QtDir=C:\\Qt\\5.9.4
set Version=5.9.4
if not exist "%QtDir%" echo Default Qt path does not exist, check your installation path. &goto Usage

setlocal
:StartLocal

42
43
44
45
46
47
48
49
50
set arch=N

shift
:ParseArgs
if "%1" == "" goto FinishedArgs
if /I "%1"=="x86" (
    set arch=x86
) else if /I "%1"=="x64" (
    set arch=x64
51
52
) else if /I "%1"=="version" (
    shift
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
) else (
    goto Usage
)
shift
goto ParseArgs

:FinishedArgs
if "%arch%"=="x86" (
    set MSBUILD_ARGS=/nologo /p:useenv=true /p:Configuration=Release /p:Platform=Win32 /verbosity:normal /maxcpucount:%NUMBER_OF_PROCESSORS%
) else if "%arch%"=="x64" (
    set MSBUILD_ARGS=/nologo /p:useenv=true /p:Configuration=Release /p:Platform=x64 /verbosity:normal /maxcpucount:%NUMBER_OF_PROCESSORS%
)

@setlocal

set VSInstallerFolder="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"
if %PROCESSOR_ARCHITECTURE%==x86 set VSInstallerFolder="%ProgramFiles%\Microsoft Visual Studio\Installer"

pushd %VSInstallerFolder%
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do (
  set VSLATESTDIR=%%i
)
popd

echo VS Installation folder: %VSLATESTDIR%

if not exist "%VSLATESTDIR%\VC\Auxiliary\Build\vcvarsall.bat" (
    echo:
    echo VSInstallDir not found or not installed correctly.
    goto cleanup
)

if %PROCESSOR_ARCHITECTURE%==x86 (
86
87
    set Comp_x86=x86 10.0.16299.0
    set Comp_x64=x86_amd64 10.0.16299.0
88
) else (
89
90
    set Comp_x86=amd64_x86 10.0.16299.0
    set Comp_x64=amd64 10.0.16299.0
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
)

set path=%path:"=%
if "%arch%"=="x86" (
    call "%VSLATESTDIR%"\\VC\\Auxiliary\\Build\\vcvarsall.bat %Comp_x86%
) else if "%arch%"=="x64" (
    call "%VSLATESTDIR%"\\VC\\Auxiliary\\Build\\vcvarsall.bat %Comp_x64%
)

if "%arch%" neq "N" (
    if "%doGen%" neq "N" (
        goto genLRC
    ) else if "%doBuild%" neq "N" (
		goto buildLRC
    )
    goto :eof
)
goto Usage

:genLRC
111
echo Generating using Qt version: %Version%
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
setlocal EnableDelayedExpansion
set DaemonDir=%cd%\\..\\daemon
mkdir msvc
cd msvc
set PATH=C:\\Program Files\\CMake\\bin\\;%PATH%
if "echo QtDir is: %QtDir%"=="" (
    echo Error: QtDir not specified
    goto cleanup
)
set CMAKE_GENERATOR_STRING=""
set CMAKE_OPTIONS=""
if "%arch%"=="x86" (
    set CMAKE_GENERATOR_STRING="Visual Studio 15 2017 Win32"
    set QtCmakeDir=%QtDir%\\msvc2017\\lib\\cmake
) else if "%arch%"=="x64" (
    set CMAKE_GENERATOR_STRING="Visual Studio 15 2017 Win64"
    set QtCmakeDir=%QtDir%\\msvc2017_64\\lib\\cmake
)
130
set CMAKE_OPTIONS=-DQt5Core_DIR=!QtCmakeDir!\\Qt5Core -DQt5Sql_DIR=!QtCmakeDir!\\Qt5Sql -DQt5LinguistTools_DIR=!QtCmakeDir!\\Qt5LinguistTools -DQt5Concurrent_DIR=!QtCmakeDir!\\Qt5Concurrent -DQt5Gui_DIR=!QtCmakeDir!\\Qt5Gui -Dring_BIN=!DaemonDir!\MSVC\x64\ReleaseLib_win32\bin\dring.lib -DRING_INCLUDE_DIR=!DaemonDir!\src\dring
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
cmake .. -G !CMAKE_GENERATOR_STRING! !CMAKE_OPTIONS!
endlocal
goto cleanup

:buildLRC
:: build qtwrapper
msbuild msvc\src\qtwrapper\qtwrapper.vcxproj %MSBUILD_ARGS%
:: build lrc
msbuild msvc\ringclient_static.vcxproj %MSBUILD_ARGS%
goto cleanup

@endlocal

:Usage
echo:
echo The correct usage is:
echo:
148
echo     %SCRIPTNAME% [action] [architecture] [version] [version_para]
149
150
151
152
153
echo:
echo where
echo:
echo [action]           is: gen   ^| build
echo [architecture]     is: x86   ^| x64
154
155
echo [version]          is: version - optional
echo [version_para]     is: 5.9.4 ^| Qt version installed
156
157
echo:
echo For example:
158
159
160
echo     %SCRIPTNAME% gen x86                    - gen x86 static lib vs projects for qtwrapper/lrc for Qt version 5.9.4
echo     %SCRIPTNAME% gen x86 version 5.12.0     - gen x86 static lib vs projects for qtwrapper/lrc for Qt version 5.12.0
echo     %SCRIPTNAME% build x64                  - build x64 qtwrapper/lrc static libs
161
162
163
164
165
echo:
goto :eof

:cleanup
endlocal
166
167
168
169
170
171
172
if %ERRORLEVEL% geq 1 (
    echo %command% failed
    exit %ERRORLEVEL%
) else (
    echo %command% succeeded
    exit /B %ERRORLEVEL%
)