make.bat 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. setlocal EnableDelayedExpansion
  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_DIR_OVERRRIDE=
  16. set BUILD_CMAKE_ARGS=
  17. set BUILD_ARCH=
  18. set BUILD_VS_VER=
  19. set BUILD_VS_YEAR=
  20. set BUILD_NGE=
  21. set KEY_NAME=
  22. set MSBUILD_PLATFORM=
  23. set MUST_CLEAN=
  24. set NOBUILD=
  25. set TARGET=
  26. set WINDOWS_ARCH=
  27. set TESTS_CMAKE_ARGS=
  28. :argv_loop
  29. if NOT "%1" == "" (
  30. REM Help Message
  31. if "%1" == "help" (
  32. goto HELP
  33. )
  34. REM Build Types
  35. if "%1" == "debug" (
  36. set BUILD_TYPE=Debug
  37. REM Build Configurations
  38. ) else if "%1" == "noge" (
  39. set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -DWITH_GAMEENGINE=OFF -DWITH_PLAYER=OFF
  40. set BUILD_NGE=_noge
  41. ) else if "%1" == "builddir" (
  42. set BUILD_DIR_OVERRRIDE="%BLENDER_DIR%..\%2"
  43. shift /1
  44. ) else if "%1" == "with_tests" (
  45. set TESTS_CMAKE_ARGS=-DWITH_GTESTS=On
  46. ) else if "%1" == "full" (
  47. set TARGET=Full
  48. set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
  49. -C"%BLENDER_DIR%\build_files\cmake\config\blender_full.cmake"
  50. ) else if "%1" == "lite" (
  51. set TARGET=Lite
  52. set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
  53. -C"%BLENDER_DIR%\build_files\cmake\config\blender_lite.cmake"
  54. ) else if "%1" == "cycles" (
  55. set TARGET=Cycles
  56. set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
  57. -C"%BLENDER_DIR%\build_files\cmake\config\cycles_standalone.cmake"
  58. ) else if "%1" == "headless" (
  59. set TARGET=Headless
  60. set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
  61. -C"%BLENDER_DIR%\build_files\cmake\config\blender_headless.cmake"
  62. ) else if "%1" == "bpy" (
  63. set TARGET=Bpy
  64. set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
  65. -C"%BLENDER_DIR%\build_files\cmake\config\bpy_module.cmake"
  66. ) else if "%1" == "release" (
  67. set TARGET=Release
  68. ) else if "%1" == "x86" (
  69. set BUILD_ARCH=x86
  70. ) else if "%1" == "x64" (
  71. set BUILD_ARCH=x64
  72. ) else if "%1" == "2017" (
  73. set BUILD_VS_VER=15
  74. set BUILD_VS_YEAR=2017
  75. ) else if "%1" == "2015" (
  76. set BUILD_VS_VER=14
  77. set BUILD_VS_YEAR=2015
  78. ) else if "%1" == "2013" (
  79. set BUILD_VS_VER=12
  80. set BUILD_VS_YEAR=2013
  81. ) else if "%1" == "packagename" (
  82. set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -DCPACK_OVERRIDE_PACKAGENAME="%2"
  83. shift /1
  84. ) else if "%1" == "nobuild" (
  85. set NOBUILD=1
  86. ) else if "%1" == "showhash" (
  87. for /f "delims=" %%i in ('git rev-parse HEAD') do echo Branch_hash=%%i
  88. cd release/datafiles/locale
  89. for /f "delims=" %%i in ('git rev-parse HEAD') do echo Locale_hash=%%i
  90. cd %~dp0
  91. cd release/scripts/addons
  92. for /f "delims=" %%i in ('git rev-parse HEAD') do echo Addons_Hash=%%i
  93. cd %~dp0
  94. goto EOF
  95. REM Non-Build Commands
  96. ) else if "%1" == "update" (
  97. svn up ../lib/*
  98. git pull --rebase
  99. git submodule foreach git pull --rebase origin master
  100. goto EOF
  101. ) else if "%1" == "clean" (
  102. set MUST_CLEAN=1
  103. ) else (
  104. echo Command "%1" unknown, aborting!
  105. goto EOF
  106. )
  107. shift /1
  108. goto argv_loop
  109. )
  110. if "%BUILD_ARCH%"=="" (
  111. if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
  112. set WINDOWS_ARCH= Win64
  113. set BUILD_ARCH=x64
  114. ) else if "%PROCESSOR_ARCHITEW6432%" == "AMD64" (
  115. set WINDOWS_ARCH= Win64
  116. set BUILD_ARCH=x64
  117. ) else (
  118. set WINDOWS_ARCH=
  119. set BUILD_ARCH=x86
  120. )
  121. ) else if "%BUILD_ARCH%"=="x64" (
  122. set WINDOWS_ARCH= Win64
  123. ) else if "%BUILD_ARCH%"=="x86" (
  124. set WINDOWS_ARCH=
  125. )
  126. if "%BUILD_VS_VER%"=="" (
  127. set BUILD_VS_VER=12
  128. set BUILD_VS_YEAR=2013
  129. )
  130. if "%BUILD_ARCH%"=="x64" (
  131. set MSBUILD_PLATFORM=x64
  132. ) else if "%BUILD_ARCH%"=="x86" (
  133. set MSBUILD_PLATFORM=win32
  134. )
  135. if "%target%"=="Release" (
  136. rem for vc12 check for both cuda 7.5 and 8
  137. if "%CUDA_PATH%"=="" (
  138. echo Cuda Not found, aborting!
  139. goto EOF
  140. )
  141. set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% ^
  142. -C"%BLENDER_DIR%\build_files\cmake\config\blender_release.cmake"
  143. )
  144. :DetectMSVC
  145. REM Detect MSVC Installation for 2013-2015
  146. if DEFINED VisualStudioVersion goto msvc_detect_finally
  147. set VALUE_NAME=ProductDir
  148. REM Check 64 bits
  149. set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\%BUILD_VS_VER%.0\Setup\VC"
  150. 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
  151. if DEFINED MSVC_VC_DIR goto msvc_detect_finally
  152. REM Check 32 bits
  153. set KEY_NAME="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\%BUILD_VS_VER%.0\Setup\VC"
  154. 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
  155. if DEFINED MSVC_VC_DIR goto msvc_detect_finally
  156. :msvc_detect_finally
  157. if DEFINED MSVC_VC_DIR call "%MSVC_VC_DIR%\vcvarsall.bat"
  158. if DEFINED MSVC_VC_DIR goto sanity_checks
  159. rem MSVC Build environment 2017 and up.
  160. for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SXS\VS7" /v %BUILD_VS_VER%.0 2^>nul`) DO set MSVC_VS_DIR=%%C
  161. if DEFINED MSVC_VS_DIR goto msvc_detect_finally_2017
  162. REM Check 32 bits
  163. for /F "usebackq skip=2 tokens=1-2*" %%A IN (`REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\sxs\vs7" /v %BUILD_VS_VER%.0 2^>nul`) DO set MSVC_VS_DIR=%%C
  164. if DEFINED MSVC_VS_DIR goto msvc_detect_finally_2017
  165. :msvc_detect_finally_2017
  166. if DEFINED MSVC_VS_DIR call "%MSVC_VS_DIR%\Common7\Tools\VsDevCmd.bat"
  167. :sanity_checks
  168. REM Sanity Checks
  169. where /Q msbuild
  170. if %ERRORLEVEL% NEQ 0 (
  171. if "%BUILD_VS_VER%"=="12" (
  172. rem vs12 not found, try vs14
  173. echo Visual Studio 2013 not found, trying Visual Studio 2015.
  174. set BUILD_VS_VER=14
  175. set BUILD_VS_YEAR=2015
  176. goto DetectMSVC
  177. ) else (
  178. echo Error: "MSBuild" command not in the PATH.
  179. echo You must have MSVC installed and run this from the "Developer Command Prompt"
  180. echo ^(available from Visual Studio's Start menu entry^), aborting!
  181. goto EOF
  182. )
  183. )
  184. set BUILD_DIR=%BUILD_DIR%_%TARGET%%BUILD_NGE%_%BUILD_ARCH%_vc%BUILD_VS_VER%_%BUILD_TYPE%
  185. if NOT "%BUILD_DIR_OVERRRIDE%"=="" (
  186. set BUILD_DIR=%BUILD_DIR_OVERRRIDE%
  187. )
  188. where /Q cmake
  189. if %ERRORLEVEL% NEQ 0 (
  190. echo Error: "CMake" command not in the PATH.
  191. echo You must have CMake installed and added to your PATH, aborting!
  192. goto EOF
  193. )
  194. if NOT EXIST %BLENDER_DIR%..\lib\nul (
  195. echo Error: Path to libraries not found "%BLENDER_DIR%..\lib\"
  196. echo This is needed for building, aborting!
  197. goto EOF
  198. )
  199. if "%TARGET%"=="" (
  200. echo Error: Convenience target not set
  201. echo This is required for building, aborting!
  202. echo .
  203. goto HELP
  204. )
  205. set BUILD_CMAKE_ARGS=%BUILD_CMAKE_ARGS% -G "Visual Studio %BUILD_VS_VER% %BUILD_VS_YEAR%%WINDOWS_ARCH%" %TESTS_CMAKE_ARGS%
  206. if NOT EXIST %BUILD_DIR%\nul (
  207. mkdir %BUILD_DIR%
  208. )
  209. if "%MUST_CLEAN%"=="1" (
  210. echo Cleaning %BUILD_DIR%
  211. msbuild ^
  212. %BUILD_DIR%\Blender.sln ^
  213. /target:clean ^
  214. /property:Configuration=%BUILD_TYPE% ^
  215. /verbosity:minimal ^
  216. /p:platform=%MSBUILD_PLATFORM%
  217. if %ERRORLEVEL% NEQ 0 (
  218. echo Cleaned "%BUILD_DIR%"
  219. )
  220. goto EOF
  221. )
  222. REM Only configure on first run or when called with nobuild
  223. if NOT EXIST %BUILD_DIR%\Blender.sln set MUST_CONFIGURE=1
  224. if "%NOBUILD%"=="1" set MUST_CONFIGURE=1
  225. if "%MUST_CONFIGURE%"=="1" (
  226. cmake ^
  227. %BUILD_CMAKE_ARGS% ^
  228. -H%BLENDER_DIR% ^
  229. -B%BUILD_DIR% ^
  230. %BUILD_CMAKE_ARGS%
  231. if %ERRORLEVEL% NEQ 0 (
  232. echo "Configuration Failed"
  233. goto EOF
  234. )
  235. )
  236. if DEFINED MSVC_VC_DIR echo call "%MSVC_VC_DIR%\vcvarsall.bat" > %BUILD_DIR%\rebuild.cmd
  237. if DEFINED MSVC_VS_DIR echo call "%MSVC_VS_DIR%\Common7\Tools\VsDevCmd.bat" > %BUILD_DIR%\rebuild.cmd
  238. echo cmake . >> %BUILD_DIR%\rebuild.cmd
  239. echo msbuild ^
  240. %BUILD_DIR%\Blender.sln ^
  241. /target:build ^
  242. /property:Configuration=%BUILD_TYPE% ^
  243. /maxcpucount:2 ^
  244. /verbosity:minimal ^
  245. /p:platform=%MSBUILD_PLATFORM% ^
  246. /flp:Summary;Verbosity=minimal;LogFile=%BUILD_DIR%\Build.log >> %BUILD_DIR%\rebuild.cmd
  247. echo msbuild ^
  248. %BUILD_DIR%\INSTALL.vcxproj ^
  249. /property:Configuration=%BUILD_TYPE% ^
  250. /verbosity:minimal ^
  251. /p:platform=%MSBUILD_PLATFORM% >> %BUILD_DIR%\rebuild.cmd
  252. if "%NOBUILD%"=="1" goto EOF
  253. msbuild ^
  254. %BUILD_DIR%\Blender.sln ^
  255. /target:build ^
  256. /property:Configuration=%BUILD_TYPE% ^
  257. /maxcpucount:2 ^
  258. /verbosity:minimal ^
  259. /p:platform=%MSBUILD_PLATFORM% ^
  260. /flp:Summary;Verbosity=minimal;LogFile=%BUILD_DIR%\Build.log
  261. if %ERRORLEVEL% NEQ 0 (
  262. echo "Build Failed"
  263. goto EOF
  264. )
  265. msbuild ^
  266. %BUILD_DIR%\INSTALL.vcxproj ^
  267. /property:Configuration=%BUILD_TYPE% ^
  268. /verbosity:minimal ^
  269. /p:platform=%MSBUILD_PLATFORM%
  270. echo.
  271. echo At any point you can optionally modify your build configuration by editing:
  272. echo "%BUILD_DIR%\CMakeCache.txt", then run "rebuild.cmd" in the build folder to build with the changes applied.
  273. echo.
  274. echo Blender successfully built, run from: "%BUILD_DIR%\bin\%BUILD_TYPE%\blender.exe"
  275. echo.
  276. goto EOF
  277. :HELP
  278. echo.
  279. echo Convenience targets
  280. echo - release ^(identical to the official blender.org builds^)
  281. echo - full ^(same as release minus the cuda kernels^)
  282. echo - lite
  283. echo - headless
  284. echo - cycles
  285. echo - bpy
  286. echo.
  287. echo Utilities ^(not associated with building^)
  288. echo - clean ^(Target must be set^)
  289. echo - update
  290. echo - nobuild ^(only generate project files^)
  291. echo - showhash ^(Show git hashes of source tree^)
  292. echo.
  293. echo Configuration options
  294. echo - with_tests ^(enable building unit tests^)
  295. echo - noge ^(disable building game enginge and player^)
  296. echo - debug ^(Build an unoptimized debuggable build^)
  297. echo - packagename [newname] ^(override default cpack package name^)
  298. echo - buildir [newdir] ^(override default build folder^)
  299. echo - x86 ^(override host auto-detect and build 32 bit code^)
  300. echo - x64 ^(override host auto-detect and build 64 bit code^)
  301. echo - 2013 ^(build with visual studio 2013^)
  302. echo - 2015 ^(build with visual studio 2015^) [EXPERIMENTAL]
  303. echo.
  304. :EOF