if(TRANSLATIONS_ONLY) return() endif() if(NOT DEFINED VCPKG_TARGET_TRIPLET) if(NOT WIN32) return() endif() # Check if we are in an MSVC environment. find_program(cl_exe_path NAME cl.exe HINTS ENV PATH) if($ENV{CXX} MATCHES "cl.exe$" OR cl_exe_path) # Infer the architecture from the LIB folders. foreach(LIB $ENV{LIB}) if(${LIB} MATCHES "x64$") set(VBAM_VCPKG_PLATFORM "x64-windows-static") break() endif() if(${LIB} MATCHES "x86$") set(VBAM_VCPKG_PLATFORM "x86-windows-static") break() endif() if(${LIB} MATCHES "ARM64$") set(VBAM_VCPKG_PLATFORM "arm64-windows-static") break() endif() endforeach() # If all else fails, try to use a sensible default. if(NOT DEFINED VBAM_VCPKG_PLATFORM) set(VBAM_VCPKG_PLATFORM "x64-windows-static") endif() unset(cl_exe_path) elseif (NOT DEFINED CMAKE_CXX_COMPILER) # No way to infer the compiler. return() elseif(${CMAKE_CXX_COMPILER} MATCHES "clang-cl.exe$" OR ${CMAKE_CXX_COMPILER} MATCHES "clang-cl$") # For stand-alone clang-cl, assume x64. set(VBAM_VCPKG_PLATFORM "x64-windows-static") endif() if (NOT DEFINED VBAM_VCPKG_PLATFORM) # Probably not an MSVC environment. return() endif() set(VCPKG_TARGET_TRIPLET ${VBAM_VCPKG_PLATFORM} CACHE STRING "Vcpkg target triplet (ex. x64-windows-static)" FORCE) message(STATUS "Inferred VCPKG_TARGET_TRIPLET=${VCPKG_TARGET_TRIPLET}") endif() function(vcpkg_check_git_status git_status) # The VS vcpkg component cannot be written to without elevation. if(NOT git_status EQUAL 0 AND NOT VCPKG_ROOT MATCHES "Visual Studio") 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() endfunction() function(vcpkg_get_first_upgrade vcpkg_exe) # First get the list of upgraded ports. execute_process( COMMAND ${vcpkg_exe} upgrade OUTPUT_VARIABLE upgradable OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET WORKING_DIRECTORY ${VCPKG_ROOT} ) string(REGEX REPLACE "\r?\n" ";" upgrade_lines "${upgradable}") unset(first_upgrade) foreach(line ${upgrade_lines}) if(line MATCHES "^ [* ] [^ ]*:") string(REGEX REPLACE "^ [* ] ([^[]+).*" "\\1" pkg ${line}) string(REGEX REPLACE "^[^:]+:(.+)$" "\\1" triplet ${line}) if(triplet STREQUAL "${VCPKG_TARGET_TRIPLET}") # Prefer upgrading zlib before anything else. if(NOT first_upgrade OR pkg MATCHES zlib) set(first_upgrade ${pkg}) endif() endif() endif() endforeach() if(DEFINED first_upgrade) set(first_upgrade ${first_upgrade} PARENT_SCOPE) endif() endfunction() function(vcpkg_deps_fixup vcpkg_exe) # Get installed list. execute_process( COMMAND ${vcpkg_exe} list OUTPUT_VARIABLE pkg_list OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET WORKING_DIRECTORY ${VCPKG_ROOT} ) # 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} WORKING_DIRECTORY ${VCPKG_ROOT} ) endif() endfunction() function(vcpkg_is_installed vcpkg_exe pkg_name pkg_ver pkg_triplet powershell outvar) set(${outvar} FALSE PARENT_SCOPE) unset(CMAKE_MATCH_1) string(REGEX REPLACE "-r([0-9]+)\$" "" pkg_ver ${pkg_ver}) set(pkg_rev ${CMAKE_MATCH_1}) string(REPLACE "-" "." pkg_ver ${pkg_ver}) if(NOT DEFINED VCPKG_INSTALLED_COUNT) if(VCPKG_ROOT MATCHES "Visual Studio") execute_process( COMMAND ${powershell} -executionpolicy bypass -noprofile -command "import-module '${CMAKE_BINARY_DIR}/vcpkg-binpkg/vcpkg-binpkg.psm1'; vcpkg-list" OUTPUT_VARIABLE vcpkg_list_text ) else() execute_process( COMMAND ${vcpkg_exe} list OUTPUT_VARIABLE vcpkg_list_text ERROR_QUIET ) endif() string(REGEX REPLACE "\r?\n" ";" vcpkg_list_raw "${vcpkg_list_text}") set(VCPKG_INSTALLED_COUNT 0 PARENT_SCOPE) foreach(pkg ${vcpkg_list_raw}) if(NOT pkg MATCHES "^([^:[]+)[^:]*:([^ ]+) +([0-9][^ ]*) +.*\$") continue() endif() set(inst_pkg_name ${CMAKE_MATCH_1}) set(inst_pkg_ver ${CMAKE_MATCH_3}) set(inst_pkg_triplet ${CMAKE_MATCH_2}) unset(CMAKE_MATCH_1) string(REGEX REPLACE "#([0-9]+)\$" "" inst_pkg_ver ${inst_pkg_ver}) if(CMAKE_MATCH_1) set(inst_pkg_rev ${CMAKE_MATCH_1}) else() set(inst_pkg_rev FALSE) endif() string(REPLACE "-" "." inst_pkg_ver ${inst_pkg_ver}) list(APPEND VCPKG_INSTALLED ${inst_pkg_name} ${inst_pkg_ver} ${inst_pkg_rev} ${inst_pkg_triplet}) math(EXPR VCPKG_INSTALLED_COUNT "${VCPKG_INSTALLED_COUNT} + 1") endforeach() set(VCPKG_INSTALLED ${VCPKG_INSTALLED} PARENT_SCOPE) set(VCPKG_INSTALLED_COUNT ${VCPKG_INSTALLED_COUNT} PARENT_SCOPE) endif() if(NOT VCPKG_INSTALLED_COUNT GREATER 0) return() endif() math(EXPR idx_max "(${VCPKG_INSTALLED_COUNT} - 1) * 4") foreach(idx RANGE 0 ${idx_max} 4) math(EXPR idx_ver "${idx} + 1") math(EXPR idx_rev "${idx} + 2") math(EXPR idx_triplet "${idx} + 3") list(GET VCPKG_INSTALLED ${idx} inst_pkg_name) list(GET VCPKG_INSTALLED ${idx_ver} inst_pkg_ver) list(GET VCPKG_INSTALLED ${idx_rev} inst_pkg_rev) list(GET VCPKG_INSTALLED ${idx_triplet} inst_pkg_triplet) if(NOT inst_pkg_triplet STREQUAL pkg_triplet) continue() endif() if(inst_pkg_name STREQUAL pkg_name AND pkg_ver VERSION_LESS inst_pkg_ver OR (pkg_ver VERSION_EQUAL inst_pkg_ver AND ((NOT pkg_rev AND NOT inst_pkg_rev) OR (pkg_rev AND inst_pkg_rev AND (NOT pkg_rev GREATER inst_pkg_rev))))) set(${outvar} TRUE PARENT_SCOPE) return() endif() endforeach() endfunction() function(get_binary_packages vcpkg_exe) set(binary_packages_installed FALSE PARENT_SCOPE) unset(triplets) unset(host_triplet) # Determine host triplet for vcpkg build dependencies if(WIN32) if($ENV{PROCESSOR_ARCHITECTURE} MATCHES "[Aa][Rr][Mm]64") set(host_triplet "arm64-windows") elseif($ENV{PROCESSOR_ARCHITECTURE} MATCHES "[Aa][Mm][Dd]64|[Xx]64") set(host_triplet "x64-windows") else() set(host_triplet "x86-windows") endif() endif() if(DEFINED host_triplet) list(APPEND triplets ${host_triplet}) endif() list(APPEND triplets ${VCPKG_TARGET_TRIPLET}) foreach(triplet ${triplets}) file( DOWNLOAD "https://nightly.visualboyadvance-m.org/vcpkg/${triplet}/" "${CMAKE_BINARY_DIR}/binary_package_list_${triplet}.html" STATUS pkg_list_status ) list(GET pkg_list_status 1 pkg_list_error) list(GET pkg_list_status 0 pkg_list_status) if(NOT pkg_list_status EQUAL 0) message(STATUS "Failed to download vcpkg binary package list: ${pkg_list_status} - ${pkg_list_error}") return() endif() endforeach() unset(binary_packages) foreach(triplet ${triplets}) file(READ "${CMAKE_BINARY_DIR}/binary_package_list_${triplet}.html" raw_html) string(REGEX MATCHALL "