1 :: --------------------------------------------------
\r
2 :: Run full BTLS build using msvc toolchain and available cmake generator.
\r
3 :: Script needs to be run from within a matching build environment, x86|x64.
\r
4 :: When executed from withing Visual Studio build environment current
\r
5 :: build environment will be inherited by script.
\r
7 :: %1 Mono BTLS source root directory.
\r
8 :: %2 BTLS source root directory.
\r
9 :: %3 BTLS build root directory.
\r
10 :: %4 Mono distribution root directory.
\r
12 :: %6 VS platform (Win32/x64)
\r
13 :: %7 VS configuration (Debug/Release)
\r
15 :: %9 MsBuild bin path, if used.
\r
16 :: %10 Force MSBuild (true/false), if used.
\r
17 :: --------------------------------------------------
\r
22 set TEMP_PATH=%PATH%
\r
25 set CL_BIN_NAME=cl.exe
\r
26 set LINK_BIN_NAME=link.exe
\r
27 set GIT_BIN_NAME=git.exe
\r
28 set CMAKE_BIN_NAME=cmake.exe
\r
29 set NINJA_BIN_NAME=ninja.exe
\r
30 set PERL_BIN_NAME=perl.exe
\r
31 set YASM_BIN_NAME=yasm.exe
\r
33 set MONO_BTLS_DIR=%~1
\r
37 set BTLS_BUILD_DIR=%~1
\r
39 set MONO_DIST_DIR=%~1
\r
45 set VS_CONFIGURATION=%~1
\r
49 set MSBUILD_BIN_PATH=%~1
\r
51 set FORCE_MSBUILD=%~1
\r
57 set MSBUILD=%MSBUILD_BIN_PATH%msbuild.exe
\r
59 if "%MONO_BTLS_DIR%" == "" (
\r
60 echo Missing mono BTLS source directory argument.
\r
64 if "%BTLS_DIR%" == "" (
\r
65 echo Missing BTLS source directory argument.
\r
69 if "%BTLS_BUILD_DIR%" == "" (
\r
70 echo Missing BTLS build directory argument.
\r
74 if "%MONO_DIST_DIR%" == "" (
\r
75 echo Missing mono install directory argument.
\r
79 if "%VS_CFLAGS%" == "" (
\r
80 echo Missing CFLAGS argument.
\r
84 if "%VS_PLATFORM%" == "" (
\r
88 if "%VS_CONFIGURATION%" == "" (
\r
89 set VS_CONFIGURATION=Release
\r
92 if "%VS_TARGET%" == "" (
\r
96 if "%FORCE_MSBUILD%" == "" (
\r
97 set FORCE_MSBUILD=false
\r
100 if not exist "%MONO_BTLS_DIR%" (
\r
101 echo Could not find "%MONO_BTLS_DIR%".
\r
105 if not exist "%BTLS_DIR%" (
\r
106 echo Could not find "%BTLS_DIR%".
\r
110 set BTLS_CFLAGS=%VS_CFLAGS%
\r
111 set BTLS_ARCH=x86_64
\r
112 if /i "%VS_PLATFORM%" == "win32" (
\r
116 set BTLS_NO_ASM_SUPPORT=1
\r
118 :: Check if executed from VS2015/VS2017 build environment.
\r
119 if "%VisualStudioVersion%" == "14.0" (
\r
123 if "%VisualStudioVersion%" == "15.0" (
\r
127 :: Executed outside VS2015/VS2017 build environment, try to locate Visual Studio C/C++ compiler and linker.
\r
128 call :FIND_PROGRAM "" "%CL_BIN_NAME%" CL_PATH
\r
129 if "%CL_PATH%" == "" (
\r
130 goto ON_ENV_WARNING
\r
133 call :FIND_PROGRAM "" "%LINK_BIN_NAME%" LINK_PATH
\r
134 if "%LINK_PATH%" == "" (
\r
135 goto ON_ENV_WARNING
\r
143 set VC_VARS_ALL_FILE=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
\r
144 IF EXIST "%VC_VARS_ALL_FILE%" (
\r
145 echo For VS2015 builds, make sure to run this from within Visual Studio build or using "VS2015 x86|x64 Native Tools Command Prompt" command prompt.
\r
146 echo Setup a "VS2015 x86|x64 Native Tools Command Prompt" command prompt by using "%VC_VARS_ALL_FILE% x86|amd64".
\r
150 set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
\r
151 if exist "%VSWHERE_TOOLS_BIN%" (
\r
152 echo For VS2017 builds, make sure to run this from within Visual Studio build or using "x86|x64 Native Tools Command Prompt for VS2017" command prompt.
\r
153 for /f "tokens=*" %%a IN ('"%VSWHERE_TOOLS_BIN%" -latest -property installationPath') do (
\r
154 echo Setup a "x86|x64 Native Tools Command Prompt for VS2017" command prompt by using "%%a\VC\Auxiliary\Build\vcvars32.bat|vcvars64.bat".
\r
158 echo Could not detect Visual Studio build environment. You may experience build problems if wrong toolchain is auto detected.
\r
162 :: Setup all cmake related generator, tools and variables.
\r
163 call :SETUP_CMAKE_ENVIRONMENT
\r
164 if "%CMAKE%" == "" (
\r
165 echo Failed to located working %CMAKE_BIN_NAME%, needs to be accessible in PATH or set using CMAKE environment variable.
\r
169 if "%CMAKE_GENERATOR%" == "" (
\r
170 echo Failed to setup cmake generator.
\r
175 if /i "%VS_TARGET%" == "build" (
\r
179 if /i "%VS_TARGET%" == "install" (
\r
180 goto ON_INSTALL_BTLS
\r
183 if /i "%VS_TARGET%" == "clean" (
\r
189 :: If not set by caller, check environment for working git.exe.
\r
190 call :FIND_PROGRAM "%GIT%" "%GIT_BIN_NAME%" GIT
\r
192 echo Failed to located working %GIT_BIN_NAME%, needs to be accessible in PATH or set using GIT environment variable.
\r
196 :: Make sure boringssl submodule is up to date.
\r
199 "%GIT%" submodule update --init
\r
200 if not ERRORLEVEL == 0 (
\r
201 "%GIT%" submodule init
\r
202 "%GIT%" submodule update
\r
203 if not ERRORLEVEL == 0 (
\r
204 echo Git boringssl submodules failed to updated. You may experience compilation problems if some submodules are out of date.
\r
209 if not exist "%BTLS_BUILD_DIR%" (
\r
210 mkdir "%BTLS_BUILD_DIR%"
\r
213 cd "%BTLS_BUILD_DIR%"
\r
215 :: Make sure cmake pick up msvc toolchain regardless of selected generator (Visual Studio|Ninja)
\r
216 set CC=%CL_BIN_NAME%
\r
217 set CXX=%CL_BIN_NAME%
\r
219 set BTLS_BUILD_TYPE=
\r
220 if /i "%CMAKE_GENERATOR%" == "ninja" (
\r
221 set BTLS_BUILD_TYPE=-D CMAKE_BUILD_TYPE=%VS_CONFIGURATION%
\r
226 -D BTLS_ROOT:PATH="%BTLS_DIR%" ^
\r
227 -D SRC_DIR:PATH="%MONO_BTLS_DIR%" ^
\r
228 -D BTLS_CFLAGS="%BTLS_CFLAGS%" ^
\r
229 -D OPENSSL_NO_ASM=%BTLS_NO_ASM_SUPPORT% ^
\r
230 -D BTLS_ARCH="%BTLS_ARCH%" ^
\r
231 -D BUILD_SHARED_LIBS=1 ^
\r
232 %BTLS_BUILD_TYPE% ^
\r
233 -G "%CMAKE_GENERATOR%" ^
\r
236 if not ERRORLEVEL == 0 (
\r
240 if /i "%CMAKE_GENERATOR%" == "ninja" (
\r
241 :: Build BTLS using ninja build system.
\r
242 call "%NINJA%" || (
\r
246 :: Build BTLS using msbuild build system.
\r
247 call "%MSBUILD%" mono-btls.sln /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:%VS_TARGET% /v:m /nologo || (
\r
254 if not exist "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll" (
\r
255 echo Missing btls build output, "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll"
\r
259 :: Make sure build output folder exists.
\r
260 if not exist "%MONO_DIST_DIR%" (
\r
261 echo Could not find "%MONO_DIST_DIR%", creating folder for build output.
\r
262 mkdir "%MONO_DIST_DIR%"
\r
265 :: Copy files into distribution directory.
\r
266 copy /Y "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.dll" "%MONO_DIST_DIR%" >nul 2>&1
\r
268 if exist "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" (
\r
269 copy /Y "%BTLS_BUILD_OUTPUT_DIR%\libmono-btls-shared.pdb" "%MONO_DIST_DIR%" >nul 2>&1
\r
276 if exist "%BTLS_BUILD_DIR%\build.ninja" (
\r
278 cd "%BTLS_BUILD_DIR%"
\r
279 call "%NINJA%" clean
\r
283 if exist "%BTLS_BUILD_DIR%\mono-btls.sln" (
\r
284 "%MSBUILD%" "%BTLS_BUILD_DIR%\mono-btls.sln" /p:Configuration=%VS_CONFIGURATION% /p:Platform=%VS_PLATFORM% /t:Clean /v:m /nologo
\r
295 ECHO Usage: build-btls.bat [mono_btls_src_dir] [btls_src_dir] [btls_build_dir] [mono_dist_dir] [vs_cflags] [vs_plaform] [vs_configuration].
\r
298 echo Failed to build BTLS.
\r
302 set PATH=%TEMP_PATH%
\r
303 exit /b %BUILD_RESULT%
\r
305 :: ##############################################################################################################################
\r
308 :: --------------------------------------------------
\r
309 :: Finds a program using environment.
\r
311 :: %1 Existing program to check for.
\r
312 :: %2 Name of binary to locate.
\r
313 :: %3 Output, variable to set if found requested program.
\r
314 :: --------------------------------------------------
\r
317 :: If not set by caller, check environment for program.
\r
322 call where /q "%~2" && (
\r
323 for /f "delims=" %%a in ('where "%~2"') do (
\r
332 :: --------------------------------------------------
\r
333 :: Setup up cmake build environment, including generator, build tools and variables.
\r
334 :: --------------------------------------------------
\r
335 :SETUP_CMAKE_ENVIRONMENT
\r
337 :: If not set by caller, check environment for working cmake.exe.
\r
338 call :FIND_PROGRAM "%CMAKE%" "%CMAKE_BIN_NAME%" CMAKE
\r
339 if "%CMAKE%" == "" (
\r
340 goto _SETUP_CMAKE_ENVIRONMENT_EXIT
\r
343 if /i "%VS_TARGET%" == "build" (
\r
344 echo Found CMake: "%CMAKE%"
\r
347 if /i "%FORCE_MSBUILD%" == "true" (
\r
348 goto _SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR
\r
351 :: Check for optional cmake generate and build tools for full BTLS assembler supported build. NOTE, currently BTLS assembler build
\r
352 :: can't be done using Visual Studio and must use ninja build generator + yasm and perl.
\r
353 call :FIND_PROGRAM "%NINJA%" "%NINJA_BIN_NAME%" NINJA
\r
354 call :FIND_PROGRAM "%YASM%" "%YASM_BIN_NAME%" YASM
\r
355 call :FIND_PROGRAM "%PERL%" "%PERL_BIN_NAME%" PERL
\r
357 if not "%NINJA%" == "" if not "%YASM%" == "" if not "%PERL%" == "" (
\r
358 goto _SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR
\r
361 :_SETUP_CMAKE_ENVIRONMENT_VS_GENERATOR
\r
363 if /i "%VS_TARGET%" == "build" (
\r
364 echo Using Visual Studio build generator, disabling full assembler build.
\r
367 :: Detect VS version to use right cmake generator.
\r
368 set CMAKE_GENERATOR=Visual Studio 14 2015
\r
369 if "%VisualStudioVersion%" == "15.0" (
\r
370 set CMAKE_GENERATOR=Visual Studio 15 2017
\r
373 if /i "%VS_PLATFORM%" == "x64" (
\r
374 set CMAKE_GENERATOR=%CMAKE_GENERATOR% Win64
\r
377 set BTLS_BUILD_OUTPUT_DIR=%BTLS_BUILD_DIR%\%VS_CONFIGURATION%
\r
379 goto _SETUP_CMAKE_ENVIRONMENT_EXIT
\r
381 :_SETUP_CMAKE_ENVIRONMENT_NINJA_GENERATOR
\r
383 if /i "%VS_TARGET%" == "build" (
\r
384 echo Found Ninja: "%NINJA%"
\r
385 echo Using Ninja build generator, enabling full assembler build.
\r
388 set CMAKE_GENERATOR=Ninja
\r
389 set BTLS_BUILD_OUTPUT_DIR=%BTLS_BUILD_DIR%
\r
390 set BTLS_NO_ASM_SUPPORT=0
\r
392 :_SETUP_CMAKE_ENVIRONMENT_EXIT
\r