make.bat: detect MSVC location
[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 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 - update
63                 goto EOF
64         )
65
66         REM Build Types
67         if "%1" == "debug" (
68                 set BUILD_DIR=%BUILD_DIR%_debug
69                 set BUILD_TYPE=Debug
70
71         REM Build Configurations
72         ) else if "%1" == "full" (
73                 set BUILD_DIR=%BUILD_DIR%_full
74                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
75                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_full.cmake"
76         ) else if "%1" == "lite" (
77                 set BUILD_DIR=%BUILD_DIR%_lite
78                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
79                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_lite.cmake"
80         ) else if "%1" == "cycles" (
81                 set BUILD_DIR=%BUILD_DIR%_cycles
82                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
83                     -C"%BLENDER_DIR%\build_files\cmake\config\cycles_standalone.cmake"
84         ) else if "%1" == "headless" (
85                 set BUILD_DIR=%BUILD_DIR%_headless
86                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
87                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_headless.cmake"
88         ) else if "%1" == "bpy" (
89                 set BUILD_DIR=%BUILD_DIR%_bpy
90                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
91                     -C"%BLENDER_DIR%\build_files\cmake\config\bpy_module.cmake"
92
93         REM Non-Build Commands
94         ) else if "%1" == "update" (
95                 svn up ../lib/*
96                 git pull --rebase
97                 git submodule foreach git pull --rebase origin master
98                 goto EOF
99         ) else (
100                 echo Command "%1" unknown, aborting!
101                 goto EOF
102         )
103
104         shift /1
105         goto argv_loop
106 )
107
108 if "%PROCESSOR_ARCHITECTURE%" == "x86" (
109         set WINDOWS_ARCH=
110 ) else (
111         set WINDOWS_ARCH=Win64
112 )
113
114 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -G "Visual Studio 12 2013 %WINDOWS_ARCH%"
115 if NOT EXIST %BUILD_DIR%\nul (
116         mkdir %BUILD_DIR%
117 )
118
119 cmake ^
120         %BUILD_CMAKE_ARGS% ^
121         -H%BLENDER_DIR% ^
122         -B%BUILD_DIR% ^
123         %BUILD_CMAKE_ARGS%
124
125 if %ERRORLEVEL% NEQ 0 (
126         echo "Configuration Failed"
127         goto EOF
128 )
129
130 msbuild ^
131         %BUILD_DIR%\Blender.sln ^
132         /target:build ^
133         /property:Configuration=%BUILD_TYPE% ^
134         /maxcpucount ^
135         /verbosity:minimal
136
137 if %ERRORLEVEL% NEQ 0 (
138         echo "Build Failed"
139         goto EOF
140 )
141
142 msbuild ^
143         %BUILD_DIR%\INSTALL.vcxproj ^
144         /property:Configuration=%BUILD_TYPE% ^
145         /verbosity:minimal
146
147 echo.
148 echo Your build is complete at: "%BUILD_DIR%\bin\%BUILD_TYPE%"
149 echo.
150
151 :EOF
152