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