From 9ce95042b01901a09aec20d5f4c858f339a2b9a8 Mon Sep 17 00:00:00 2001 From: Johannes Demel Date: Sat, 2 Mar 2024 22:53:58 +0100 Subject: [PATCH] cmake: Fix 64bit host CPU detection In cases where we don't cross-compile, we might want to detect if a CPU is 32bit or 64bit. CMake provides functionality for this case starting in CMake 3.10. Let's use it. Ubuntu 20.04 uses CMake 3.16. From the top of my head, this is the oldest supported distribution. Debian buster ships with CMake 3.13. Signed-off-by: Johannes Demel --- CMakeLists.txt | 4 +++- lib/CMakeLists.txt | 9 ++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6401845..8d55fa0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,9 @@ ######################################################################## # Project setup ######################################################################## -cmake_minimum_required(VERSION 3.8) +# We use `IS_64BIT now: https://cmake.org/cmake/help/latest/command/cmake_host_system_information.html +cmake_minimum_required(VERSION 3.10) + set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose build type: None Debug Release RelWithDebInfo MinSizeRel") diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 074f46f8..b1c407ad 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -255,17 +255,16 @@ endif() ######################################################################## if(NOT CROSSCOMPILE_MULTILIB AND CPU_IS_x86) include(CheckTypeSize) - check_type_size("void*[8]" SIZEOF_CPU BUILTIN_TYPES_ONLY) - if(${SIZEOF_CPU} EQUAL 64) + cmake_host_system_information(RESULT ASSUME_64BIT_HOST QUERY IS_64BIT) + if(ASSUME_64BIT_HOST) overrule_arch(32 "CPU width is 64 bits") - endif() - if(${SIZEOF_CPU} EQUAL 32) + else() overrule_arch(64 "CPU width is 32 bits") endif() #MSVC 64 bit does not have MMX, overrule it if(MSVC) - if(${SIZEOF_CPU} EQUAL 64) + if(ASSUME_64BIT_HOST) overrule_arch(mmx "No MMX for Win64") endif() force_arch(sse "Built-in for MSVC > 2013")