Properly detect architecture for Qt

This commit is contained in:
wheremyfoodat 2023-09-27 19:51:06 +03:00
commit 6dff2c38c8
2 changed files with 31 additions and 2 deletions

View file

@ -65,8 +65,6 @@ if(ENABLE_DISCORD_RPC AND NOT ANDROID)
endif() endif()
if (ENABLE_QT_GUI) if (ENABLE_QT_GUI)
set(ARCHITECTURE "x86_64")
if (NOT USE_SYSTEM_QT) if (NOT USE_SYSTEM_QT)
# Shout-out to whoever made this # Shout-out to whoever made this
include(third_party/CMakeModules/install_qt.cmake) include(third_party/CMakeModules/install_qt.cmake)

View file

@ -4,6 +4,22 @@
# Params: # Params:
# target: Qt dependency to install. Specify a version number to download Qt, or "tools_(name)" for a specific build tool. # target: Qt dependency to install. Specify a version number to download Qt, or "tools_(name)" for a specific build tool.
function(download_qt target) function(download_qt target)
# Detect architecture to find which Qt version to fetch
if (CMAKE_OSX_ARCHITECTURES)
set(ARCHITECTURE "${CMAKE_OSX_ARCHITECTURES}")
elseif (MSVC)
detect_architecture("_M_AMD64" x86_64)
detect_architecture("_M_IX86" x86)
detect_architecture("_M_ARM" arm)
detect_architecture("_M_ARM64" arm64)
else()
detect_architecture("__x86_64__" x86_64)
detect_architecture("__i386__" x86)
detect_architecture("__arm__" arm)
detect_architecture("__aarch64__" arm64)
endif()
message(STATUS "Qt Downloader: Detected target architecture: ${ARCHITECTURE}")
if (target MATCHES "tools_.*") if (target MATCHES "tools_.*")
set(DOWNLOAD_QT_TOOL ON) set(DOWNLOAD_QT_TOOL ON)
else() else()
@ -102,3 +118,18 @@ endfunction()
function(get_external_prefix lib_name prefix_var) function(get_external_prefix lib_name prefix_var)
set(${prefix_var} "${CMAKE_BINARY_DIR}/externals/${lib_name}" PARENT_SCOPE) set(${prefix_var} "${CMAKE_BINARY_DIR}/externals/${lib_name}" PARENT_SCOPE)
endfunction() endfunction()
function(detect_architecture symbol arch)
include(CheckSymbolExists)
if (NOT DEFINED ARCHITECTURE)
set(CMAKE_REQUIRED_QUIET 1)
check_symbol_exists("${symbol}" "" ARCHITECTURE_${arch})
unset(CMAKE_REQUIRED_QUIET)
# The output variable needs to be unique across invocations otherwise
# CMake's crazy scope rules will keep it defined
if (ARCHITECTURE_${arch})
set(ARCHITECTURE "${arch}" PARENT_SCOPE)
endif()
endif()
endfunction()