Skip to content

Commit 099888b

Browse files
committed
build: support VCPKG_ROOT env in vcpkg_install.bat
If %VCPKG_ROOT% environment variable is set, check that the parent directory exists and throw an error if it does not. If %VCPKG_ROOT% is not set, set it to %cwd%\vcpkg, which was the previous behavior. Change all references to %cwd%\vcpkg to %VCPKG_ROOT%. Change the documentation in the top comment to refer to %VCPKG_ROOT%. This allows a developer to maintain his or her own vcpkg clone and not have to unnecessarily repeat the very time-consuming process of compiling the dependencies. Set ENV{VCPKG_ROOT} to the VCPKG_DIR default in CMakeLists.txt, because the cmake code does not support this yet, this is introduced in a subsequent commit. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
1 parent a180f08 commit 099888b

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

compat/vcbuild/vcpkg_install.bat

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@ REM This script installs the "vcpkg" source package manager and uses
44
REM it to build the third-party libraries that git requires when it
55
REM is built using MSVC.
66
REM
7-
REM [1] Install VCPKG.
8-
REM [a] Create <root>/compat/vcbuild/vcpkg/
7+
REM [1] Install VCPKG (unless already exists.)
8+
REM [a] Create %VCPKG_ROOT% defaulting to
9+
REM <root>/compat/vcbuild/vcpkg/.
910
REM [b] Download "vcpkg".
1011
REM [c] Compile using the currently installed version of VS.
11-
REM [d] Create <root>/compat/vcbuild/vcpkg/vcpkg.exe
12+
REM [d] Create %VCPKG_ROOT%/vcpkg.exe
1213
REM
13-
REM [2] Install third-party libraries.
14+
REM [2] Install third-party libraries (unless already installed.)
1415
REM [a] Download each (which may also install CMAKE).
1516
REM [b] Compile in RELEASE mode and install in:
16-
REM vcpkg/installed/<arch>/{bin,lib}
17+
REM %VCPKG_ROOT%/installed/<arch>/{bin,lib}
1718
REM [c] Compile in DEBUG mode and install in:
18-
REM vcpkg/installed/<arch>/debug/{bin,lib}
19+
REM %VCPKG_ROOT%/installed/<arch>/debug/{bin,lib}
1920
REM [d] Install headers in:
20-
REM vcpkg/installed/<arch>/include
21+
REM %VCPKG_ROOT%/installed/<arch>/include
2122
REM
2223
REM [3] Create a set of MAKE definitions for the top-level
2324
REM Makefile to allow "make MSVC=1" to find the above
2425
REM third-party libraries.
25-
REM [a] Write vcpkg/VCPGK-DEFS
26+
REM [a] Write %VCPKG_ROOT%/VCPGK-DEFS
2627
REM
2728
REM https://blogs.msdn.microsoft.com/vcblog/2016/09/19/vcpkg-a-tool-to-acquire-and-build-c-open-source-libraries-on-windows/
2829
REM https://github.com/Microsoft/vcpkg
@@ -40,7 +41,14 @@ REM ================================================================
4041
@FOR /F "delims=" %%D IN ("%~dp0") DO @SET cwd=%%~fD
4142
cd %cwd%
4243

43-
IF EXIST vcpkg\vcpkg.exe goto :install_libraries
44+
IF NOT DEFINED VCPKG_ROOT (
45+
set VCPKG_ROOT=%cwd%\vcpkg
46+
) ELSE (IF NOT EXIST %VCPKG_ROOT%\..\ (
47+
echo Invalid VCPKG_ROOT: %VCPKG_ROOT%, not under a valid directory. >&2
48+
exit /B 1
49+
))
50+
51+
IF EXIST %VCPKG_ROOT%\vcpkg.exe goto :install_libraries
4452

4553
git.exe version 2>nul
4654
IF ERRORLEVEL 1 (
@@ -50,29 +58,29 @@ REM ================================================================
5058
EXIT /B 1
5159
)
5260

53-
echo Fetching vcpkg in %cwd%vcpkg
54-
git.exe clone https://github.com/Microsoft/vcpkg vcpkg
61+
echo Fetching vcpkg in %VCPKG_ROOT%
62+
git.exe clone https://github.com/Microsoft/vcpkg %VCPKG_ROOT%
5563
IF ERRORLEVEL 1 ( EXIT /B 1 )
5664

57-
cd vcpkg
65+
cd %VCPKG_ROOT%
5866
echo Building vcpkg
5967
powershell -exec bypass scripts\bootstrap.ps1
6068
IF ERRORLEVEL 1 ( EXIT /B 1 )
6169

62-
echo Successfully installed %cwd%vcpkg\vcpkg.exe
70+
echo Successfully installed %VCPKG_ROOT%\vcpkg.exe
6371

6472
:install_libraries
6573

6674
echo Installing third-party libraries(%arch%)...
6775
FOR %%i IN (zlib expat libiconv openssl libssh2 curl) DO (
68-
cd %cwd%vcpkg
76+
cd %VCPKG_ROOT%
6977
IF NOT EXIST "packages\%%i_%arch%" CALL :sub__install_one %%i
7078
IF ERRORLEVEL 1 ( EXIT /B 1 )
7179
)
7280

7381
:install_defines
7482
cd %cwd%
75-
SET inst=%cwd%vcpkg\installed\%arch%
83+
SET inst=%VCPKG_ROOT%\installed\%arch%
7684

7785
echo vcpkg_inc=-I"%inst%\include">VCPKG-DEFS
7886
echo vcpkg_rel_lib=-L"%inst%\lib">>VCPKG-DEFS

contrib/buildsystems/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ endif()
6868

6969
if(USE_VCPKG)
7070
set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg")
71+
set(ENV{VCPKG_ROOT} "${VCPKG_DIR}")
7172
message("WIN32: ${WIN32}") # show its underlying text values
7273
message("VCPKG_DIR: ${VCPKG_DIR}")
7374
message("VCPKG_ARCH: ${VCPKG_ARCH}") # maybe unset

0 commit comments

Comments
 (0)