Vcpkg fixes.

Fix vcpkg upgrades to work with the current vcpkg master.

When upgrading zlib, remove all optional deps first, because everything
depends on zlib and this can overrun the appveyor 1hr time limit.

Make SFML an optional dep too, like ffmpeg.

Reduce the vcpkg install time limit to 20 minutes, otherwise it may try
to build wxWidgets and ffmpeg and overrun the 1hr time limit.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2020-08-26 10:07:04 +00:00
parent 3ee26c0de6
commit 5081ae44e5
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
2 changed files with 69 additions and 33 deletions

View File

@ -17,6 +17,14 @@ if(COMMAND cmake_policy)
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW) # set CMAKE_PROJECT_VERSION*
endif()
if(POLICY CMP0011)
cmake_policy(SET CMP0011 NEW) # Policy PUSH/POP for scripts.
endif()
if(POLICY CMP0012)
cmake_policy(SET CMP0012 NEW) # Saner if() behavior.
endif()
endif()
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
@ -29,8 +37,12 @@ if(TAG_RELEASE)
include(MakeReleaseCommitAndTag)
endif()
set(VCPKG_DEPS zlib SDL2 SFML gettext wxWidgets)
set(VCPKG_DEPS_OPTIONAL ffmpeg ENABLE_FFMPEG)
set(VCPKG_DEPS zlib SDL2 gettext wxWidgets)
set(VCPKG_DEPS_OPTIONAL
SFML ENABLE_LINK
ffmpeg ENABLE_FFMPEG
)
include(Set-Toolchain-vcpkg)

View File

@ -1,3 +1,7 @@
if(POLICY CMP0012)
cmake_policy(SET CMP0012 NEW) # Saner if() behavior.
endif()
if(NOT DEFINED VCPKG_TARGET_TRIPLET)
return()
endif()
@ -42,20 +46,14 @@ function(vcpkg_get_first_upgrade vcpkg_exe)
string(REGEX REPLACE "\r?\n" ";" upgrade_lines "${upgradable}")
unset(first_upgrade)
foreach(line ${upgrade_lines})
if(line MATCHES "^ [* ] ")
string(REGEX REPLACE "^ [* ] " "" pkg ${line})
if(line MATCHES "^ [* ] [^ ]*:")
string(REGEX REPLACE "^ [* ] ([^[]+).*" "\\1" pkg ${line})
string(REGEX REPLACE "^[^:]+:(.+)$" "\\1" triplet ${line})
# Check if package is up-to-date, but would be rebuilt due to other dependencies.
execute_process(
COMMAND ${vcpkg_exe} upgrade ${pkg}
OUTPUT_VARIABLE pkg_upgrade
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
WORKING_DIRECTORY ${VCPKG_ROOT}
)
if(NOT pkg_upgrade MATCHES up-to-date)
if(triplet STREQUAL "${VCPKG_TARGET_TRIPLET}")
# Prefer upgrading zlib before anything else.
if(NOT first_upgrade OR pkg MATCHES zlib)
set(first_upgrade ${pkg})
@ -64,7 +62,9 @@ function(vcpkg_get_first_upgrade vcpkg_exe)
endif()
endforeach()
if(DEFINED first_upgrade)
set(first_upgrade ${first_upgrade} PARENT_SCOPE)
endif()
endfunction()
function(vcpkg_deps_fixup vcpkg_exe)
@ -80,12 +80,30 @@ function(vcpkg_deps_fixup vcpkg_exe)
# If libvorbis is NOT installed but libogg is, remove libvorbis recursively.
if(pkg_list MATCHES libogg AND (NOT pkg_list MATCHES libvorbis))
execute_process(
COMMAND "${vcpkg_exe}" remove --recurse libogg:${VCPKG_TARGET_TRIPLET}
COMMAND ${vcpkg_exe} remove --recurse libogg:${VCPKG_TARGET_TRIPLET}
WORKING_DIRECTORY ${VCPKG_ROOT}
)
endif()
endfunction()
function(vcpkg_remove_optional_deps vcpkg_exe)
list(LENGTH VCPKG_DEPS_OPTIONAL optionals_list_len)
math(EXPR optionals_list_last "${optionals_list_len} - 1")
unset(deps)
foreach(i RANGE 0 ${optionals_list_last} 2)
list(GET VCPKG_DEPS_OPTIONAL ${i} dep)
list(APPEND deps ${dep}:${VCPKG_TARGET_TRIPLET})
endforeach()
execute_process(
COMMAND ${vcpkg_exe} remove --recurse ${deps}
WORKING_DIRECTORY ${VCPKG_ROOT}
)
endfunction()
function(vcpkg_set_toolchain)
if(NOT DEFINED ENV{VCPKG_ROOT})
if(WIN32)
@ -209,8 +227,8 @@ function(vcpkg_set_toolchain)
vcpkg_seconds()
set(began ${seconds})
# Limit total installation time to 30 minutes to not overrun CI time limit.
math(EXPR time_limit "${began} + (30 * 60)")
# Limit total installation time to 20 minutes to not overrun CI time limit.
math(EXPR time_limit "${began} + (20 * 60)")
vcpkg_deps_fixup("${vcpkg_exe}")
@ -220,6 +238,26 @@ function(vcpkg_set_toolchain)
WORKING_DIRECTORY ${VCPKG_ROOT}
)
# If ports have been updated, and there is time, rebuild cache one at a time to not overrun the CI time limit.
vcpkg_seconds()
if(seconds LESS time_limit)
vcpkg_get_first_upgrade(${vcpkg_exe})
if(DEFINED first_upgrade)
# If we have to upgrade zlib, remove optional deps first so that
# the build doesn't overrun the CI time limit.
if(first_upgrade STREQUAL "zlib")
vcpkg_remove_optional_deps(${vcpkg_exe})
endif()
execute_process(
COMMAND ${vcpkg_exe} upgrade --no-dry-run "${first_upgrade}:${VCPKG_TARGET_TRIPLET}"
WORKING_DIRECTORY ${VCPKG_ROOT}
)
endif()
endif()
# Install optional deps, within time limit.
list(LENGTH VCPKG_DEPS_OPTIONAL optionals_list_len)
math(EXPR optionals_list_last "${optionals_list_len} - 1")
@ -234,7 +272,7 @@ function(vcpkg_set_toolchain)
vcpkg_seconds()
if(seconds LESS time_limit AND (val OR val STREQUAL ""))
if("${val}" OR (seconds LESS time_limit AND ("${val}" OR "${val}" STREQUAL "")))
set(dep_qualified "${dep}:${VCPKG_TARGET_TRIPLET}")
execute_process(
@ -248,20 +286,6 @@ function(vcpkg_set_toolchain)
endif()
endforeach()
# If ports have been updated, and there is time, rebuild cache one at a time to not overrun the CI time limit.
vcpkg_seconds()
if(seconds LESS time_limit)
vcpkg_get_first_upgrade(${vcpkg_exe})
if(DEFINED first_upgrade)
execute_process(
COMMAND ${vcpkg_exe} upgrade --no-dry-run ${first_upgrade}
WORKING_DIRECTORY ${VCPKG_ROOT}
)
endif()
endif()
if(WIN32 AND VCPKG_TARGET_TRIPLET MATCHES x64 AND CMAKE_GENERATOR MATCHES "Visual Studio")
set(CMAKE_GENERATOR_PLATFORM x64 CACHE STRING "visual studio build architecture" FORCE)
endif()