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