hctbuild.cmd 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. @echo off
  2. if "%1"=="/?" goto :showhelp
  3. if "%1"=="-?" goto :showhelp
  4. if "%1"=="-help" goto :showhelp
  5. if "%1"=="--help" goto :showhelp
  6. setlocal
  7. if "%HLSL_SRC_DIR%"=="" (
  8. echo Missing source directory.
  9. if exist %~dp0..\..\LLVMBuild.txt (
  10. set HLSL_SRC_DIR=%~dp0..\..
  11. echo Source directory deduced to be %~dp0..\..
  12. ) else (
  13. exit /b 1
  14. )
  15. )
  16. if "%1"=="/buildoutdir" (
  17. echo Build output directory set to %2
  18. set HLSL_BLD_DIR=%2
  19. shift /1
  20. shift /1
  21. )
  22. if "%HLSL_BLD_DIR%"=="" (
  23. echo Missing build directory.
  24. exit /b 1
  25. )
  26. where cmake.exe 1>nul 2>nul
  27. if errorlevel 1 (
  28. echo Unable to find cmake.exe on the path.
  29. echo cmake 3.4 is available from https://cmake.org/files/v3.4/cmake-3.4.0-win32-x86.exe
  30. exit /b 1
  31. )
  32. if "%BUILD_ARCH%"=="" (
  33. set BUILD_ARCH=Win32
  34. )
  35. set BUILD_GENERATOR=Visual Studio 14 2015
  36. set BUILD_VS_VER=2015
  37. set BUILD_CONFIG=Debug
  38. set DO_SETUP=1
  39. set DO_BUILD=1
  40. set CMAKE_OPTS=
  41. if "%1"=="-s" (
  42. set DO_BUILD=0
  43. shift /1
  44. )
  45. if "%1"=="-b" (
  46. set DO_SETUP=0
  47. shift /1
  48. )
  49. if "%1"=="-alldef" (
  50. set CMAKE_OPTS=-DHLSL_OPTIONAL_PROJS_IN_DEFAULT:BOOL=ON
  51. shift /1
  52. )
  53. if "%1"=="-analyze" (
  54. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_ENABLE_ANALYZE:BOOL=ON
  55. shift /1
  56. )
  57. if "%1"=="-fv" (
  58. echo Fixed version flag set for build.
  59. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_ENABLE_FIXED_VER:BOOL=ON
  60. shift /1
  61. )
  62. if "%1"=="-cv" (
  63. echo Set the CLANG_VENDOR value.
  64. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_VENDOR:STRING=%2
  65. shift /1
  66. shift /1
  67. )
  68. if "%1"=="-rel" (
  69. set BUILD_CONFIG=Release
  70. shift /1
  71. )
  72. if "%1"=="-x86" (
  73. set BUILD_ARCH=Win32
  74. shift /1
  75. )
  76. if "%1"=="-x64" (
  77. set BUILD_ARCH=x64
  78. shift /1
  79. )
  80. if "%1"=="-arm" (
  81. set BUILD_ARCH=ARM
  82. shift /1
  83. )
  84. if "%1"=="-Debug" (
  85. set BUILD_CONFIG=Debug
  86. shift /1
  87. )
  88. if "%1"=="-Release" (
  89. set BUILD_CONFIG=Release
  90. shift /1
  91. )
  92. if "%1"=="-vs2017" (
  93. set BUILD_GENERATOR=Visual Studio 15 2017
  94. set BUILD_VS_VER=2017
  95. shift /1
  96. )
  97. rem If only VS 2017 is available, pick that by default.
  98. if "%BUILD_VS_VER%"=="2015" (
  99. reg query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DevDiv\vs\Servicing\14.0\devenv /v Install /reg:32 1>nul 2>nul
  100. if errorlevel 1 (
  101. echo Visual Studio 2015 not available, setting up build for Visual Studio 2017.
  102. set BUILD_GENERATOR=Visual Studio 15 2017
  103. set BUILD_VS_VER=2017
  104. )
  105. )
  106. rem Begin SPIRV change
  107. if "%1"=="-spirv" (
  108. echo SPIR-V codegen is enabled.
  109. set CMAKE_OPTS=%CMAKE_OPTS% -DENABLE_SPIRV_CODEGEN:BOOL=ON
  110. shift /1
  111. )
  112. if "%1"=="-spirvtest" (
  113. echo Building SPIR-V tests is enabled.
  114. set CMAKE_OPTS=%CMAKE_OPTS% -DSPIRV_BUILD_TESTS:BOOL=ON
  115. shift /1
  116. )
  117. rem End SPIRV change
  118. if "%BUILD_ARCH%"=="x64" (
  119. set BUILD_GENERATOR=%BUILD_GENERATOR% %BUILD_ARCH:x64=Win64%
  120. )
  121. if "%1"=="-ninja" (
  122. set BUILD_GENERATOR=Ninja
  123. shift /1
  124. )
  125. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_ENABLE_ARCMT:BOOL=OFF
  126. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_ENABLE_STATIC_ANALYZER:BOOL=OFF
  127. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_INCLUDE_TESTS:BOOL=OFF -DLLVM_INCLUDE_TESTS:BOOL=OFF
  128. set CMAKE_OPTS=%CMAKE_OPTS% -DHLSL_INCLUDE_TESTS:BOOL=ON
  129. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_TARGETS_TO_BUILD:STRING=None
  130. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_INCLUDE_DOCS:BOOL=OFF -DLLVM_INCLUDE_EXAMPLES:BOOL=OFF
  131. set CMAKE_OPTS=%CMAKE_OPTS% -DLIBCLANG_BUILD_STATIC:BOOL=ON
  132. rem set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_OPTIMIZED_TABLEGEN:BOOL=ON
  133. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_OPTIMIZED_TABLEGEN:BOOL=OFF
  134. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_REQUIRES_EH:BOOL=ON
  135. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_APPEND_VC_REV:BOOL=ON
  136. rem Enable exception handling (which requires RTTI).
  137. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_ENABLE_RTTI:BOOL=ON
  138. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_ENABLE_EH:BOOL=ON
  139. rem Setup a specific, stable triple for HLSL.
  140. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_DEFAULT_TARGET_TRIPLE:STRING=dxil-ms-dx
  141. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_BUILD_EXAMPLES:BOOL=OFF
  142. set CMAKE_OPTS=%CMAKE_OPTS% -DLLVM_REQUIRES_RTTI:BOOL=ON
  143. set CMAKE_OPTS=%CMAKE_OPTS% -DCLANG_CL:BOOL=OFF
  144. set CMAKE_OPTS=%CMAKE_OPTS% -DCMAKE_SYSTEM_VERSION=10.0.14393.0
  145. set CMAKE_OPTS=%CMAKE_OPTS% -DDXC_BUILD_ARCH=%BUILD_ARCH%
  146. rem This parameter is used with vcvarsall to force use of 64-bit build tools
  147. rem instead of 32-bit tools that run out of memory.
  148. if "%BUILD_ARCH%"=="Win32" (
  149. set BUILD_TOOLS=amd64_x86
  150. ) else if "%BUILD_ARCH%"=="x64" (
  151. set BUILD_TOOLS=amd64
  152. ) else if "%BUILD_ARCH%"=="ARM" (
  153. set BUILD_TOOLS=amd64_arm
  154. )
  155. call :configandbuild %BUILD_CONFIG% %BUILD_ARCH% %HLSL_BLD_DIR% "%BUILD_GENERATOR%"
  156. if errorlevel 1 exit /b 1
  157. if "%BUILD_GENERATOR%"=="Ninja" (
  158. echo Success - files are available at %HLSL_BLD_DIR%\bin
  159. ) else (
  160. echo Success - files are available at %HLSL_BLD_DIR%\%BUILD_CONFIG%\bin
  161. )
  162. call :handlesuccess
  163. exit /b 0
  164. :showhelp
  165. echo Builds HLSL solutions and the product and test binaries for the current
  166. echo flavor and architecture.
  167. echo.
  168. echo hctbuild [-s or -b] [-alldef] [-analyze] [-fv] [-rel] [-arm or -x86 or -x64] [-Release] [-Debug] [-vs2017] [-ninja]
  169. echo.
  170. echo -s creates the projects only, without building
  171. echo -b builds the existing project
  172. echo.
  173. echo -alldef adds optional projects to the default build
  174. echo -analyze adds /analyze option
  175. echo -fv fixes the resource version for release
  176. echo.
  177. echo -rel builds release rather than debug
  178. echo.
  179. echo current BUILD_ARCH=%BUILD_ARCH%. Override with:
  180. echo -x86 targets an x86 build (aka. Win32)
  181. echo -x64 targets an x64 build (aka. Win64)
  182. echo -arm targets an ARM build
  183. echo.
  184. echo Generator:
  185. echo -ninja use Ninja as the generator
  186. echo.
  187. echo AppVeyor Support
  188. echo -Release builds release
  189. echo -Debug builds debug
  190. echo -vs2017 uses Visual Studio 2017 to build
  191. echo.
  192. if not "%HLSL_BLD_DIR%"=="" (
  193. echo The solution file is at %HLSL_BLD_DIR%\LLVM.sln
  194. echo.
  195. )
  196. goto :eof
  197. :configandbuild
  198. rem Configure and build a specific configuration, typically Debug or Release.
  199. rem %1 - the conf name
  200. rem %2 - the platform name
  201. rem %3 - the build directory
  202. rem %4 - the generator name
  203. if not exist %3 (
  204. mkdir %3
  205. if errorlevel 1 (
  206. echo Unable to create %3
  207. call :handlefail
  208. exit /b 1
  209. )
  210. )
  211. cd /d %3
  212. if "%DO_SETUP%"=="1" (
  213. echo Creating solution files for %2, logging to %3\cmake-log.txt
  214. if "%BUILD_GENERATOR%"=="Ninja" (
  215. echo Running cmake -DCMAKE_BUILD_TYPE:STRING=%1 %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% > %3\cmake-log.txt
  216. cmake -DCMAKE_BUILD_TYPE:STRING=%1 %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% >> %3\cmake-log.txt 2>&1
  217. ) else (
  218. rem -DCMAKE_BUILD_TYPE:STRING=%1 is not necessary for multi-config generators like VS
  219. echo Running cmake %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% > %3\cmake-log.txt
  220. cmake %CMAKE_OPTS% -G %4 %HLSL_SRC_DIR% >> %3\cmake-log.txt 2>&1
  221. )
  222. if errorlevel 1 (
  223. echo Failed to configure cmake projects.
  224. echo ===== begin cmake-log.txt =====
  225. type %3\cmake-log.txt
  226. echo ===== end cmake-log.txt =====
  227. echo Run 'cmake %HLSL_SRC_DIR%' in %3 will continue project generation after fixing the issue.
  228. cmake --version | findstr 3.4
  229. if errorlevel 1 (
  230. echo CMake 3.4 is the currently supported version - your installed cmake may be out of date.
  231. echo See README.md at the root for an explanation of dependencies.
  232. )
  233. findstr -c:"Could NOT find D3D12" %3\cmake-log.txt >NUL
  234. if errorlevel 1 (
  235. rem D3D12 has been found, nothing to diagnose here.
  236. ) else (
  237. echo D3D12 has not been found. Confirm that you have installed the Windows 10 SDK.
  238. echo See README.md at the root for an explanation of dependencies.
  239. echo Run hctclean after installing the SDK to completely rebuild the projects.
  240. )
  241. call :handlefail
  242. exit /b 1
  243. )
  244. )
  245. if "%DO_BUILD%"=="1" (
  246. rem Should add support for the non-x86-qualified programfiles.
  247. echo Building solution files for %2 with %1 configuration.
  248. if "%BUILD_GENERATOR%" NEQ "Ninja" (
  249. if "%BUILD_VS_VER%"=="2015" (
  250. if exist "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" (
  251. call :buildvs_x86dir %1 %2 %3
  252. goto :donebuild
  253. )
  254. )
  255. )
  256. rem Just defer to cmake for now.
  257. cmake --build . --config %1
  258. :donebuild
  259. if errorlevel 1 (
  260. echo Failed to build projects.
  261. echo After fixing, run 'cmake --build --config %1 .' in %2
  262. call :handlefail
  263. exit /b 1
  264. )
  265. endlocal
  266. )
  267. exit /b 0
  268. :buildvs_x86dir
  269. rem Build with the VS tools in the x86 program files directory, maxcpucount makes this goes much faster.
  270. rem 1 - config
  271. rem 2 - platform
  272. rem 3 - build directory
  273. setlocal
  274. call "%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %BUILD_TOOLS%
  275. rem Add /ds for a detailed summary at the end.
  276. echo Logging to %3\msbuild-log.txt
  277. MSBuild.exe /nologo /property:Configuration=%1 /property:Platform=%2 /maxcpucount:2 %3\LLVM.sln /consoleloggerparameters:Summary;Verbosity=minimal /fileloggerparameters:LogFile=%3\msbuild-log.txt
  278. if NOT "%ERRORLEVEL%"=="0" (
  279. exit /b 1
  280. )
  281. endlocal
  282. exit /b 0
  283. :handlefail
  284. cscript.exe //Nologo %HLSL_SRC_DIR%\utils\hct\hctspeak.js /say:"build failed"
  285. exit /b 0
  286. :handlesuccess
  287. cscript.exe //Nologo %HLSL_SRC_DIR%\utils\hct\hctspeak.js /say:"build succeeded"
  288. exit /b 0