vcpkg でzlib のビルドに失敗する現象とその解決策

環境

現象

私の環境では、vcpkg によるzlib のビルドが上手くいきませんでした。 コンソールの出力は以下のものでした。

$ vcpkg install zlib:x64-windows
The following packages will be built and installed:
    zlib[core]:x64-windows
Starting package 1/1: zlib:x64-windows
Building package zlib[core]:x64-windows...
-- Using cached E:/app/vcpkg/downloads/zlib1211.tar.gz
-- Using source at E:/app/vcpkg/buildtrees/zlib/src/1.2.11-f690224aeb
-- Configuring x64-windows
-- Building x64-windows-dbg
CMake Error at scripts/cmake/vcpkg_build_cmake.cmake:175 (message):
    Command failed: C:/Program Files/CMake/bin/cmake.exe;--build;.;--config;Debug;--target;install;--;-v;-j1
    Working Directory: E:/app/vcpkg/buildtrees/zlib/x64-windows-dbg
    See logs for more information:
      E:\app\vcpkg\buildtrees\zlib\install-x64-windows-dbg-out.log

Call Stack (most recent call first):
  scripts/cmake/vcpkg_install_cmake.cmake:24 (vcpkg_build_cmake)
  ports/zlib/portfile.cmake:32 (vcpkg_install_cmake)
  scripts/ports.cmake:71 (include)


Error: Building package zlib:x64-windows failed with: BUILD_FAILED
Please ensure you're using the latest portfiles with `.\vcpkg update`, then
submit an issue at https://github.com/Microsoft/vcpkg/issues including:
  Package: zlib:x64-windows
  Vcpkg version: 2018.11.23-nohash

Additionally, attach any relevant sections from the log files above.

しかもビルドに失敗するだけでなく、PC の動作が重くなる症状も現れました。 重くなる症状はPC を再起動すれば治りますが、 zlib がビルドできないのはOpenCV などのzlib に依存するライブラリがビルドできなくなるので解決したい問題です。

解決策

Visual Studio の英語言語パックをインストールすることでビルドできるようになりました。

ビルドに失敗する原因について調べたところ、以下のissue のcomment にたどり着きました。

This problem(many D8000 errors) seems to only occur in non-English versions of Vision Studio, and can be solved by installing the English language pack.

これに従って、Visual Studio の英語言語パックをインストールし、 (念のため)Visual Studio の使用言語を英語に変更しました。 これで再び$ vcpkg install zlib:x64-windows を実行したところ、ライブラリのビルドに成功しました。
ちなみに私の環境でvcpkg コマンドが完了するまでに3時間弱かかりました。 ビルドに成功してもPC が重くなります。 どうやらこれは別の問題みたいです。

おまけ

ちなみに上記の方法を試すより先に、以下のissue にたどり着きました。

'vcpkg install zlib' CMake integration test failed · Issue #4817 · Microsoft/vcpkg · GitHub

その中のコメントによると、Windows SDK のバージョンに関係しているかもしれないとのことでしたので Windows SDK 10.0.10240 をインストールしました。 しかしzlib のビルドはうまくいきませんでした。
issue のやりとりを最後まで確認すると、 Windows SDK のバージョンではなく、Visual C++ 2010 Redistributable のバージョンのことだったようです。
ちゃんと最後まで読まないとダメですね。