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