From e8e5610fc4032c50186e892a54d792d139da1445 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Tue, 15 Jan 2019 10:52:56 +0100 Subject: [PATCH 1/5] Per arch build and inlining of cpuid_x86. --- CMakeLists.txt | 42 +++++++++++++++++++++------------- src/cpuid_x86_clang_gcc.c | 36 ----------------------------- src/cpuid_x86_msvc.c | 34 --------------------------- src/cpuinfo_x86.c | 48 +++++++++++++++++++++++++++++++++++++++ src/filesystem.c | 4 +++- src/hwcaps.c | 46 +++++++++++++------------------------ test/CMakeLists.txt | 5 ++++ 7 files changed, 98 insertions(+), 117 deletions(-) delete mode 100644 src/cpuid_x86_clang_gcc.c delete mode 100644 src/cpuid_x86_msvc.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 591c116..a5fbfc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,38 +21,48 @@ option(BUILD_SHARED_LIBS "Build library as shared." OFF) # set(_HDRS - include/cpuinfo_aarch64.h - include/cpuinfo_arm.h - include/cpuinfo_mips.h - include/cpuinfo_ppc.h - include/cpuinfo_x86.h include/cpu_features_macros.h ) -add_library(cpu_features - ${_HDRS} +set(_SRCS include/internal/bit_utils.h include/internal/linux_features_aggregator.h - include/internal/cpuid_x86.h include/internal/filesystem.h include/internal/hwcaps.h include/internal/stack_line_reader.h include/internal/string_view.h - include/cpu_features_macros.h src/linux_features_aggregator.c - src/cpuid_x86_clang_gcc.c - src/cpuid_x86_msvc.c - src/cpuinfo_aarch64.c - src/cpuinfo_arm.c - src/cpuinfo_mips.c - src/cpuinfo_ppc.c - src/cpuinfo_x86.c src/filesystem.c src/hwcaps.c src/stack_line_reader.c src/string_view.c ) +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips") + list(APPEND _HDRS include/cpuinfo_mips.h) + list(APPEND _SRCS src/cpuinfo_mips.c) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") + list(APPEND _HDRS include/cpuinfo_arm.h) + list(APPEND _SRCS src/cpuinfo_arm.c) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") + list(APPEND _HDRS include/cpuinfo_aarch64.h) + list(APPEND _SRCS src/cpuinfo_aarch64.c) +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") + list(APPEND _HDRS include/cpuinfo_x86.h) + list(APPEND _HDRS include/internal/cpuid_x86.h) + list(APPEND _SRCS src/cpuinfo_x86.c) +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") + list(APPEND _HDRS include/cpuinfo_ppc.h) + list(APPEND _SRCS src/cpuinfo_ppc.c) +else() + message(SEND_ERROR "Unsupported architectures ${CMAKE_SYSTEM_PROCESSOR}") +endif() + +add_library(cpu_features + ${_HDRS} + ${_SRCS} +) + target_include_directories(cpu_features PUBLIC $ diff --git a/src/cpuid_x86_clang_gcc.c b/src/cpuid_x86_clang_gcc.c deleted file mode 100644 index 472e712..0000000 --- a/src/cpuid_x86_clang_gcc.c +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2017 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "internal/cpuid_x86.h" - -#if defined(CPU_FEATURES_ARCH_X86) -#if defined(CPU_FEATURES_COMPILER_CLANG) || defined(CPU_FEATURES_COMPILER_GCC) - -#include - -Leaf CpuId(uint32_t leaf_id) { - Leaf leaf; - __cpuid_count(leaf_id, 0, leaf.eax, leaf.ebx, leaf.ecx, leaf.edx); - return leaf; -} - -uint32_t GetXCR0Eax(void) { - uint32_t eax, edx; - __asm("XGETBV" : "=a"(eax), "=d"(edx) : "c"(0)); - return eax; -} - -#endif // defined(CPU_FEATURES_COMPILER_CLANG) || - // defined(CPU_FEATURES_COMPILER_GCC) -#endif // defined(CPU_FEATURES_ARCH_X86) diff --git a/src/cpuid_x86_msvc.c b/src/cpuid_x86_msvc.c deleted file mode 100644 index cd8f19f..0000000 --- a/src/cpuid_x86_msvc.c +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2017 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "internal/cpuid_x86.h" - -#if defined(CPU_FEATURES_ARCH_X86) && defined(CPU_FEATURES_COMPILER_MSC) -#include -#include // For __cpuidex() - -Leaf CpuId(uint32_t leaf_id) { - Leaf leaf; - int data[4]; - __cpuid(data, leaf_id); - leaf.eax = data[0]; - leaf.ebx = data[1]; - leaf.ecx = data[2]; - leaf.edx = data[3]; - return leaf; -} - -uint32_t GetXCR0Eax(void) { return _xgetbv(0); } - -#endif // defined(CPU_FEATURES_ARCH_X86) && defined(CPU_FEATURES_COMPILER_MSC) diff --git a/src/cpuinfo_x86.c b/src/cpuinfo_x86.c index 0114817..7e04816 100644 --- a/src/cpuinfo_x86.c +++ b/src/cpuinfo_x86.c @@ -19,6 +19,54 @@ #include #include +#if !defined(CPU_FEATURES_ARCH_X86) +#error "Cannot compile cpuinfo_x86 on a non x86 platform." +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Definitions for CpuId and GetXCR0Eax. +//////////////////////////////////////////////////////////////////////////////// + +#if defined(CPU_FEATURES_MOCK_CPUID_X86) +// Implementation will be provided by test/cpuinfo_x86_test.cc. +#elif defined(CPU_FEATURES_COMPILER_CLANG) || defined(CPU_FEATURES_COMPILER_GCC) + +#include + +Leaf CpuId(uint32_t leaf_id) { + Leaf leaf; + __cpuid_count(leaf_id, 0, leaf.eax, leaf.ebx, leaf.ecx, leaf.edx); + return leaf; +} + +uint32_t GetXCR0Eax(void) { + uint32_t eax, edx; + __asm("XGETBV" : "=a"(eax), "=d"(edx) : "c"(0)); + return eax; +} + +#elif defined(CPU_FEATURES_COMPILER_MSC) + +#include +#include // For __cpuidex() + +Leaf CpuId(uint32_t leaf_id) { + Leaf leaf; + int data[4]; + __cpuid(data, leaf_id); + leaf.eax = data[0]; + leaf.ebx = data[1]; + leaf.ecx = data[2]; + leaf.edx = data[3]; + return leaf; +} + +uint32_t GetXCR0Eax(void) { return _xgetbv(0); } + +#else +#error "Unsupported compiler, x86 cpuid requires either GCC, Clang or MSVC." +#endif + static const Leaf kEmptyLeaf; static Leaf SafeCpuId(uint32_t max_cpuid_leaf, uint32_t leaf_id) { diff --git a/src/filesystem.c b/src/filesystem.c index 286a9cc..25444da 100644 --- a/src/filesystem.c +++ b/src/filesystem.c @@ -19,7 +19,9 @@ #include #include -#if defined(_MSC_VER) +#if defined(CPU_FEATURES_MOCK_FILESYSTEM) +// Implementation will be provided by test/filesystem_for_testing.cc. +#elif defined(_MSC_VER) #include int CpuFeatures_OpenFile(const char* filename) { return _open(filename, _O_RDONLY); diff --git a/src/hwcaps.c b/src/hwcaps.c index c67c5e6..d8c6df2 100644 --- a/src/hwcaps.c +++ b/src/hwcaps.c @@ -40,23 +40,13 @@ #define HWCAPS_REGULAR_LINUX #endif -#if defined(HWCAPS_ANDROID_MIPS_OR_ARM) || defined(HWCAPS_REGULAR_LINUX) -#define HWCAPS_SUPPORTED -#endif - //////////////////////////////////////////////////////////////////////////////// // Implementation of GetElfHwcapFromGetauxval //////////////////////////////////////////////////////////////////////////////// -// On Linux we simply use getauxval. -#if defined(HWCAPS_REGULAR_LINUX) -#include -#include -static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) { - return getauxval(hwcap_type); -} -#endif // defined(HWCAPS_REGULAR_LINUX) - +#if defined(CPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL) +// Implementation will be provided by test/hwcaps_for_testing.cc. +#elif defined(HWCAPS_ANDROID_MIPS_OR_ARM) // 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 // since API level 20. @@ -71,7 +61,7 @@ static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) { // implementation does not parse /proc/self/auxv. Instead it depends on values // that are passed by the kernel at process-init time to the C runtime // initialization layer. -#if defined(HWCAPS_ANDROID_MIPS_OR_ARM) + #include #define AT_HWCAP 16 #define AT_HWCAP2 26 @@ -101,12 +91,19 @@ static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) { dlclose(libc_handle); return ret; } -#endif // defined(HWCAPS_ANDROID_MIPS_OR_ARM) +#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) +// On Regular Linux we simply use getauxval. +#include +#include +static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) { + return getauxval(hwcap_type); +} +#else +#error "This platform does not provide hardware capabilities." +#endif -#if defined(HWCAPS_SUPPORTED) -//////////////////////////////////////////////////////////////////////////////// -// Implementation of GetHardwareCapabilities for Android and Linux -//////////////////////////////////////////////////////////////////////////////// +// Implementation of GetHardwareCapabilities for OS that provide +// GetElfHwcapFromGetauxval(). // Fallback when getauxval is not available, retrieves hwcaps from // "/proc/self/auxv". @@ -174,14 +171,3 @@ PlatformType CpuFeatures_GetPlatformType(void) { sizeof(type.base_platform)); return type; } -#else // (defined(HWCAPS_SUPPORTED) - -//////////////////////////////////////////////////////////////////////////////// -// Implementation of GetHardwareCapabilities for unsupported platforms. -//////////////////////////////////////////////////////////////////////////////// - -const HardwareCapabilities kEmptyHardwareCapabilities; -HardwareCapabilities CpuFeatures_GetHardwareCapabilities(void) { - return kEmptyHardwareCapabilities; -} -#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 794ef04..b4e83f8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,8 +13,10 @@ add_definitions(-DCPU_FEATURES_TEST) add_library(string_view ../src/string_view.c) ##------------------------------------------------------------------------------ add_library(filesystem_for_testing filesystem_for_testing.cc) +target_compile_definitions(filesystem_for_testing PUBLIC CPU_FEATURES_MOCK_FILESYSTEM) ##------------------------------------------------------------------------------ add_library(hwcaps_for_testing hwcaps_for_testing.cc) +target_compile_definitions(hwcaps_for_testing PUBLIC CPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL) target_link_libraries(hwcaps_for_testing filesystem_for_testing) ##------------------------------------------------------------------------------ add_library(stack_line_reader ../src/stack_line_reader.c) @@ -54,9 +56,12 @@ target_link_libraries(linux_features_aggregator_test all_libraries) add_test(NAME linux_features_aggregator_test COMMAND linux_features_aggregator_test) ##------------------------------------------------------------------------------ ## cpuinfo_x86_test +if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") 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_link_libraries(cpuinfo_x86_test all_libraries) add_test(NAME cpuinfo_x86_test COMMAND cpuinfo_x86_test) +endif() ##------------------------------------------------------------------------------ ## cpuinfo_arm_test add_executable(cpuinfo_arm_test cpuinfo_arm_test.cc ../src/cpuinfo_arm.c) From 122b06708722f075a2f7194e16f370dcf1dbd0c4 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Tue, 15 Jan 2019 15:18:08 +0100 Subject: [PATCH 2/5] Use Cmake macros to detect getauxval and dlopen --- CMakeLists.txt | 15 ++++++++++++--- src/hwcaps.c | 23 ++++++----------------- test/CMakeLists.txt | 2 +- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a5fbfc6..8150178 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,12 @@ option(BUILD_SHARED_LIBS "Build library as shared." OFF) # 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 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 _SRCS src/cpuinfo_ppc.c) else() - message(SEND_ERROR "Unsupported architectures ${CMAKE_SYSTEM_PROCESSOR}") + message(FATAL_ERROR "Unsupported architectures ${CMAKE_SYSTEM_PROCESSOR}") endif() add_library(cpu_features @@ -71,8 +77,11 @@ target_include_directories(cpu_features include/internal ) set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${_HDRS}") -target_compile_definitions(cpu_features - PUBLIC STACK_LINE_READER_BUFFER_SIZE=1024) +target_compile_definitions(cpu_features PUBLIC + 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}) # The use of shared libraries is discouraged. diff --git a/src/hwcaps.c b/src/hwcaps.c index d8c6df2..815e5c1 100644 --- a/src/hwcaps.c +++ b/src/hwcaps.c @@ -31,22 +31,18 @@ } while (0) #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 //////////////////////////////////////////////////////////////////////////////// #if defined(CPU_FEATURES_MOCK_GET_ELF_HWCAP_FROM_GETAUXVAL) // Implementation will be provided by test/hwcaps_for_testing.cc. -#elif defined(HWCAPS_ANDROID_MIPS_OR_ARM) +#elif defined(HAVE_STRONG_GETAUXVAL) +#include +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 // call it if it exits, or return 0 for failure. This function is available // since API level 20. @@ -91,13 +87,6 @@ static uint32_t GetElfHwcapFromGetauxval(uint32_t hwcap_type) { dlclose(libc_handle); return ret; } -#elif defined(CPU_FEATURES_OS_LINUX_OR_ANDROID) -// On Regular Linux we simply use getauxval. -#include -#include -static unsigned long GetElfHwcapFromGetauxval(uint32_t hwcap_type) { - return getauxval(hwcap_type); -} #else #error "This platform does not provide hardware capabilities." #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b4e83f8..6f4a7cd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -58,7 +58,7 @@ add_test(NAME linux_features_aggregator_test COMMAND linux_features_aggregator_t ## cpuinfo_x86_test if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") 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) add_test(NAME cpuinfo_x86_test COMMAND cpuinfo_x86_test) endif() From 347065af9536ce67c4cd03aa797a5c5894256807 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Tue, 15 Jan 2019 15:30:43 +0100 Subject: [PATCH 3/5] Add AMD64 and i386/i686 to x86 detection --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8150178..e15405c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,9 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") list(APPEND _HDRS include/cpuinfo_aarch64.h) list(APPEND _SRCS src/cpuinfo_aarch64.c) -elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") +elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR + CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR + CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") list(APPEND _HDRS include/cpuinfo_x86.h) list(APPEND _HDRS include/internal/cpuid_x86.h) list(APPEND _SRCS src/cpuinfo_x86.c) From b3bb9048f4b42325a9979d78204e1843254344de Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Tue, 15 Jan 2019 15:42:04 +0100 Subject: [PATCH 4/5] Fix discovery of --- CMakeLists.txt | 53 +++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e15405c..1a51ec5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,8 +23,8 @@ option(BUILD_SHARED_LIBS "Build library as shared." OFF) include (CheckIncludeFile) include (CheckSymbolExists) -check_symbol_exists(getauxval sys/auxv.h HAVE_STRONG_GETAUXVAL) check_include_file(dlfcn.h HAVE_DLFCN_H) +check_symbol_exists(getauxval "sys/auxv.h" HAVE_STRONG_GETAUXVAL) set(_HDRS include/cpu_features_macros.h @@ -32,44 +32,55 @@ set(_HDRS set(_SRCS include/internal/bit_utils.h - include/internal/linux_features_aggregator.h - include/internal/filesystem.h - include/internal/hwcaps.h - include/internal/stack_line_reader.h - include/internal/string_view.h - src/linux_features_aggregator.c - src/filesystem.c - src/hwcaps.c - src/stack_line_reader.c - src/string_view.c ) +macro(add_linux_detection) + if(NOT (APPLE OR UNIX)) + message(FATAL_ERROR "Use of add_linux_detection() on non Linux-like OS") + endif() + list(APPEND _SRCS + include/internal/linux_features_aggregator.h + src/linux_features_aggregator.c + include/internal/hwcaps.h + src/hwcaps.c + include/internal/filesystem.h + src/filesystem.c + include/internal/stack_line_reader.h + src/stack_line_reader.c + include/internal/string_view.h + src/string_view.c + ) +endmacro() + if(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips") list(APPEND _HDRS include/cpuinfo_mips.h) list(APPEND _SRCS src/cpuinfo_mips.c) + add_linux_detection() elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") list(APPEND _HDRS include/cpuinfo_arm.h) list(APPEND _SRCS src/cpuinfo_arm.c) + add_linux_detection() elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") list(APPEND _HDRS include/cpuinfo_aarch64.h) list(APPEND _SRCS src/cpuinfo_aarch64.c) + add_linux_detection() elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$") list(APPEND _HDRS include/cpuinfo_x86.h) list(APPEND _HDRS include/internal/cpuid_x86.h) list(APPEND _SRCS src/cpuinfo_x86.c) + # add_linux_detection() is not needed on x86, we fetch the features directly + # from the CPU. elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") list(APPEND _HDRS include/cpuinfo_ppc.h) list(APPEND _SRCS src/cpuinfo_ppc.c) + add_linux_detection() else() message(FATAL_ERROR "Unsupported architectures ${CMAKE_SYSTEM_PROCESSOR}") endif() -add_library(cpu_features - ${_HDRS} - ${_SRCS} -) +add_library(cpu_features ${_HDRS} ${_SRCS}) target_include_directories(cpu_features PUBLIC @@ -79,11 +90,13 @@ target_include_directories(cpu_features include/internal ) set_target_properties(cpu_features PROPERTIES PUBLIC_HEADER "${_HDRS}") -target_compile_definitions(cpu_features PUBLIC - STACK_LINE_READER_BUFFER_SIZE=1024 - HAVE_STRONG_GETAUXVAL=${HAVE_STRONG_GETAUXVAL} - HAVE_DLFCN_H=${HAVE_DLFCN_H} -) +target_compile_definitions(cpu_features PUBLIC STACK_LINE_READER_BUFFER_SIZE=1024) +if(HAVE_DLFCN_H) + target_compile_definitions(cpu_features PRIVATE HAVE_DLFCN_H) +endif() +if(HAVE_STRONG_GETAUXVAL) + target_compile_definitions(cpu_features PRIVATE HAVE_STRONG_GETAUXVAL) +endif() target_link_libraries(cpu_features PUBLIC ${CMAKE_DL_LIBS}) # The use of shared libraries is discouraged. From 98bd43ffce1aecaa449beb64bbc5312239b876eb Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Tue, 15 Jan 2019 17:10:47 +0100 Subject: [PATCH 5/5] UNIX works for Unix like OS so no need to add APPLE. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a51ec5..1571344 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ set(_SRCS ) macro(add_linux_detection) - if(NOT (APPLE OR UNIX)) + if(NOT UNIX) message(FATAL_ERROR "Use of add_linux_detection() on non Linux-like OS") endif() list(APPEND _SRCS