Skip to content

Commit

Permalink
cmake: Fix 64bit host CPU detection
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jdemel committed Mar 30, 2024
1 parent 8a015bb commit 881a839
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 4 additions & 5 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 881a839

Please sign in to comment.