1::
2:: Copyright(c) 2019 Intel Corporation
3::
4:: This source code is subject to the terms of the BSD 2 Clause License and
5:: the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6:: was not distributed with this source code in the LICENSE file, you can
7:: obtain it at www.aomedia.org/license/software. If the Alliance for Open
8:: Media Patent License 1.0 was not distributed with this source code in the
9:: PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10::
11@echo off
12
13setlocal
14cd /d "%~dp0"
15
16:: Set defaults to prevent inheriting
17set "build=y"
18:: Default is debug
19set "buildtype=Debug"
20:: Default is shared
21set "shared=ON"
22set "GENERATOR="
23:: (cmake -G 2>&1 | Select-String -SimpleMatch '*').Line.Split('=')[0].TrimEnd().Replace('* ','')
24:: Default is not building unit tests
25set "unittest=OFF"
26if NOT -%1-==-- call :args %*
27if %errorlevel%==1 exit /b 1
28if exist CMakeCache.txt del /f /s /q CMakeCache.txt 1>nul
29if exist CMakeFiles rmdir /s /q CMakeFiles 1>nul
30if NOT "%GENERATOR%"=="" set GENERATOR=-G"%GENERATOR%"
31
32echo Building in %buildtype% configuration
33
34if NOT "%build%"=="y" echo Generating build files
35
36if "%shared%"=="ON" (
37    echo Building shared
38) else (
39    echo Building static
40)
41
42if "%unittest%"=="ON" echo Building unit tests
43
44if "%vs%"=="2019" (
45    cmake ../.. %GENERATOR% -A x64 -DCMAKE_INSTALL_PREFIX=%SYSTEMDRIVE%\svt-encoders -DBUILD_SHARED_LIBS=%shared% -DBUILD_TESTING=%unittest% %cmake_eflags% || exit /b 1
46) else (
47    cmake ../.. %GENERATOR% -DCMAKE_INSTALL_PREFIX=%SYSTEMDRIVE%\svt-encoders -DBUILD_SHARED_LIBS=%shared% -DBUILD_TESTING=%unittest% %cmake_eflags% || exit /b 1
48)
49
50if "%build%"=="y" cmake --build . --config %buildtype%
51goto :EOF
52
53:args
54if -%1-==-- (
55    exit /b
56) else if /I "%1"=="/help" (
57    call :help
58) else if /I "%1"=="help" (
59    call :help
60) else if /I "%1"=="clean" (
61    echo Cleaning build folder
62    for %%i in (*) do if not "%%~i" == "build.bat" del "%%~i"
63    for /d %%i in (*) do if not "%%~i" == "build.bat" (
64        del /f /s /q "%%~i" 1>nul
65        rmdir /s /q "%%~i" 1>nul
66    )
67    exit /b
68) else if /I "%1"=="2019" (
69    echo Generating Visual Studio 2019 solution
70    set "GENERATOR=Visual Studio 16 2019"
71    set vs=2019
72    shift
73) else if /I "%1"=="2017" (
74    echo Generating Visual Studio 2017 solution
75    set "GENERATOR=Visual Studio 15 2017 Win64"
76    set vs=2017
77    shift
78) else if /I "%1"=="2015" (
79    echo Generating Visual Studio 2015 solution
80    set "GENERATOR=Visual Studio 14 2015 Win64"
81    set vs=2015
82    shift
83) else if /I "%1"=="2013" (
84    echo Generating Visual Studio 2013 solution
85    echo This is currently not officially supported
86    set "GENERATOR=Visual Studio 12 2013 Win64"
87    set vs=2013
88    shift
89) else if /I "%1"=="2012" (
90    echo Generating Visual Studio 2012 solution
91    echo This is currently not officially supported
92    set "GENERATOR=Visual Studio 11 2012 Win64"
93    set vs=2012
94    shift
95) else if /I "%1"=="2010" (
96    echo Generating Visual Studio 2010 solution
97    echo This is currently not officially supported
98    set "GENERATOR=Visual Studio 10 2010 Win64"
99    set vs=2010
100    shift
101) else if /I "%1"=="2008" (
102    echo Generating Visual Studio 2008 solution
103    echo This is currently not officially supported
104    set "GENERATOR=Visual Studio 9 2008 Win64"
105    set vs=2008
106    shift
107) else if /I "%1"=="ninja" (
108    echo Generating Ninja files
109    echo This is currently not officially supported
110    set "GENERATOR=Ninja"
111    shift
112) else if /I "%1"=="msys" (
113    echo Generating MSYS Makefiles
114    echo This is currently not officially supported
115    set "GENERATOR=MSYS Makefiles"
116    shift
117) else if /I "%1"=="mingw" (
118    echo Generating MinGW Makefiles
119    echo This is currently not officially supported
120    set "GENERATOR=MinGW Makefiles"
121    shift
122) else if /I "%1"=="unix" (
123    echo Generating Unix Makefiles
124    echo This is currently not officially supported
125    set "GENERATOR=Unix Makefiles"
126    shift
127) else if /I "%1"=="release" (
128    set "buildtype=Release"
129    shift
130) else if /I "%1"=="debug" (
131    set "buildtype=Debug"
132    shift
133) else if /I "%1"=="test" (
134    set "unittest=ON"
135    shift
136) else if /I "%1"=="static" (
137    set "shared=OFF"
138    shift
139) else if /I "%1"=="shared" (
140    set "shared=ON"
141    shift
142) else if /I "%1"=="nobuild" (
143    set "build=n"
144    shift
145) else if /I "%1"=="c-only" (
146    set "cmake_eflags=%cmake_eflags% -DCOMPILE_C_ONLY=ON"
147    shift
148) else if /I "%1"=="avx512" (
149    set "cmake_eflags=%cmake_eflags% -DENABLE_AVX512=ON"
150    shift
151) else if /I "%1"=="lto" (
152    set "cmake_eflags=%cmake_eflags% -DSVT_AV1_LTO=ON"
153    shift
154)  else (
155    echo Unknown argument "%1"
156    call :help
157    goto :EOF
158)
159goto :args
160
161:help
162    echo Batch file to build SVT-AV1 on Windows
163    echo Usage: build.bat [2019^|2017^|2015^|clean] [release^|debug] [nobuild] [test] [shared^|static] [c-only] [avx512]
164    exit /b 1
165goto :EOF
166