aboutsummaryrefslogtreecommitdiff
path: root/utils/vcbuild.bat
blob: 567166e94b87af3d4091228b4fca5e10967900e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
@if not "%verboseBuild%"=="y" echo off

rem  Shave and a Haircut
rem  (c) 2019 Epic Games
rem  US Patent 6720962

rem
rem  Build a Visual Studio project
rem

set result=0

setlocal

if a%5b==ab (
    echo Usage: vcbuild directory project config vsVersion solutionBaseName [bits]
    goto error
)

set builddir=%1
set project=%2
set config=%3
set vsVersion=%4
set solution=%5

set timeStr=%TIME: =%
set timeStr=%timeStr::=_%
set timeStr=%timeStr:.=_%
set logfile=%TEMP%\vcbuild_%timeStr%_%RANDOM%.log

set platform=x64

rem  For Visual Studio 7.* we used the normal solution and project file names,
rem  but from VS8 onward the solution and project files have Visual Studio major
rem  version number before the extension. E.g. "shaveHaircut-vs8.sln".
rem  Since the paths may contain parentheses, we cannot use the new style of
rem  'if' statements here.
if /i "%vsVersion%"=="vs10" goto useVS10
if /i "%vsVersion%"=="vs11" goto useVS11
if /i "%vsVersion%"=="vs14" goto useVS14
if /i "%vsVersion%"=="vs15" goto useVS15
if /i not "%vsVersion%"=="vs7" goto notVS7

    set solution=%solution%.sln
    set project=%project%.vcproj
    set vsDotVersion=7.1
    set vsPublicVersion=2003
    set vsToolsVar=VS71COMNTOOLS
    set vsToolsPath=%VS71COMNTOOLS%
    goto doneVSVersion
:notVS7
    set solution=%solution%-%vsVersion%.sln
    set project=%project%-%vsVersion%.vcproj
    set vsDotVersion=8.0
    set vsPublicVersion=2005
    set vsToolsVar=VS80COMNTOOLS
    set vsToolsPath=%VS80COMNTOOLS%
    goto doneVSVersion
:useVS10
    set solution=%solution%-%vsVersion%.sln
    set project=%project%-%vsVersion%.vcxproj
    set vsDotVersion=10.0
    set vsPublicVersion=2010
    set vsToolsVar=VS100COMNTOOLS
    set vsToolsPath=%VS100COMNTOOLS%
    goto doneVSVersion    
:useVS11
    set solution=%solution%-%vsVersion%.sln
    set project=%project%-%vsVersion%.vcxproj
    set vsDotVersion=11.0
    set vsPublicVersion=2012
    set vsToolsVar=VS110COMNTOOLS
    set vsToolsPath=%VS110COMNTOOLS%
    goto doneVSVersion        
:useVS14
    set solution=%solution%-%vsVersion%.sln
    set project=%project%-%vsVersion%.vcxproj
    set vsDotVersion=14.0
    set vsPublicVersion=2015
    set vsToolsVar=VS140COMNTOOLS
    set vsToolsPath=%VS140COMNTOOLS%
    goto doneVSVersion        
:useVS15
    set solution=%solution%-%vsVersion%.sln
    set project=%project%-%vsVersion%.vcxproj
    set vsDotVersion=15.0
    set vsPublicVersion=2017
    set vsToolsVar=VS150COMNTOOLS
    set vsToolsPath=%VS150COMNTOOLS%
    goto doneVSVersion        
    
:doneVSVersion

if not exist "%solution%" (
    echo vcbuild: Could not find solution file '%solution%'.
    echo vcbuild: Note that you must be in the same directory as the solution file
    goto error
)

set vsPath=%vsToolsPath%\..\IDE\devenv.exe

if exist "%vsPath%" goto foundIt
    set vsPath=c:\Program Files (x86)\Microsoft Visual Studio %vsDotVersion%\Common7\Tools\..\IDE\devenv.exe

if exist "%vsPath%" goto foundIt
    set vsPath=c:\Program Files (x86)\Microsoft Visual Studio\%vsPublicVersion%\Professional\Common7\Tools\..\IDE\devenv.exe

if exist "%vsPath%" goto foundIt
    echo vcbuild: Could not find %vsPath%. If you have installed Visual Studio
    echo vcbuild: %vsDotVersion% in a non-standard location, please set the
    echo vcbuild: %vsToolsVar% variable to point to its Tools folder.
goto error

:foundIt

rem  Remove the .exe from the devenv command so that the .com version will
rem  be used, if available.
rem
set vsPath=%vsPath:.exe=%

rem
rem  Visual Studio has problems with .\dir notation.  It's fine with
rem  dir1\dir2 it just seems to have trouble with using '.' for the current
rem  directory.  So we only add the path to the project file if the build dir
rem  is not the current directory.
rem
if not "%builddir%"=="." set project=%builddir%\%project%

@echo on
"%vsPath%" %solution% /rebuild "%config%" /project %project% /projectconfig "%config%|%platform%" >%logfile% 2>&1
@set errcode=%errorlevel%
@if not "%verboseBuild%"=="y" echo off

rem  If there was an error, display the build log.
if not %errcode%==0 type %logfile%

rem  For some reason Visual Studio 2017 keeps the log file open after its command
rem  has returned, which causes the deletion below to fail.
rem
if %vsPublicVersion% LSS 2017 (
    if exist %logfile% del %logfile%
)

if not %errcode%==0 goto error

endlocal
set result=0
goto done

:error
endlocal
set result=1

:done