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