From e05fa5c1c3a2b11217cd2589c80978a66a01d84a Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 27 Jun 2020 14:58:30 +0100 Subject: [PATCH] CMake: Add builtins --- CMakeLists.txt | 1 + cmake/FindBuiltins.cmake | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 cmake/FindBuiltins.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 34697e09b2..184ff3ab27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ if (NOT WIN32) find_package(Fontconfig) find_package(ICU OPTIONAL_COMPONENTS i18n lx) find_package(XDG_basedir) + find_package(Builtins) endif (NOT WIN32) if (APPLE) find_package(Iconv) diff --git a/cmake/FindBuiltins.cmake b/cmake/FindBuiltins.cmake new file mode 100644 index 0000000000..c84292729b --- /dev/null +++ b/cmake/FindBuiltins.cmake @@ -0,0 +1,34 @@ +include(CheckCXXSourceCompiles) + +check_cxx_source_compiles(" + int main() { + return __builtin_popcountll(__builtin_popcountl(__builtin_popcount(__builtin_ctz(1)))); + }" + BITMATH_BUILTINS_FOUND +) + +if (BITMATH_BUILTINS_FOUND) + add_compile_options( + -DWITH_BITMATH_BUILTINS + ) +endif (BITMATH_BUILTINS_FOUND) + +check_cxx_source_compiles(" +#include +int main() { + int64_t a = 0; + int64_t b = 0; + int64_t c = 0; + bool res1 = __builtin_add_overflow(a, b, &c); + bool res2 = __builtin_sub_overflow(a, b, &c); + bool res3 = __builtin_mul_overflow(a, b, &c); + return (res1 || res2 || res3) ? 1 : 0; +}" + OVERFLOW_BUILTINS_FOUND +) + +if (OVERFLOW_BUILTINS_FOUND) + add_compile_options( + -DWITH_OVERFLOW_BUILTINS + ) +endif (OVERFLOW_BUILTINS_FOUND)