Add Packaging for Tizen platform
[platform/upstream/Vulkan-LoaderAndValidationLayers.git] / update_external_sources.bat
1 @echo off
2 REM Update source for glslang, spirv-tools
3
4 REM Determine the appropriate CMake strings for the current version of Visual Studio
5 echo Determining VS version
6 python .\determine_vs_version.py > vsversion.tmp
7 set /p VS_VERSION=< vsversion.tmp
8 echo Detected Visual Studio Version as %VS_VERSION%
9
10 REM Cleanup the file we used to collect the VS version output since it's no longer needed.
11 del /Q /F vsversion.tmp
12
13 setlocal EnableDelayedExpansion
14 set errorCode=0
15 set BUILD_DIR=%~dp0
16 set BASE_DIR="%BUILD_DIR%external"
17 set GLSLANG_DIR=%BASE_DIR%\glslang
18 set SPIRV_TOOLS_DIR=%BASE_DIR%\spirv-tools
19
20 REM // ======== Parameter parsing ======== //
21
22    if "%1" == "" (
23       echo usage: update_external_sources.bat [options]
24       echo.
25       echo Available options:
26       echo   --sync-glslang      just pull glslang_revision
27       echo   --sync-spirv-tools  just pull spirv-tools_revision
28       echo   --build-glslang     pulls glslang_revision, configures CMake, builds Release and Debug
29       echo   --build-spirv-tools pulls spirv-tools_revision, configures CMake, builds Release and Debug
30       echo   --all               sync and build glslang, LunarGLASS, spirv-tools
31       goto:finish
32    )
33
34    set sync-glslang=0
35    set sync-spirv-tools=0
36    set build-glslang=0
37    set build-spirv-tools=0
38    set check-glslang-build-dependencies=0
39
40    :parameterLoop
41
42       if "%1"=="" goto:parameterContinue
43
44       if "%1" == "--sync-glslang" (
45          set sync-glslang=1
46          shift
47          goto:parameterLoop
48       )
49
50       if "%1" == "--sync-spirv-tools" (
51          set sync-spirv-tools=1
52          shift
53          goto:parameterLoop
54       )
55
56       if "%1" == "--build-glslang" (
57          set sync-glslang=1
58          set check-glslang-build-dependencies=1
59          set build-glslang=1
60          shift
61          goto:parameterLoop
62       )
63
64       if "%1" == "--build-spirv-tools" (
65          set sync-spirv-tools=1
66          REM glslang has the same needs as spirv-tools
67          set check-glslang-build-dependencies=1
68          set build-spirv-tools=1
69          shift
70          goto:parameterLoop
71       )
72
73       if "%1" == "--all" (
74          set sync-glslang=1
75          set sync-spirv-tools=1
76          set build-glslang=1
77          set build-spirv-tools=1
78          set check-glslang-build-dependencies=1
79          shift
80          goto:parameterLoop
81       )
82
83       echo Unrecognized options "%1"
84       goto:error
85
86    :parameterContinue
87
88 REM // ======== end Parameter parsing ======== //
89
90
91 REM // ======== Dependency checking ======== //
92    REM git is required for all paths
93    for %%X in (git.exe) do (set FOUND=%%~$PATH:X)
94    if not defined FOUND (
95       echo Dependency check failed:
96       echo   git.exe not found
97       echo   Git for Windows can be downloaded here:  https://git-scm.com/download/win
98       echo   Install and ensure git.exe makes it into your PATH
99       set errorCode=1
100    )
101
102    if %check-glslang-build-dependencies% equ 1 (
103       for %%X in (cmake.exe) do (set FOUND=%%~$PATH:X)
104       if not defined FOUND (
105          echo Dependency check failed:
106          echo   cmake.exe not found
107          echo   Get CNake 2.8 for Windows here:  http://www.cmake.org/cmake/resources/software.html
108          echo   Install and ensure each makes it into your PATH, default is "C:\Program Files (x86)\CMake\bin"
109          set errorCode=1
110       )
111    )
112
113
114    REM goto:main
115
116 REM // ======== end Dependency checking ======== //
117
118 :main
119
120 if %errorCode% neq 0 (goto:error)
121
122 REM Read the target versions from external file, which is shared with Linux script
123
124 if not exist glslang_revision (
125    echo.
126    echo Missing glslang_revision file!  Place it next to this script with target version in it.
127    set errorCode=1
128    goto:error
129 )
130
131 if not exist spirv-tools_revision (
132    echo.
133    echo Missing spirv-tools_revision file!  Place it next to this script with target version in it.
134    set errorCode=1
135    goto:error
136 )
137
138 set /p GLSLANG_REVISION= < glslang_revision
139 set /p SPIRV_TOOLS_REVISION= < spirv-tools_revision
140 set /p SPIRV_HEADERS_REVISION= < spirv-headers_revision
141 echo GLSLANG_REVISION=%GLSLANG_REVISION%
142 echo SPIRV_TOOLS_REVISION=%SPIRV_TOOLS_REVISION%
143 echo SPIRV_HEADERS_REVISION=%SPIRV_HEADERS_REVISION%
144
145
146 echo Creating and/or updating glslang, spirv-tools in %BASE_DIR%
147
148 if %sync-glslang% equ 1 (
149    if exist %GLSLANG_DIR% (
150       rd /S /Q %GLSLANG_DIR%
151    )
152    if not exist %GLSLANG_DIR% (
153       call:create_glslang
154    )
155    if %errorCode% neq 0 (goto:error)
156    call:update_glslang
157    if %errorCode% neq 0 (goto:error)
158 )
159
160 if %sync-spirv-tools% equ 1 (
161    if exist %SPIRV_TOOLS_DIR% (
162       rd /S /Q %SPIRV_TOOLS_DIR%
163    )
164    if %errorlevel% neq 0 (goto:error)
165    if not exist %SPIRV_TOOLS_DIR% (
166       call:create_spirv-tools
167    )
168    if %errorCode% neq 0 (goto:error)
169    call:update_spirv-tools
170    if %errorCode% neq 0 (goto:error)
171 )
172
173 if %build-glslang% equ 1 (
174    call:build_glslang
175    if %errorCode% neq 0 (goto:error)
176 )
177
178 if %build-spirv-tools% equ 1 (
179    call:build_spirv-tools
180    if %errorCode% neq 0 (goto:error)
181 )
182
183 echo.
184 echo Exiting
185 goto:finish
186
187 :error
188 echo.
189 echo Halting due to error
190 goto:finish
191
192 :finish
193 if not "%cd%\" == "%BUILD_DIR%" ( cd %BUILD_DIR% )
194 endlocal
195 goto:eof
196
197
198
199 REM // ======== Functions ======== //
200
201 :create_glslang
202    echo.
203    echo Creating local glslang repository %GLSLANG_DIR%)
204    mkdir %GLSLANG_DIR%
205    cd %GLSLANG_DIR%
206    git clone https://github.com/KhronosGroup/glslang.git .
207    git checkout %GLSLANG_REVISION%
208    if not exist %GLSLANG_DIR%\SPIRV (
209       echo glslang source download failed!
210       set errorCode=1
211    )
212 goto:eof
213
214 :update_glslang
215    echo.
216    echo Updating %GLSLANG_DIR%
217    cd %GLSLANG_DIR%
218    git fetch --all
219    git checkout %GLSLANG_REVISION%
220 goto:eof
221
222 :create_spirv-tools
223    echo.
224    echo Creating local spirv-tools repository %SPIRV_TOOLS_DIR%)
225    mkdir %SPIRV_TOOLS_DIR%
226    cd %SPIRV_TOOLS_DIR%
227    git clone https://github.com/KhronosGroup/SPIRV-Tools.git .
228    git checkout %SPIRV_TOOLS_REVISION%
229    if not exist %SPIRV_TOOLS_DIR%\source (
230       echo spirv-tools source download failed!
231       set errorCode=1
232    )
233    mkdir %SPIRV_TOOLS_DIR%\external
234    mkdir %SPIRV_TOOLS_DIR%\external\spirv-headers
235    cd %SPIRV_TOOLS_DIR%\external\spirv-headers
236    git clone https://github.com/KhronosGroup/SPIRV-HEADERS.git .
237    git checkout %SPIRV_HEADERS_REVISION%
238    if not exist %SPIRV_TOOLS_DIR%\external\spirv-headers\README.md (
239       echo spirv-headers download failed!
240       set errorCode=1
241    )
242 goto:eof
243
244 :update_spirv-tools
245    echo.
246    echo Updating %SPIRV_TOOLS_DIR%
247    cd %SPIRV_TOOLS_DIR%
248    git fetch --all
249    git checkout %SPIRV_TOOLS_REVISION%
250    cd %SPIRV_TOOLS_DIR%\external\spirv-headers
251    git fetch --all
252    git checkout %SPIRV_HEADERS_REVISION%
253 goto:eof
254
255 :build_glslang
256    echo.
257    echo Building %GLSLANG_DIR%
258    cd  %GLSLANG_DIR%
259
260    REM Cleanup any old directories lying around.
261    if exist build32 (
262       rmdir /s /q build32
263    )
264    if exist build (
265       rmdir /s /q build
266    )
267    
268    echo Making 32-bit glslang
269    echo *************************
270    mkdir build32
271    set GLSLANG_BUILD_DIR=%GLSLANG_DIR%\build32
272    cd %GLSLANG_BUILD_DIR%
273
274    echo Generating 32-bit Glslang CMake files for Visual Studio %VS_VERSION% -DCMAKE_INSTALL_PREFIX=install ..
275    cmake -G "Visual Studio %VS_VERSION%" -DCMAKE_INSTALL_PREFIX=install ..
276    
277    echo Building 32-bit Glslang: MSBuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Debug
278    msbuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Debug /verbosity:quiet
279    
280    REM Check for existence of one lib, even though we should check for all results
281    if not exist %GLSLANG_BUILD_DIR%\glslang\Debug\glslangd.lib (
282       echo.
283       echo glslang 32-bit Debug build failed!
284       set errorCode=1
285    )
286    echo Building Glslang: MSBuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Release
287    msbuild INSTALL.vcxproj /p:Platform=x86 /p:Configuration=Release /verbosity:quiet
288    
289    REM Check for existence of one lib, even though we should check for all results
290    if not exist %GLSLANG_BUILD_DIR%\glslang\Release\glslang.lib (
291       echo.
292       echo glslang 32-bit Release build failed!
293       set errorCode=1
294    )
295    
296    cd ..
297  
298    echo Making 64-bit glslang
299    echo *************************
300    mkdir build
301    set GLSLANG_BUILD_DIR=%GLSLANG_DIR%\build
302    cd %GLSLANG_BUILD_DIR%
303
304    echo Generating 64-bit Glslang CMake files for Visual Studio %VS_VERSION% -DCMAKE_INSTALL_PREFIX=install ..
305    cmake -G "Visual Studio %VS_VERSION% Win64" -DCMAKE_INSTALL_PREFIX=install ..
306    
307    echo Building 64-bit Glslang: MSBuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug
308    msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Debug /verbosity:quiet
309    
310    REM Check for existence of one lib, even though we should check for all results
311    if not exist %GLSLANG_BUILD_DIR%\glslang\Debug\glslangd.lib (
312       echo.
313       echo glslang 64-bit Debug build failed!
314       set errorCode=1
315    )
316    echo Building Glslang: MSBuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release
317    msbuild INSTALL.vcxproj /p:Platform=x64 /p:Configuration=Release /verbosity:quiet
318    
319    REM Check for existence of one lib, even though we should check for all results
320    if not exist %GLSLANG_BUILD_DIR%\glslang\Release\glslang.lib (
321       echo.
322       echo glslang 64-bit Release build failed!
323       set errorCode=1
324    )
325 goto:eof
326
327 :build_spirv-tools
328    echo.
329    echo Building %SPIRV_TOOLS_DIR%
330    cd  %SPIRV_TOOLS_DIR%
331
332    REM Cleanup any old directories lying around.
333    if exist build32 (
334       rmdir /s /q build32
335    )
336    if exist build (
337       rmdir /s /q build
338    )
339
340    echo Making 32-bit spirv-tools
341    echo *************************
342    mkdir build32
343    set SPIRV_TOOLS_BUILD_DIR=%SPIRV_TOOLS_DIR%\build32
344
345    cd %SPIRV_TOOLS_BUILD_DIR%
346    
347    echo Generating 32-bit spirv-tools CMake files for Visual Studio %VS_VERSION% ..
348    cmake -G "Visual Studio %VS_VERSION%" ..
349    
350    echo Building 32-bit spirv-tools: MSBuild ALL_BUILD.vcxproj /p:Platform=x86 /p:Configuration=Debug
351    msbuild ALL_BUILD.vcxproj /p:Platform=x86 /p:Configuration=Debug /verbosity:quiet
352    
353    REM Check for existence of one lib, even though we should check for all results
354    if not exist %SPIRV_TOOLS_BUILD_DIR%\source\Debug\SPIRV-Tools.lib (
355       echo.
356       echo spirv-tools 32-bit Debug build failed!
357       set errorCode=1
358    )
359    
360    echo Building 32-bit spirv-tools: MSBuild ALL_BUILD.vcxproj /p:Platform=x86 /p:Configuration=Release
361    msbuild ALL_BUILD.vcxproj /p:Platform=x86 /p:Configuration=Release /verbosity:quiet
362
363    REM Check for existence of one lib, even though we should check for all results
364    if not exist %SPIRV_TOOLS_BUILD_DIR%\source\Release\SPIRV-Tools.lib (
365       echo.
366       echo spirv-tools 32-bit Release build failed!
367       set errorCode=1
368    )
369    
370    cd ..
371  
372    echo Making 64-bit spirv-tools  
373    echo *************************
374    mkdir build
375    set SPIRV_TOOLS_BUILD_DIR=%SPIRV_TOOLS_DIR%\build
376    cd %SPIRV_TOOLS_BUILD_DIR%
377
378    echo Generating 64-bit spirv-tools CMake files for Visual Studio %VS_VERSION% ..
379    cmake -G "Visual Studio %VS_VERSION% Win64" ..
380    
381    echo Building 64-bit spirv-tools: MSBuild ALL_BUILD.vcxproj /p:Platform=x64 /p:Configuration=Debug
382    msbuild ALL_BUILD.vcxproj /p:Platform=x64 /p:Configuration=Debug /verbosity:quiet
383    
384    REM Check for existence of one lib, even though we should check for all results
385    if not exist %SPIRV_TOOLS_BUILD_DIR%\source\Debug\SPIRV-Tools.lib (
386       echo.
387       echo spirv-tools 64-bit Debug build failed!
388       set errorCode=1
389    )
390    
391    echo Building 64-bit spirv-tools: MSBuild ALL_BUILD.vcxproj /p:Platform=x64 /p:Configuration=Release
392    msbuild ALL_BUILD.vcxproj /p:Platform=x64 /p:Configuration=Release /verbosity:quiet
393
394    REM Check for existence of one lib, even though we should check for all results
395    if not exist %SPIRV_TOOLS_BUILD_DIR%\source\Release\SPIRV-Tools.lib (
396       echo.
397       echo spirv-tools 64-bit Release build failed!
398       set errorCode=1
399    )
400 goto:eof