[msvc/make.bat] Allow override of the build folder name
[blender.git] / make.bat
1 @echo off
2 REM This batch file does an out-of-source CMake build in ../build_windows
3 REM This is for users who like to configure & build Blender with a single command.
4 setlocal EnableDelayedExpansion
5 setlocal ENABLEEXTENSIONS
6 set BLENDER_DIR=%~dp0
7 set BLENDER_DIR_NOSPACES=%BLENDER_DIR: =%
8 if not "%BLENDER_DIR%"=="%BLENDER_DIR_NOSPACES%" (
9         echo There are spaces detected in the build path "%BLENDER_DIR%", this is currently not supported, exiting....
10         goto EOF
11 )
12 set BUILD_DIR=%BLENDER_DIR%..\build_windows
13 set BUILD_TYPE=Release
14 rem reset all variables so they do not get accidentally get carried over from previous builds
15 set BUILD_DIR_OVERRRIDE=
16 set BUILD_CMAKE_ARGS=
17 set BUILD_ARCH=
18 set BUILD_VS_VER=
19 set BUILD_VS_YEAR=
20 set KEY_NAME=
21 set MSBUILD_PLATFORM=
22 set MUST_CLEAN=
23 set NOBUILD=
24 set TARGET=
25 set WINDOWS_ARCH=
26 set TESTS_CMAKE_ARGS=
27 :argv_loop
28 if NOT "%1" == "" (
29
30         REM Help Message
31         if "%1" == "help" (
32                 goto HELP
33         )
34
35         REM Build Types
36         if "%1" == "debug" (
37                 set BUILD_TYPE=Debug
38         REM Build Configurations
39         ) else if "%1" == "builddir" (
40                 set BUILD_DIR_OVERRRIDE="%BLENDER_DIR%..\%2"
41                 shift /1
42         ) else if "%1" == "with_tests" (
43                 set TESTS_CMAKE_ARGS=-DWITH_GTESTS=On
44         ) else if "%1" == "full" (
45                 set TARGET=Full
46                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
47                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_full.cmake"
48         ) else if "%1" == "lite" (
49                 set TARGET=Lite
50                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
51                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_lite.cmake"
52         ) else if "%1" == "cycles" (
53                 set TARGET=Cycles
54                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
55                     -C"%BLENDER_DIR%\build_files\cmake\config\cycles_standalone.cmake"
56         ) else if "%1" == "headless" (
57                 set TARGET=Headless
58                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
59                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_headless.cmake"
60         ) else if "%1" == "bpy" (
61                 set TARGET=Bpy
62                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
63                     -C"%BLENDER_DIR%\build_files\cmake\config\bpy_module.cmake"
64         ) else if "%1" == "release" (
65                 set TARGET=Release
66         )       else if "%1" == "x86" (
67                 set BUILD_ARCH=x86
68         )       else if "%1" == "x64" (
69                 set BUILD_ARCH=x64
70         )       else if "%1" == "2017" (
71         set BUILD_VS_VER=15
72         set BUILD_VS_YEAR=2017
73         )       else if "%1" == "2015" (
74         set BUILD_VS_VER=14
75         set BUILD_VS_YEAR=2015
76         )       else if "%1" == "2013" (
77         set BUILD_VS_VER=12
78         set BUILD_VS_YEAR=2013
79         )       else if "%1" == "packagename" (
80         set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -DCPACK_OVERRIDE_PACKAGENAME="%2"
81         shift /1
82         )       else if "%1" == "nobuild" (
83         set NOBUILD=1
84         )       else if "%1" == "showhash" (
85                 for /f "delims=" %%i in ('git rev-parse HEAD') do echo Branch_hash=%%i
86                 cd release/datafiles/locale
87                 for /f "delims=" %%i in ('git rev-parse HEAD') do echo Locale_hash=%%i
88                 cd %~dp0
89                 cd release/scripts/addons
90                 for /f "delims=" %%i in ('git rev-parse HEAD') do echo Addons_Hash=%%i
91                 cd %~dp0
92                 goto EOF
93         REM Non-Build Commands
94         ) else if "%1" == "update" (
95                 svn up ../lib/*
96                 git pull --rebase
97                 git submodule foreach git pull --rebase origin master
98                 goto EOF
99         ) else if "%1" == "clean" (
100                 set MUST_CLEAN=1
101         ) else (
102                 echo Command "%1" unknown, aborting!
103                 goto EOF
104         )
105
106         shift /1
107         goto argv_loop
108 )
109 if "%BUILD_ARCH%"=="" (
110         if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
111                 set WINDOWS_ARCH= Win64
112                 set BUILD_ARCH=x64
113         ) else if "%PROCESSOR_ARCHITEW6432%" == "AMD64" (
114                 set WINDOWS_ARCH= Win64
115                 set BUILD_ARCH=x64
116         ) else (
117                 set WINDOWS_ARCH=
118                 set BUILD_ARCH=x86
119         )
120 ) else if "%BUILD_ARCH%"=="x64" (
121                 set WINDOWS_ARCH= Win64
122         ) else if "%BUILD_ARCH%"=="x86" (
123                 set WINDOWS_ARCH=
124         )
125
126 if "%BUILD_VS_VER%"=="" (
127         set BUILD_VS_VER=12
128         set BUILD_VS_YEAR=2013
129 )
130
131 if "%BUILD_ARCH%"=="x64" (
132         set MSBUILD_PLATFORM=x64
133         ) else if "%BUILD_ARCH%"=="x86" (
134                 set MSBUILD_PLATFORM=win32
135 )
136
137
138 if "%target%"=="Release" (
139                 rem for vc12 check for both cuda 7.5 and 8
140                 if "%CUDA_PATH%"=="" (
141                         echo Cuda Not found, aborting!
142                         goto EOF
143                 )
144                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
145                 -C"%BLENDER_DIR%\build_files\cmake\config\blender_release.cmake"
146 )
147
148 :DetectMSVC
149 REM Detect MSVC Installation for 2013-2015
150 if DEFINED VisualStudioVersion goto msvc_detect_finally
151 set VALUE_NAME=ProductDir
152 REM Check 64 bits
153 set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\%BUILD_VS_VER%.0\Setup\VC"
154 for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO set MSVC_VC_DIR=%%C
155 if DEFINED MSVC_VC_DIR goto msvc_detect_finally
156 REM Check 32 bits
157 set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\%BUILD_VS_VER%.0\Setup\VC"
158 for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO set MSVC_VC_DIR=%%C
159 if DEFINED MSVC_VC_DIR goto msvc_detect_finally
160 :msvc_detect_finally
161 if DEFINED MSVC_VC_DIR call "%MSVC_VC_DIR%\vcvarsall.bat"
162 if DEFINED MSVC_VC_DIR goto sanity_checks
163
164 rem MSVC Build environment 2017 and up.
165 for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SXS\VS7" /v %BUILD_VS_VER%.0 2^>nul`) DO set MSVC_VS_DIR=%%C
166 if DEFINED MSVC_VS_DIR goto msvc_detect_finally_2017
167 REM Check 32 bits
168 for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\sxs\vs7" /v %BUILD_VS_VER%.0 2^>nul`) DO set MSVC_VS_DIR=%%C
169 if DEFINED MSVC_VS_DIR goto msvc_detect_finally_2017
170 :msvc_detect_finally_2017
171 if DEFINED MSVC_VS_DIR call "%MSVC_VS_DIR%\Common7\Tools\VsDevCmd.bat"
172
173 :sanity_checks
174 REM Sanity Checks
175 where /Q msbuild
176 if %ERRORLEVEL% NEQ 0 (
177         if "%BUILD_VS_VER%"=="12" (
178                 rem vs12 not found, try vs14
179                 echo Visual Studio 2013 not found, trying Visual Studio 2015.
180                 set BUILD_VS_VER=14
181                 set BUILD_VS_YEAR=2015
182                 goto DetectMSVC
183         )       else    (
184                 echo Error: "MSBuild" command not in the PATH.
185                 echo You must have MSVC installed and run this from the "Developer Command Prompt"
186                 echo ^(available from Visual Studio's Start menu entry^), aborting!
187                 goto EOF
188         )
189 )
190
191
192 set BUILD_DIR=%BUILD_DIR%_%TARGET%_%BUILD_ARCH%_vc%BUILD_VS_VER%_%BUILD_TYPE%
193 if NOT "%BUILD_DIR_OVERRRIDE%"=="" (
194         set BUILD_DIR=%BUILD_DIR_OVERRRIDE%
195 )
196
197 where /Q cmake
198 if %ERRORLEVEL% NEQ 0 (
199         echo Error: "CMake" command not in the PATH.
200         echo You must have CMake installed and added to your PATH, aborting!
201         goto EOF
202 )
203 if NOT EXIST %BLENDER_DIR%..\lib\nul (
204         echo Error: Path to libraries not found "%BLENDER_DIR%..\lib\"
205         echo This is needed for building, aborting!
206         goto EOF
207 )
208 if "%TARGET%"=="" (
209         echo Error: Convenience target not set
210         echo This is required for building, aborting!
211         echo .
212         goto HELP
213 )
214
215 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -G "Visual Studio %BUILD_VS_VER% %BUILD_VS_YEAR%%WINDOWS_ARCH%" %TESTS_CMAKE_ARGS%
216 if NOT EXIST %BUILD_DIR%\nul (
217         mkdir %BUILD_DIR%
218 )
219 if "%MUST_CLEAN%"=="1" (
220                 echo Cleaning %BUILD_DIR%
221                 msbuild ^
222                         %BUILD_DIR%\Blender.sln ^
223                         /target:clean ^
224                         /property:Configuration=%BUILD_TYPE% ^
225                         /verbosity:minimal ^
226                         /p:platform=%MSBUILD_PLATFORM%
227
228                 if %ERRORLEVEL% NEQ 0 (
229                         echo Cleaned "%BUILD_DIR%"
230                 )
231                 goto EOF
232 )
233 REM Only configure on first run or when called with nobuild
234 if NOT EXIST %BUILD_DIR%\Blender.sln set MUST_CONFIGURE=1
235 if "%NOBUILD%"=="1" set MUST_CONFIGURE=1
236
237 if "%MUST_CONFIGURE%"=="1" (
238         cmake ^
239                 %BUILD_CMAKE_ARGS% ^
240                 -H%BLENDER_DIR% ^
241                 -B%BUILD_DIR% ^
242                 %BUILD_CMAKE_ARGS%
243
244         if %ERRORLEVEL% NEQ 0 (
245                 echo "Configuration Failed"
246                 goto EOF
247         )
248 )
249 if "%NOBUILD%"=="1" goto EOF
250
251 msbuild ^
252         %BUILD_DIR%\Blender.sln ^
253         /target:build ^
254         /property:Configuration=%BUILD_TYPE% ^
255         /maxcpucount ^
256         /verbosity:minimal ^
257         /p:platform=%MSBUILD_PLATFORM% ^
258         /flp:Summary;Verbosity=minimal;LogFile=%BUILD_DIR%\Build.log
259
260 if %ERRORLEVEL% NEQ 0 (
261         echo "Build Failed"
262         goto EOF
263 )
264
265 msbuild ^
266         %BUILD_DIR%\INSTALL.vcxproj ^
267         /property:Configuration=%BUILD_TYPE% ^
268         /verbosity:minimal ^
269         /p:platform=%MSBUILD_PLATFORM%
270
271 echo.
272 echo At any point you can optionally modify your build configuration by editing:
273 echo "%BUILD_DIR%\CMakeCache.txt", then run "make" again to build with the changes applied.
274 echo.
275 echo Blender successfully built, run from: "%BUILD_DIR%\bin\%BUILD_TYPE%\blender.exe"
276 echo.
277 goto EOF
278 :HELP
279                 echo.
280                 echo Convenience targets
281                 echo - release ^(identical to the official blender.org builds^)
282                 echo - full ^(same as release minus the cuda kernels^)
283                 echo - lite
284                 echo - headless
285                 echo - cycles
286                 echo - bpy
287                 echo.
288                 echo Utilities ^(not associated with building^)
289                 echo - clean ^(Target must be set^)
290                 echo - update
291                 echo - nobuild ^(only generate project files^)
292                 echo - showhash ^(Show git hashes of source tree^)
293                 echo.
294                 echo Configuration options
295                 echo - with_tests ^(enable building unit tests^)
296                 echo - debug ^(Build an unoptimized debuggable build^)
297                 echo - packagename [newname] ^(override default cpack package name^)
298                 echo - buildir [newdir] ^(override default build folder^)
299                 echo - x86 ^(override host auto-detect and build 32 bit code^)
300                 echo - x64 ^(override host auto-detect and build 64 bit code^)
301                 echo - 2013 ^(build with visual studio 2013^)
302                 echo - 2015 ^(build with visual studio 2015^) [EXPERIMENTAL]
303                 echo.
304
305 :EOF