From c06e3bf3fcd1b5dc1ff1912017586e2eb0966ee9 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Mon, 21 Oct 2019 13:58:55 +0000 Subject: [PATCH] cmake: update vcpkg mod for appveyor build cache On appveyor we only cache the `vcpkg/installed` directory, so vcpkg itself still needs to be pulled from git. Also update vcpkg from git if it has already been cloned, and always rebuild vcpkg itself. Signed-off-by: Rafael Kitover --- cmake/Set-Toolchain-vcpkg.cmake | 58 +++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/cmake/Set-Toolchain-vcpkg.cmake b/cmake/Set-Toolchain-vcpkg.cmake index 43b31169..fd82240e 100644 --- a/cmake/Set-Toolchain-vcpkg.cmake +++ b/cmake/Set-Toolchain-vcpkg.cmake @@ -16,25 +16,55 @@ if(VCPKG_TARGET_TRIPLET) ) if(NOT git_status EQUAL 0) - message(FATAL_ERROR "Error cloning vcpkg, please make sure git for windows is installed correctly, it can be installed from Visual Studio components") + message(FATAL_ERROR "Error cloning vcpkg from git, please make sure git for windows is installed correctly, it can be installed from Visual Studio components") + endif() + else() + # this is the case when we cache vcpkg/installed with the appveyor build cache + if(NOT EXISTS ${VCPKG_ROOT}/.git) + set(git_commands + "git init" + "git remote add origin https://github.com/microsoft/vcpkg.git" + "git fetch --all --prune" + "git reset --hard origin/master" + "git branch --set-upstream-to=origin/master master" + ) + foreach(git_command ${git_commands}) + separate_arguments(git_command) + + execute_process( + COMMAND ${git_command} + RESULT_VARIABLE git_status + WORKING_DIRECTORY ${VCPKG_ROOT} + ) + + if(NOT git_status EQUAL 0) + break() + endif() + endforeach() + else() + execute_process( + COMMAND git pull --rebase + RESULT_VARIABLE git_status + WORKING_DIRECTORY ${VCPKG_ROOT} + ) + endif() + + if(NOT git_status EQUAL 0) + message(FATAL_ERROR "Error updating vcpkg from git, please make sure git for windows is installed correctly, it can be installed from Visual Studio components") endif() endif() - # build vcpkg if not built + # build latest vcpkg if(WIN32) - if(NOT EXISTS ${VCPKG_ROOT}/vcpkg.exe) - execute_process( - COMMAND bootstrap-vcpkg.bat - WORKING_DIRECTORY ${VCPKG_ROOT} - ) - endif() + execute_process( + COMMAND bootstrap-vcpkg.bat + WORKING_DIRECTORY ${VCPKG_ROOT} + ) else() - if(NOT EXISTS ${VCPKG_ROOT}/vcpkg) - execute_process( - COMMAND ./bootstrap-vcpkg.sh - WORKING_DIRECTORY ${VCPKG_ROOT} - ) - endif() + execute_process( + COMMAND ./bootstrap-vcpkg.sh + WORKING_DIRECTORY ${VCPKG_ROOT} + ) endif() foreach(pkg ${VCPKG_DEPS})