From 6dff2c38c809f57b23062d6433be1584c362a21a Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Wed, 27 Sep 2023 19:51:06 +0300 Subject: [PATCH] Properly detect architecture for Qt --- CMakeLists.txt | 2 -- third_party/CMakeModules/install_qt.cmake | 31 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f882b91..89565045 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,8 +65,6 @@ if(ENABLE_DISCORD_RPC AND NOT ANDROID) endif() if (ENABLE_QT_GUI) - set(ARCHITECTURE "x86_64") - if (NOT USE_SYSTEM_QT) # Shout-out to whoever made this include(third_party/CMakeModules/install_qt.cmake) diff --git a/third_party/CMakeModules/install_qt.cmake b/third_party/CMakeModules/install_qt.cmake index 95f53b81..93cd3fe4 100644 --- a/third_party/CMakeModules/install_qt.cmake +++ b/third_party/CMakeModules/install_qt.cmake @@ -4,6 +4,22 @@ # Params: # target: Qt dependency to install. Specify a version number to download Qt, or "tools_(name)" for a specific build tool. 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_.*") set(DOWNLOAD_QT_TOOL ON) else() @@ -101,4 +117,19 @@ endfunction() function(get_external_prefix lib_name prefix_var) set(${prefix_var} "${CMAKE_BINARY_DIR}/externals/${lib_name}" PARENT_SCOPE) +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() \ No newline at end of file