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