2021-07-13 15:09:10 -04:00
@ echo off
: : Copyright Epic Games, Inc. All Rights Reserved.
: : To build the Boost libraries, you need to have "Build Tools for Visual Studio" installed: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
setlocal EnableDelayedExpansion
2022-10-20 12:53:38 -04:00
set BUILD_SCRIPT_LOCATION = %~dp0
set UE_MODULE_LOCATION = %BUILD_SCRIPT_LOCATION% ..\..
2021-07-13 15:09:10 -04:00
: : Set the following variable to 1 if you already downloaded and extracted the boost sources, and you need to play around with the build configuration.
set ALREADY_HAVE_SOURCES = 0
: : Get version from arguments.
set ARG_VERSION = %1
: : Get libraries list from arguments. It is built from all remaining arguments with '=' and ',' being argument delimiters.
set ARG_LIBRARIES = %2
set BOOST_WITH_LIBRARIES = --with-%2
set BOOST_WITH_PYTHON = 0
: loop_over_libraries
if " %2 " == " python " set BOOST_WITH_PYTHON = 1
shift
if [%2 ]== [] goto after_loop_over_libraries
set ARG_LIBRARIES = %ARG_LIBRARIES% , %2
set BOOST_WITH_LIBRARIES = %BOOST_WITH_LIBRARIES% --with-%2
goto loop_over_libraries
: after_loop_over_libraries
: : Extract version number.
if [%ARG_VERSION% ]== [] goto usage
set BOOST_VERSION = %ARG_VERSION%
: : Extract libraries to be built.
set BOOST_BUILD_LIBRARIES = 0
if not [!ARG_LIBRARIES!]== [] set BOOST_BUILD_LIBRARIES = 1
: : Print arguments to make spotting errors in the arguments easier.
echo Provided arguments:
echo Boost version: %BOOST_VERSION%
if !BOOST_BUILD_LIBRARIES! == 1 (
echo Build libraries: !ARG_LIBRARIES!
) else (
echo Build libraries: ^< headers-only^>
)
echo .
: : Set up paths and filenames.
set BOOST_VERSION_FILENAME = boost_%BOOST_VERSION:.=_%
set BOOST_ZIP_FILE = %BOOST_VERSION_FILENAME% .zip
2022-10-20 12:53:38 -04:00
set BUILD_LOCATION = %UE_MODULE_LOCATION% \Intermediate
set INSTALL_INCLUDEDIR = include
set INSTALL_LIB_DIR = lib/Win64
set INSTALL_LOCATION = %UE_MODULE_LOCATION% \boost-%BOOST_VERSION:.=_%
set INSTALL_INCLUDE_LOCATION = %INSTALL_LOCATION% \%INSTALL_INCLUDEDIR%
set INSTALL_LIB_LOCATION = %INSTALL_LOCATION% \%INSTALL_LIB_DIR%
2021-07-13 15:09:10 -04:00
if %ALREADY_HAVE_SOURCES% == 0 (
: : Remove previous intermediate files to allow for a clean build.
2022-10-20 12:53:38 -04:00
if exist %BUILD_LOCATION% (
2021-07-13 15:09:10 -04:00
: : Filenames in the intermediate directory are likely too long for tools like 'rmdir' to handle. Instead, we use robocopy to mirror an empty temporary folder, and then delete it.
2022-10-20 12:53:38 -04:00
echo [%time% ] Deleting previous intermediate files in '%BUILD_LOCATION% '...
mkdir " %BUILD_LOCATION% _DELETE "
robocopy " %BUILD_LOCATION% _DELETE " " %BUILD_LOCATION% " /purge /W:0 /R:0 > NUL
rmdir " %BUILD_LOCATION% _DELETE "
rmdir " %BUILD_LOCATION% "
2021-07-13 15:09:10 -04:00
)
: : Create intermediate directory.
2022-10-20 12:53:38 -04:00
mkdir %BUILD_LOCATION%
2021-07-13 15:09:10 -04:00
)
: : Use intermediate directory.
2022-10-20 12:53:38 -04:00
cd %BUILD_LOCATION%
2021-07-13 15:09:10 -04:00
if %ALREADY_HAVE_SOURCES% == 0 (
: : Download ZIP files.
set BOOST_URL = https://boostorg.jfrog.io/artifactory/main/release/%BOOST_VERSION% /source/%BOOST_ZIP_FILE%
echo [!time!] Downloading !BOOST_URL! ...
powershell -Command " (New-Object Net.WebClient).DownloadFile('!BOOST_URL!', ' %BOOST_ZIP_FILE% ') "
if not errorlevel 0 goto error
: : Extract ZIP file.
echo [!time!] Extracting %BOOST_ZIP_FILE% ...
tar -xf %BOOST_ZIP_FILE%
if not errorlevel 0 goto error
) else (
2022-10-20 12:53:38 -04:00
echo Expecting sources to already be available at '%BUILD_LOCATION% \%BOOST_VERSION_FILENAME% '.
2021-07-13 15:09:10 -04:00
)
: : Build and install or just copy header files.
cd %BOOST_VERSION_FILENAME%
if !BOOST_BUILD_LIBRARIES! == 1 (
: : Bootstrap before build.
2022-10-20 12:53:38 -04:00
set LOG_FILE = %BUILD_LOCATION% \%BOOST_VERSION_FILENAME% _bootstrap.log
2021-07-13 15:09:10 -04:00
echo [!time!] Bootstrapping Boost %BOOST_VERSION% , see '!LOG_FILE!' for details...
2022-10-20 12:53:38 -04:00
call .\bootstrap.bat > !LOG_FILE! 2 >& 1
2021-07-13 15:09:10 -04:00
if not errorlevel 0 goto error
: : Set tool set to current UE tool set.
2022-10-20 12:53:38 -04:00
set BOOST_TOOLSET = msvc-14.3
2021-07-13 15:09:10 -04:00
: : Provide user config to provide tool set version and Python configuration.
2022-10-20 12:53:38 -04:00
set BOOST_USER_CONFIG = %BUILD_SCRIPT_LOCATION% \user-config.jam
2021-07-13 15:09:10 -04:00
: : Build all libraries.
2022-10-20 12:53:38 -04:00
set LOG_FILE = %BUILD_LOCATION% \%BOOST_VERSION_FILENAME% _build.log
2021-07-13 15:09:10 -04:00
echo [!time!] Building Boost %BOOST_VERSION% , see '!LOG_FILE!' for details...
2022-10-20 12:53:38 -04:00
.\b2.exe ^
--prefix=%INSTALL_LOCATION% ^
--includedir=%INSTALL_INCLUDE_LOCATION% ^
--libdir=%INSTALL_LIB_LOCATION% ^
-j8^
address-model=64^
threading=multi^
variant=release^
%BOOST_WITH_LIBRARIES% ^
--user-config=!BOOST_USER_CONFIG! ^
--hash^
--build-type=complete^
--layout=tagged^
--debug-configuration^
toolset=!BOOST_TOOLSET! ^
install^
> !LOG_FILE! 2 >& 1
2021-07-13 15:09:10 -04:00
if not errorlevel 0 goto error
) else (
: : Copy header files using robocopy to prevent issues with long file paths.
2022-10-20 12:53:38 -04:00
if not exist %INSTALL_LOCATION% (
mkdir %INSTALL_LOCATION%
2021-07-13 15:09:10 -04:00
)
2022-10-20 12:53:38 -04:00
set LOG_FILE = %BUILD_LOCATION% \%BOOST_VERSION_FILENAME% _robocopy.log
2021-07-13 15:09:10 -04:00
echo [!time!] Copying header files, see '!LOG_FILE!' for details...
set HEADERS_SOURCE = boost
2022-10-20 12:53:38 -04:00
set HEADERS_DESTINATION = %INSTALL_LOCATION% \include\boost
robocopy !HEADERS_SOURCE! !HEADERS_DESTINATION! /e > !LOG_FILE! 2 >& 1
2021-07-13 15:09:10 -04:00
set ROBOCOPY_SUCCESS = false
if errorlevel 0 set ROBOCOPY_SUCCESS = true
if errorlevel 1 set ROBOCOPY_SUCCESS = true
if !ROBOCOPY_SUCCESS! == " false " goto error
)
: : Print success confirmation and exit.
2022-10-20 12:53:38 -04:00
echo [!time!] Boost %BOOST_VERSION% installed to '%INSTALL_LOCATION% '.
2021-07-13 15:09:10 -04:00
echo [!time!] Done.
exit /B 0
: : Helper functions
: error
: : Print generic error message and exit.
echo [!time!] Last command returned an error!
echo [!time!] Abort.
exit /B 1
: usage
: : Print usage and exit.
echo Invalid arguments.
echo .
echo Usage:
echo .
echo BuildForWindows.bat ^< version^> [^< comma-separated-library-name-list^> ]
echo .
echo Usage examples:
echo .
2023-11-22 14:52:25 -05:00
echo BuildForWindows.bat 1.82.0
echo -- Installs Boost version 1.82.0 as header-only.
2021-07-13 15:09:10 -04:00
echo .
2023-11-22 14:52:25 -05:00
echo BuildForWindows.bat 1.82.0 iostreams,system,thread
echo -- Builds and installs Boost version 1.82.0 with iostreams, system, and thread libraries.
2021-07-13 15:09:10 -04:00
echo .
2023-11-22 14:52:25 -05:00
echo BuildForWindows.bat 1.82.0 all
echo -- Builds and installs Boost version 1.82.0 with all of its libraries.
2021-07-13 15:09:10 -04:00
exit /B 1
2023-11-22 14:52:25 -05:00
endlocal