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