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 7ecd6c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
18 changes: 11 additions & 7 deletions 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)
cmake_minimum_required(VERSION 3.10)

# We use `IS_64BIT now: https://cmake.org/cmake/help/latest/command/cmake_host_system_information.html
set(CMAKE_BUILD_TYPE
${CMAKE_BUILD_TYPE}
CACHE STRING "Choose build type: None Debug Release RelWithDebInfo MinSizeRel")
Expand Down Expand Up @@ -82,7 +84,7 @@ message(STATUS "Build type set to ${CMAKE_BUILD_TYPE}.")

set(VERSION_INFO_MAJOR_VERSION 3)
set(VERSION_INFO_MINOR_VERSION 1)
set(VERSION_INFO_MAINT_VERSION 2)
set(VERSION_INFO_MAINT_VERSION 0)
include(VolkVersion) #setup version info

math(EXPR VOLK_VERSION_DECIMAL "${VERSION_INFO_MAJOR_VERSION} * 10000
Expand Down Expand Up @@ -213,30 +215,32 @@ add_subdirectory(docs)
########################################################################
# Detect /lib versus /lib64
########################################################################
include(GNUInstallDirs)
if(${CMAKE_INSTALL_LIBDIR} MATCHES lib64)
set(LIB_SUFFIX 64)
endif()

########################################################################
# Setup the package config file
########################################################################
#set variables found in the pc.in file
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(libdir "\${exec_prefix}/lib${LIB_SUFFIX}")
set(includedir "\${prefix}/include")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tmpl/volk.pc.in
${CMAKE_CURRENT_BINARY_DIR}/volk.pc @ONLY)

install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/volk.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
DESTINATION lib${LIB_SUFFIX}/pkgconfig
COMPONENT "volk_devel")

########################################################################
# Install all headers in the include directories
########################################################################
set(VOLK_RUNTIME_DIR bin)
set(VOLK_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR})
set(VOLK_LIBRARY_DIR lib${LIB_SUFFIX})
set(VOLK_INCLUDE_DIR include)

install(
Expand Down Expand Up @@ -318,7 +322,7 @@ configure_file(${CMAKE_SOURCE_DIR}/cmake/Modules/VolkConfigVersion.cmake.in
########################################################################

if(NOT CMAKE_MODULES_DIR)
set(CMAKE_MODULES_DIR ${CMAKE_INSTALL_LIBDIR}/cmake)
set(CMAKE_MODULES_DIR lib${LIB_SUFFIX}/cmake)
endif(NOT CMAKE_MODULES_DIR)

install(
Expand Down
15 changes: 7 additions & 8 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 Expand Up @@ -592,8 +591,8 @@ set_target_properties(volk PROPERTIES DEFINE_SYMBOL "volk_EXPORTS")
install(
TARGETS volk
EXPORT VOLK-export
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT "volk_runtime" # .so file
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT "volk_devel" # .lib file
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_runtime" # .so file
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_devel" # .lib file
RUNTIME DESTINATION bin COMPONENT "volk_runtime" # .dll file
)

Expand Down Expand Up @@ -635,7 +634,7 @@ if(ENABLE_STATIC_LIBS)
install(
TARGETS volk_static
EXPORT VOLK-export
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT "volk_devel")
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT "volk_devel")
endif(ENABLE_STATIC_LIBS)

########################################################################
Expand Down

0 comments on commit 7ecd6c6

Please sign in to comment.