mirror of
https://github.com/google/cpu_features.git
synced 2025-04-27 23:22:31 +02:00
Use Cmake macros to detect getauxval and dlopen
This commit is contained in:
parent
e8e5610fc4
commit
122b067087
@ -20,6 +20,12 @@ option(BUILD_SHARED_LIBS "Build library as shared." OFF)
|
|||||||
# library : cpu_features
|
# library : cpu_features
|
||||||
#
|
#
|
||||||
|
|
||||||
|
include (CheckIncludeFile)
|
||||||
|
include (CheckSymbolExists)
|
||||||
|
|
||||||
|
check_symbol_exists(getauxval sys/auxv.h HAVE_STRONG_GETAUXVAL)
|
||||||
|
check_include_file(dlfcn.h HAVE_DLFCN_H)
|
||||||
|
|
||||||
set(_HDRS
|
set(_HDRS
|
||||||
include/cpu_features_macros.h
|
include/cpu_features_macros.h
|
||||||
)
|
)
|
||||||
@ -55,7 +61,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
|
|||||||
list(APPEND _HDRS include/cpuinfo_ppc.h)
|
list(APPEND _HDRS include/cpuinfo_ppc.h)
|
||||||
list(APPEND _SRCS src/cpuinfo_ppc.c)
|
list(APPEND _SRCS src/cpuinfo_ppc.c)
|
||||||
else()
|
else()
|
||||||
message(SEND_ERROR "Unsupported architectures ${CMAKE_SYSTEM_PROCESSOR}")
|
message(FATAL_ERROR "Unsupported architectures ${CMAKE_SYSTEM_PROCESSOR}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library(cpu_features
|
add_library(cpu_features
|
||||||
@ -71,8 +77,11 @@ target_include_directories(cpu_features
|
|||||||
include/internal
|
include/internal
|
||||||
)
|
)
|
||||||
set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${_HDRS}")
|
set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${_HDRS}")
|
||||||
target_compile_definitions(cpu_features
|
target_compile_definitions(cpu_features PUBLIC
|
||||||
PUBLIC STACK_LINE_READER_BUFFER_SIZE=1024)
|
STACK_LINE_READER_BUFFER_SIZE=1024
|
||||||
|
HAVE_STRONG_GETAUXVAL=${HAVE_STRONG_GETAUXVAL}
|
||||||
|
HAVE_DLFCN_H=${HAVE_DLFCN_H}
|
||||||
|
)
|
||||||
target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS})
|
target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS})
|
||||||
|
|
||||||
# The use of shared libraries is discouraged.
|
# The use of shared libraries is discouraged.
|
||||||
|
23
src/hwcaps.c
23
src/hwcaps.c
@ -31,22 +31,18 @@
|
|||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CPU_FEATURES_ARCH_MIPS) || defined(CPU_FEATURES_ARCH_ANY_ARM)
|
|
||||||
#define HWCAPS_ANDROID_MIPS_OR_ARM
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) && \
|
|
||||||
!defined(HWCAPS_ANDROID_MIPS_OR_ARM)
|
|
||||||
#define HWCAPS_REGULAR_LINUX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Implementation of GetElfHwcapFromGetauxval
|
// Implementation of GetElfHwcapFromGetauxval
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if defined(CPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL)
|
#if defined(CPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL)
|
||||||
// Implementation will be provided by test/hwcaps_for_testing.cc.
|
// Implementation will be provided by test/hwcaps_for_testing.cc.
|
||||||
#elif defined(HWCAPS_ANDROID_MIPS_OR_ARM)
|
#elif defined(HAVE_STRONG_GETAUXVAL)
|
||||||
|
#include <sys/auxv.h>
|
||||||
|
static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) {
|
||||||
|
return getauxval(hwcap_type);
|
||||||
|
}
|
||||||
|
#elif defined(HAVE_DLFCN_H)
|
||||||
// On Android we probe the system's C library for a 'getauxval' function and
|
// On Android we probe the system's C library for a 'getauxval' function and
|
||||||
// call it if it exits, or return 0 for failure. This function is available
|
// call it if it exits, or return 0 for failure. This function is available
|
||||||
// since API level 20.
|
// since API level 20.
|
||||||
@ -91,13 +87,6 @@ static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) {
|
|||||||
dlclose(libc_handle);
|
dlclose(libc_handle);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID)
|
|
||||||
// On Regular Linux we simply use getauxval.
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#include <sys/auxv.h>
|
|
||||||
static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) {
|
|
||||||
return getauxval(hwcap_type);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
#error "This platform does not provide hardware capabilities."
|
#error "This platform does not provide hardware capabilities."
|
||||||
#endif
|
#endif
|
||||||
|
@ -58,7 +58,7 @@ add_test(NAME linux_features_aggregator_test COMMAND linux_features_aggregator_t
|
|||||||
## cpuinfo_x86_test
|
## cpuinfo_x86_test
|
||||||
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
|
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
|
||||||
add_executable(cpuinfo_x86_test cpuinfo_x86_test.cc ../src/cpuinfo_x86.c)
|
add_executable(cpuinfo_x86_test cpuinfo_x86_test.cc ../src/cpuinfo_x86.c)
|
||||||
target_compile_definitions(stack_line_reader PUBLIC CPU_FEATURES_MOCK_CPUID_X86)
|
target_compile_definitions(cpuinfo_x86_test PUBLIC CPU_FEATURES_MOCK_CPUID_X86)
|
||||||
target_link_libraries(cpuinfo_x86_test all_libraries)
|
target_link_libraries(cpuinfo_x86_test all_libraries)
|
||||||
add_test(NAME cpuinfo_x86_test COMMAND cpuinfo_x86_test)
|
add_test(NAME cpuinfo_x86_test COMMAND cpuinfo_x86_test)
|
||||||
endif()
|
endif()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user