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