Fix make.bat checking 64bit systems
[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 set BUILD_CMAKE_ARGS=
10
11 REM Detect MSVC Installation
12 if DEFINED VisualStudioVersion goto msvc_detect_finally
13 set VALUE_NAME=ProductDir
14 REM Check 64 bits
15 set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0\Setup\VC"
16 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
17 if DEFINED MSVC_VC_DIR goto msvc_detect_finally
18 REM Check 32 bits
19 set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\12.0\Setup\VC"
20 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
21 if DEFINED MSVC_VC_DIR goto msvc_detect_finally
22 :msvc_detect_finally
23 if DEFINED MSVC_VC_DIR call "%MSVC_VC_DIR%\vcvarsall.bat"
24
25
26 REM Sanity Checks
27 where /Q msbuild
28 if %ERRORLEVEL% NEQ 0 (
29         echo Error: "MSBuild" command not in the PATH.
30         echo You must have MSVC installed and run this from the "Developer Command Prompt"
31         echo ^(available from Visual Studio's Start menu entry^), aborting!
32         goto EOF
33 )
34 where /Q cmake
35 if %ERRORLEVEL% NEQ 0 (
36         echo Error: "CMake" command not in the PATH.
37         echo You must have CMake installed and added to your PATH, aborting!
38         goto EOF
39 )
40 if NOT EXIST %BLENDER_DIR%..\lib\nul (
41         echo Error: Path to libraries not found "%BLENDER_DIR%..\lib\"
42         echo This is needed for building, aborting!
43         goto EOF
44 )
45
46
47 :argv_loop
48 if NOT "%1" == "" (
49
50         REM Help Message
51         if "%1" == "help" (
52                 echo.
53                 echo Convenience targets
54                 echo - debug
55                 echo - full
56                 echo - lite
57                 echo - headless
58                 echo - cycles
59                 echo - bpy
60                 echo.
61                 echo Utilities ^(not associated with building^)
62                 echo - clean
63                 echo - update
64                 goto EOF
65         )
66
67         REM Build Types
68         if "%1" == "debug" (
69                 set BUILD_DIR=%BUILD_DIR%_debug
70                 set BUILD_TYPE=Debug
71
72         REM Build Configurations
73         ) else if "%1" == "full" (
74                 set BUILD_DIR=%BUILD_DIR%_full
75                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
76                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_full.cmake"
77         ) else if "%1" == "lite" (
78                 set BUILD_DIR=%BUILD_DIR%_lite
79                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
80                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_lite.cmake"
81         ) else if "%1" == "cycles" (
82                 set BUILD_DIR=%BUILD_DIR%_cycles
83                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
84                     -C"%BLENDER_DIR%\build_files\cmake\config\cycles_standalone.cmake"
85         ) else if "%1" == "headless" (
86                 set BUILD_DIR=%BUILD_DIR%_headless
87                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
88                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_headless.cmake"
89         ) else if "%1" == "bpy" (
90                 set BUILD_DIR=%BUILD_DIR%_bpy
91                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
92                     -C"%BLENDER_DIR%\build_files\cmake\config\bpy_module.cmake"
93
94         REM Non-Build Commands
95         ) else if "%1" == "update" (
96                 svn up ../lib/*
97                 git pull --rebase
98                 git submodule foreach git pull --rebase origin master
99                 goto EOF
100         ) else if "%1" == "clean" (
101                 msbuild ^
102                         %BUILD_DIR%\Blender.sln ^
103                         /target:clean ^
104                         /property:Configuration=%BUILD_TYPE% ^
105                         /verbosity:minimal
106                 if %ERRORLEVEL% NEQ 0 (
107                         echo Cleaned "%BUILD_DIR%"
108                 )
109                 goto EOF
110         ) else (
111                 echo Command "%1" unknown, aborting!
112                 goto EOF
113         )
114
115         shift /1
116         goto argv_loop
117 )
118
119 if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
120         set WINDOWS_ARCH=Win64
121 ) else if "%PROCESSOR_ARCHITEW6432%" == "AMD64" (
122         set WINDOWS_ARCH=Win64
123 ) else (
124         set WINDOWS_ARCH=
125 )
126
127 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -G "Visual Studio 12 2013 %WINDOWS_ARCH%"
128 if NOT EXIST %BUILD_DIR%\nul (
129         mkdir %BUILD_DIR%
130 )
131
132 REM Only configure on first run
133 if NOT EXIST %BUILD_DIR%\Blender.sln (
134         cmake ^
135                 %BUILD_CMAKE_ARGS% ^
136                 -H%BLENDER_DIR% ^
137                 -B%BUILD_DIR% ^
138                 %BUILD_CMAKE_ARGS%
139
140         if %ERRORLEVEL% NEQ 0 (
141                 echo "Configuration Failed"
142                 goto EOF
143         )
144 )
145
146 msbuild ^
147         %BUILD_DIR%\Blender.sln ^
148         /target:build ^
149         /property:Configuration=%BUILD_TYPE% ^
150         /maxcpucount ^
151         /verbosity:minimal
152
153 if %ERRORLEVEL% NEQ 0 (
154         echo "Build Failed"
155         goto EOF
156 )
157
158 msbuild ^
159         %BUILD_DIR%\INSTALL.vcxproj ^
160         /property:Configuration=%BUILD_TYPE% ^
161         /verbosity:minimal
162
163 echo.
164 echo At any point you can optionally modify your build configuration by editing:
165 echo "%BUILD_DIR%\CMakeCache.txt", then run "make" again to build with the changes applied.
166 echo.
167 echo Blender successfully built, run from: "%BUILD_DIR%\bin\%BUILD_TYPE%"
168 echo.
169
170 :EOF
171