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