make.bat: sanity checks w/ useful error messages
[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 set BLENDER_DIR=%~dp0
6 set BUILD_DIR=%BLENDER_DIR%..\build_windows
7 set BUILD_TYPE=Release
8 set BUILD_CMAKE_ARGS=
9
10 REM Sanity Checks
11 where /Q msbuild
12 if %ERRORLEVEL% NEQ 0 (
13         echo Error: "MSBuild" command not in the PATH.
14         echo You must have MSVC installed and run this from the "Developer Command Prompt"
15         echo ^(available from Visual Studio's Start menu entry^), aborting!
16         goto EOF
17 )
18 where /Q cmake
19 if %ERRORLEVEL% NEQ 0 (
20         echo Error: "CMake" command not in the PATH.
21         echo You must have CMake installed and added to your PATH, aborting!
22         goto EOF
23 )
24 if NOT EXIST %BLENDER_DIR%..\lib\nul (
25         echo Error: Path to libraries not found "%BLENDER_DIR%..\lib\"
26         echo This is needed for building, aborting!
27         goto EOF
28 )
29
30
31 :argv_loop
32 if NOT "%1" == "" (
33
34         REM Help Message
35         if "%1" == "--help" (
36                 echo.
37                 echo Convenience targets
38                 echo - debug
39                 echo - full
40                 echo - lite
41                 echo - headless
42                 echo - cycles
43                 echo - bpy
44                 echo.
45                 echo Utilities ^(not associated with building^)
46                 echo - update
47                 goto EOF
48         )
49
50         REM Build Types
51         if "%1" == "debug" (
52                 set BUILD_DIR=%BUILD_DIR%_debug
53                 set BUILD_TYPE=Debug
54
55         REM Build Configurations
56         ) else if "%1" == "full" (
57                 set BUILD_DIR=%BUILD_DIR%_full
58                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
59                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_full.cmake"
60         ) else if "%1" == "lite" (
61                 set BUILD_DIR=%BUILD_DIR%_lite
62                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
63                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_lite.cmake"
64         ) else if "%1" == "cycles" (
65                 set BUILD_DIR=%BUILD_DIR%_cycles
66                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
67                     -C"%BLENDER_DIR%\build_files\cmake\config\cycles_standalone.cmake"
68         ) else if "%1" == "headless" (
69                 set BUILD_DIR=%BUILD_DIR%_headless
70                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
71                     -C"%BLENDER_DIR%\build_files\cmake\config\blender_headless.cmake"
72         ) else if "%1" == "bpy" (
73                 set BUILD_DIR=%BUILD_DIR%_bpy
74                 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
75                     -C"%BLENDER_DIR%\build_files\cmake\config\bpy_module.cmake"
76
77         REM Non-Build Commands
78         ) else if "%1" == "update" (
79                 svn up ../lib/*
80                 git pull --rebase
81                 git submodule foreach git pull --rebase origin master
82                 goto EOF
83         ) else (
84                 echo Command "%1" unknown, aborting!
85                 goto EOF
86         )
87
88         shift /1
89         goto argv_loop
90 )
91
92 if "%PROCESSOR_ARCHITECTURE%" == "x86" (
93         set WINDOWS_ARCH=
94 ) else (
95         set WINDOWS_ARCH=Win64
96 )
97
98 set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -G "Visual Studio 12 2013 %WINDOWS_ARCH%"
99 if NOT EXIST %BUILD_DIR%\nul (
100         mkdir %BUILD_DIR%
101 )
102
103 cmake ^
104         %BUILD_CMAKE_ARGS% ^
105         -H%BLENDER_DIR% ^
106         -B%BUILD_DIR% ^
107         %BUILD_CMAKE_ARGS%
108
109 if %ERRORLEVEL% NEQ 0 (
110         echo "Configuration Failed"
111         goto EOF
112 )
113
114 msbuild ^
115         %BUILD_DIR%\Blender.sln ^
116         /target:build ^
117         /property:Configuration=%BUILD_TYPE% ^
118         /maxcpucount ^
119         /verbosity:minimal
120
121 if %ERRORLEVEL% NEQ 0 (
122         echo "Build Failed"
123         goto EOF
124 )
125
126 msbuild ^
127         %BUILD_DIR%\INSTALL.vcxproj ^
128         /property:Configuration=%BUILD_TYPE% ^
129         /verbosity:minimal
130
131 echo.
132 echo Your build is complete at: "%BUILD_DIR%\bin\%BUILD_TYPE%"
133 echo.
134
135 :EOF
136