Merge branch 'master' into blender2.8
[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 set BUILD_DIR=%BUILD_DIR%_%TARGET%_%BUILD_ARCH%_vc%BUILD_VS_VER%_%BUILD_TYPE%
133
134
135 if "%target%"=="Release" (
136                 rem for vc12 check for both cuda 7.5 and 8 
137                 if "%CUDA_PATH%"=="" (
138                         echo Cuda Not found, aborting!
139                         goto EOF
140                 )
141                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
142                 -C"%BLENDER_DIR%\build_files\cmake\config\blender_release.cmake" 
143 )
144
145 :DetectMSVC
146 REM Detect MSVC Installation for 2013-2015
147 if DEFINED VisualStudioVersion goto msvc_detect_finally
148 set VALUE_NAME=ProductDir
149 REM Check 64 bits
150 set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\%BUILD_VS_VER%.0\Setup\VC"
151 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
152 if DEFINED MSVC_VC_DIR goto msvc_detect_finally
153 REM Check 32 bits
154 set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\%BUILD_VS_VER%.0\Setup\VC"
155 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
156 if DEFINED MSVC_VC_DIR goto msvc_detect_finally
157 :msvc_detect_finally
158 if DEFINED MSVC_VC_DIR call "%MSVC_VC_DIR%\vcvarsall.bat"
159 if DEFINED MSVC_VC_DIR goto sanity_checks
160
161 rem MSVC Build environment 2017 and up. 
162 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
163 if DEFINED MSVC_VS_DIR goto msvc_detect_finally_2017
164 REM Check 32 bits
165 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
166 if DEFINED MSVC_VS_DIR goto msvc_detect_finally_2017
167 :msvc_detect_finally_2017
168 if DEFINED MSVC_VS_DIR call "%MSVC_VS_DIR%\Common7\Tools\VsDevCmd.bat"
169
170 :sanity_checks
171 REM Sanity Checks
172 where /Q msbuild
173 if %ERRORLEVEL% NEQ 0 (
174         if "%BUILD_VS_VER%"=="12" (
175                 rem vs12 not found, try vs14
176                 echo Visual Studio 2012 not found, trying Visual Studio 2015.
177                 set BUILD_VS_VER=14
178                 set BUILD_VS_YEAR=2015
179                 goto DetectMSVC
180         )       else    (
181                 echo Error: "MSBuild" command not in the PATH.
182                 echo You must have MSVC installed and run this from the "Developer Command Prompt"
183                 echo ^(available from Visual Studio's Start menu entry^), aborting!
184                 goto EOF
185         )
186 )
187 where /Q cmake
188 if %ERRORLEVEL% NEQ 0 (
189         echo Error: "CMake" command not in the PATH.
190         echo You must have CMake installed and added to your PATH, aborting!
191         goto EOF
192 )
193 if NOT EXIST %BLENDER_DIR%..\lib\nul (
194         echo Error: Path to libraries not found "%BLENDER_DIR%..\lib\"
195         echo This is needed for building, aborting!
196         goto EOF
197 )
198 if "%TARGET%"=="" (
199         echo Error: Convenience target not set
200         echo This is required for building, aborting!
201         echo . 
202         goto HELP
203 )
204
205 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -G "Visual Studio %BUILD_VS_VER% %BUILD_VS_YEAR%%WINDOWS_ARCH%"
206 if NOT EXIST %BUILD_DIR%\nul (
207         mkdir %BUILD_DIR%
208 )
209 if "%MUST_CLEAN%"=="1" (
210                 echo Cleaning %BUILD_DIR%
211                 msbuild ^
212                         %BUILD_DIR%\Blender.sln ^
213                         /target:clean ^
214                         /property:Configuration=%BUILD_TYPE% ^
215                         /verbosity:minimal ^
216                         /p:platform=%MSBUILD_PLATFORM%
217
218                 if %ERRORLEVEL% NEQ 0 (
219                         echo Cleaned "%BUILD_DIR%"
220                 )
221                 goto EOF
222 )
223 REM Only configure on first run or when called with nobuild
224 if NOT EXIST %BUILD_DIR%\Blender.sln set MUST_CONFIGURE=1
225 if "%NOBUILD%"=="1" set MUST_CONFIGURE=1
226
227 if "%MUST_CONFIGURE%"=="1" (
228         cmake ^
229                 %BUILD_CMAKE_ARGS% ^
230                 -H%BLENDER_DIR% ^
231                 -B%BUILD_DIR% ^
232                 %BUILD_CMAKE_ARGS%
233
234         if %ERRORLEVEL% NEQ 0 (
235                 echo "Configuration Failed"
236                 goto EOF
237         )
238 )
239 if "%NOBUILD%"=="1" goto EOF
240
241 msbuild ^
242         %BUILD_DIR%\Blender.sln ^
243         /target:build ^
244         /property:Configuration=%BUILD_TYPE% ^
245         /maxcpucount ^
246         /verbosity:minimal ^
247         /p:platform=%MSBUILD_PLATFORM% ^
248         /flp:Summary;Verbosity=minimal;LogFile=%BUILD_DIR%\Build.log
249
250 if %ERRORLEVEL% NEQ 0 (
251         echo "Build Failed"
252         goto EOF
253 )
254
255 msbuild ^
256         %BUILD_DIR%\INSTALL.vcxproj ^
257         /property:Configuration=%BUILD_TYPE% ^
258         /verbosity:minimal ^
259         /p:platform=%MSBUILD_PLATFORM%
260
261 echo.
262 echo At any point you can optionally modify your build configuration by editing:
263 echo "%BUILD_DIR%\CMakeCache.txt", then run "make" again to build with the changes applied.
264 echo.
265 echo Blender successfully built, run from: "%BUILD_DIR%\bin\%BUILD_TYPE%"
266 echo.
267 goto EOF
268 :HELP
269                 echo.
270                 echo Convenience targets
271                 echo - release ^(identical to the offical blender.org builds^)
272                 echo - full ^(same as release minus the cuda kernels^)
273                 echo - lite 
274                 echo - headless
275                 echo - cycles
276                 echo - bpy
277                 echo.
278                 echo Utilities ^(not associated with building^)
279                 echo - clean ^(Target must be set^)
280                 echo - update
281                 echo - nobuild ^(only generate project files^)
282                 echo - showhash ^(Show git hashes of source tree^)
283                 echo.
284                 echo Configuration options
285                 echo - debug ^(Build an unoptimized debuggable build^)
286                 echo - packagename [newname] ^(override default cpack package name^)
287                 echo - x86 ^(override host autodetect and build 32 bit code^)
288                 echo - x64 ^(override host autodetect and build 64 bit code^)
289                 echo - 2013 ^(build with visual studio 2013^)
290                 echo - 2015 ^(build with visual studio 2015^) [EXPERIMENTAL]
291                 echo.
292
293 :EOF
294