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