-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathbuild.cmd
More file actions
210 lines (170 loc) · 6.08 KB
/
Copy pathbuild.cmd
File metadata and controls
210 lines (170 loc) · 6.08 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
@echo off
REM Copyright (C) Microsoft Corporation.
REM Copyright (C) 2025 IAMAI CONSULTING CORP
REM MIT License.
setlocal ENABLEDELAYEDEXPANSION
set "ROOT_DIR=%~dp0"
set "PAS_BUILD_UNITY=OFF"
REM Preserve the original tail: SHIFT tokenizes unquoted NMake assignments at =.
set "PAS_BUILD_ARGS= %* "
:parse_build_args
if "%~1"=="" goto :build_args_ready
if /i "%~1"=="--unity" (
set "PAS_BUILD_UNITY=ON"
set "PAS_BUILD_ARGS=!PAS_BUILD_ARGS: --unity = !"
set "PAS_BUILD_ARGS=!PAS_BUILD_ARGS: "--unity" = !"
)
shift
goto :parse_build_args
:build_args_ready
REM =====================================================
REM Check Visual Studio environment
REM =====================================================
if "%VisualStudioVersion%"=="16.0" (
echo Detected Visual Studio environment: VS 2019
) else if "%VisualStudioVersion%"=="17.0" (
echo Detected Visual Studio environment: VS 2022
) else (
echo Visual Studio developer environment not detected. Initializing VS 2022 build tools.
)
REM =====================================================
REM Unreal Engine detection (OPTIONAL)
REM UE_ROOT is optional to allow standalone / Unity builds
REM =====================================================
set "UE_DETECTED=0"
set "UE_MINOR="
REM Accept UE_ROOT with or without surrounding quotes.
if defined UE_ROOT set "UE_ROOT=!UE_ROOT:"=!"
if not defined UE_ROOT (
echo:
echo UE_ROOT not set. Building without Unreal Engine integration.
goto :select_msvc_default
)
set "BUILD_VERSION_FILE=!UE_ROOT!\Engine\Build\Build.version"
if not exist "!BUILD_VERSION_FILE!" (
echo:
echo UE_ROOT is set but Build.version not found:
echo !BUILD_VERSION_FILE!
echo Falling back to standalone build.
goto :select_msvc_default
)
for /f "tokens=2 delims=:," %%A in ('findstr /i "MinorVersion" "!BUILD_VERSION_FILE!"') do (
set "UE_MINOR=%%A"
)
set "UE_MINOR=%UE_MINOR: =%"
echo Detected Unreal Engine version: 5.%UE_MINOR%
set "UE_DETECTED=1"
REM =====================================================
REM Select MSVC version (UE-aware)
REM =====================================================
if "%UE_MINOR%"=="2" (
set "MSVC_VER=14.37"
) else if "%UE_MINOR%"=="7" (
set "MSVC_VER=14.44"
) else if "%UE_MINOR%"=="8" (
set "MSVC_VER=14.44"
) else (
echo:
echo Unsupported Unreal Engine version 5.%UE_MINOR%
echo Falling back to default toolset.
goto :select_msvc_default
)
goto :msvc_ready
REM =====================================================
REM Default MSVC (standalone / Unity)
REM =====================================================
:select_msvc_default
echo Using default MSVC toolset (standalone / Unity build)
set "MSVC_VER="
REM =====================================================
REM Initialize MSVC environment
REM =====================================================
:msvc_ready
if defined MSVC_VER (
echo Requested MSVC toolset version: %MSVC_VER%
) else (
echo Requested MSVC toolset version: latest installed
)
set "VSWHERE=%SystemDrive%\Progra~2\Microsoft Visual Studio\Installer\vswhere.exe"
set "VS_INSTALL_DIR="
set "MSVC_TOOLS_VERSION="
if defined VSINSTALLDIR set "VS_INSTALL_DIR=%VSINSTALLDIR%"
call :check_vs_install "%ProgramFiles%\Microsoft Visual Studio\2022\Community"
call :check_vs_install "%ProgramFiles%\Microsoft Visual Studio\2022\Professional"
call :check_vs_install "%ProgramFiles%\Microsoft Visual Studio\2022\Enterprise"
call :check_vs_install "%SystemDrive%\Progra~2\Microsoft Visual Studio\2022\BuildTools"
if defined VS_INSTALL_DIR goto :vs_install_found
if not exist "!VSWHERE!" goto :vs_install_found
for /f "tokens=*" %%I in ('call "!VSWHERE!" -version "[17.0,18.0)" -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath') do set "VS_INSTALL_DIR=%%I"
:vs_install_found
if not defined VS_INSTALL_DIR (
echo:
echo [ERROR] Visual Studio 2022 with C++ build tools was not found.
goto :buildfailed_nomsg
)
if defined MSVC_VER (
for /d %%I in ("!VS_INSTALL_DIR!\VC\Tools\MSVC\%MSVC_VER%*") do (
if not defined MSVC_TOOLS_VERSION set "MSVC_TOOLS_VERSION=%%~nxI"
)
) else (
for /f "delims=" %%I in ('dir /b /ad /o-n "!VS_INSTALL_DIR!\VC\Tools\MSVC" 2^>NUL') do (
if not defined MSVC_TOOLS_VERSION set "MSVC_TOOLS_VERSION=%%I"
)
)
if not defined MSVC_TOOLS_VERSION (
echo:
if defined MSVC_VER (
echo [ERROR] MSVC toolset %MSVC_VER% was not found under:
) else (
echo [ERROR] No MSVC toolset was found under:
)
echo !VS_INSTALL_DIR!\VC\Tools\MSVC
if "%UE_DETECTED%"=="1" (
echo Install the requested MSVC toolset or update build.cmd for your Unreal Engine version.
) else (
echo Install the Visual Studio C++ build tools.
)
goto :buildfailed_nomsg
)
echo Using Visual Studio installation: %VS_INSTALL_DIR%
echo Using MSVC tools version: %MSVC_TOOLS_VERSION%
call "%VS_INSTALL_DIR%\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=%MSVC_TOOLS_VERSION%
if errorlevel 1 (
echo:
echo [ERROR] Failed to initialize MSVC %MSVC_TOOLS_VERSION%
goto :buildfailed_nomsg
)
set PATH=%VS_INSTALL_DIR%\MSBuild\Current\Bin\amd64;%VS_INSTALL_DIR%\MSBuild\Current\Bin;%PATH%
set MSBUILD_TOOLSET_ARGS=/p:VCToolsVersion=%MSVC_TOOLS_VERSION%
if "!UE_DETECTED!"=="1" (
set "PAS_TOOLCHAIN_ID=UE5.!UE_MINOR!-MSVC!MSVC_TOOLS_VERSION!"
) else (
set "PAS_TOOLCHAIN_ID=system-MSVC!MSVC_TOOLS_VERSION!"
)
echo Using Project AirSim build tree: build\win64\!PAS_TOOLCHAIN_ID!
where /q nmake
if errorlevel 1 (
echo:
echo [ERROR] nmake not found after initializing Visual Studio build tools.
goto :buildfailed_nomsg
)
REM =====================================================
REM Build
REM =====================================================
nmake /f build_windows.mk !PAS_BUILD_ARGS! PAS_BUILD_UNITY=!PAS_BUILD_UNITY!
if errorlevel 1 (
goto :buildfailed_nomsg
)
exit /b 0
REM =====================================================
REM Error handling
REM =====================================================
:buildfailed_nomsg
chdir /d "%ROOT_DIR%"
echo:
echo Build Failed.
exit /b 1
:check_vs_install
if defined VS_INSTALL_DIR exit /b 0
if exist "%~1\VC\Auxiliary\Build\vcvarsall.bat" set "VS_INSTALL_DIR=%~1"
exit /b 0