Improve detection of the target architecture on Apple platforms. (#34054)

This commit is contained in:
Theodore Tsirpanis 2023-10-07 02:47:54 +03:00 committed by GitHub
parent 681e510ff1
commit cc97b4536a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -268,6 +268,39 @@ else()
set(Z_VCPKG_TARGET_TRIPLET_ARCH arm64)
elseif(CMAKE_GENERATOR STREQUAL "Visual Studio 17 2022")
set(Z_VCPKG_TARGET_TRIPLET_ARCH x64)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND DEFINED CMAKE_OSX_ARCHITECTURES)
list(LENGTH CMAKE_OSX_ARCHITECTURES Z_VCPKG_OSX_ARCH_COUNT)
if(Z_VCPKG_OSX_ARCH_COUNT EQUAL "0")
message(WARNING "Unable to determine target architecture. "
"Consider providing a value for the CMAKE_OSX_ARCHITECTURES cache variable. "
"Continuing without vcpkg.")
set(VCPKG_TOOLCHAIN ON)
cmake_policy(POP)
return()
endif()
if(Z_VCPKG_OSX_ARCH_COUNT GREATER "1")
message(WARNING "Detected more than one target architecture. Using the first one.")
endif()
list(GET CMAKE_OSX_ARCHITECTURES "0" Z_VCPKG_OSX_TARGET_ARCH)
if(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "arm64")
set(Z_VCPKG_TARGET_TRIPLET_ARCH arm64)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "arm64s")
set(Z_VCPKG_TARGET_TRIPLET_ARCH arm64s)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "armv7s")
set(Z_VCPKG_TARGET_TRIPLET_ARCH armv7s)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "armv7")
set(Z_VCPKG_TARGET_TRIPLET_ARCH arm)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "x86_64")
set(Z_VCPKG_TARGET_TRIPLET_ARCH x64)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "i386")
set(Z_VCPKG_TARGET_TRIPLET_ARCH x86)
else()
message(WARNING "Unable to determine target architecture, continuing without vcpkg.")
set(VCPKG_TOOLCHAIN ON)
cmake_policy(POP)
return()
endif()
else()
find_program(Z_VCPKG_CL cl)
if(Z_VCPKG_CL MATCHES "amd64/cl.exe$" OR Z_VCPKG_CL MATCHES "x64/cl.exe$")
@ -278,39 +311,6 @@ else()
set(Z_VCPKG_TARGET_TRIPLET_ARCH arm64)
elseif(Z_VCPKG_CL MATCHES "bin/cl.exe$" OR Z_VCPKG_CL MATCHES "x86/cl.exe$")
set(Z_VCPKG_TARGET_TRIPLET_ARCH x86)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND DEFINED CMAKE_SYSTEM_NAME AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(LENGTH CMAKE_OSX_ARCHITECTURES Z_VCPKG_OSX_ARCH_COUNT)
if(Z_VCPKG_OSX_ARCH_COUNT EQUAL "0")
message(WARNING "Unable to determine target architecture. "
"Consider providing a value for the CMAKE_OSX_ARCHITECTURES cache variable. "
"Continuing without vcpkg.")
set(VCPKG_TOOLCHAIN ON)
cmake_policy(POP)
return()
endif()
if(Z_VCPKG_OSX_ARCH_COUNT GREATER "1")
message(WARNING "Detected more than one target architecture. Using the first one.")
endif()
list(GET CMAKE_OSX_ARCHITECTURES "0" Z_VCPKG_OSX_TARGET_ARCH)
if(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "arm64")
set(Z_VCPKG_TARGET_TRIPLET_ARCH arm64)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "arm64s")
set(Z_VCPKG_TARGET_TRIPLET_ARCH arm64s)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "armv7s")
set(Z_VCPKG_TARGET_TRIPLET_ARCH armv7s)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "armv7")
set(Z_VCPKG_TARGET_TRIPLET_ARCH arm)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "x86_64")
set(Z_VCPKG_TARGET_TRIPLET_ARCH x64)
elseif(Z_VCPKG_OSX_TARGET_ARCH STREQUAL "i386")
set(Z_VCPKG_TARGET_TRIPLET_ARCH x86)
else()
message(WARNING "Unable to determine target architecture, continuing without vcpkg.")
set(VCPKG_TOOLCHAIN ON)
cmake_policy(POP)
return()
endif()
elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR
CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64" OR
CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "amd64")