diff options
author | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2015-11-13 10:58:23 +0900 |
---|---|---|
committer | Tsuda Kageyu <tsuda.kageyu@gmail.com> | 2015-11-13 10:58:23 +0900 |
commit | 6775cef651f01753efff221264112af7f11aa183 (patch) | |
tree | 0d803862b0dc64008079241d7198b4d9f59c63f7 /ConfigureChecks.cmake | |
parent | 86c7e905ba7872fa3a4b3e96b0d8b6ca4fa35e56 (diff) |
Make use of the Boost Endian library for byte swapping.
It's likely to be better at choosing the most efficient method than our CMake tests.
Diffstat (limited to 'ConfigureChecks.cmake')
-rw-r--r-- | ConfigureChecks.cmake | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 5c740756..3fa01bb1 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -108,57 +108,69 @@ endif() # Determine which kind of byte swap functions your compiler supports. check_cxx_source_compiles(" + #include <boost/endian/conversion.hpp> int main() { - __builtin_bswap16(0); - __builtin_bswap32(0); - __builtin_bswap64(0); + boost::endian::endian_reverse(static_cast<uint16_t>(1)); + boost::endian::endian_reverse(static_cast<uint32_t>(1)); + boost::endian::endian_reverse(static_cast<uint64_t>(1)); return 0; } -" HAVE_GCC_BYTESWAP) +" HAVE_BOOST_BYTESWAP) -if(NOT HAVE_GCC_BYTESWAP) +if(NOT HAVE_BOOST_BYTESWAP) check_cxx_source_compiles(" - #include <byteswap.h> int main() { - __bswap_16(0); - __bswap_32(0); - __bswap_64(0); + __builtin_bswap16(0); + __builtin_bswap32(0); + __builtin_bswap64(0); return 0; } - " HAVE_GLIBC_BYTESWAP) + " HAVE_GCC_BYTESWAP) - if(NOT HAVE_GLIBC_BYTESWAP) + if(NOT HAVE_GCC_BYTESWAP) check_cxx_source_compiles(" - #include <stdlib.h> + #include <byteswap.h> int main() { - _byteswap_ushort(0); - _byteswap_ulong(0); - _byteswap_uint64(0); + __bswap_16(0); + __bswap_32(0); + __bswap_64(0); return 0; } - " HAVE_MSC_BYTESWAP) + " HAVE_GLIBC_BYTESWAP) - if(NOT HAVE_MSC_BYTESWAP) + if(NOT HAVE_GLIBC_BYTESWAP) check_cxx_source_compiles(" - #include <libkern/OSByteOrder.h> + #include <stdlib.h> int main() { - OSSwapInt16(0); - OSSwapInt32(0); - OSSwapInt64(0); + _byteswap_ushort(0); + _byteswap_ulong(0); + _byteswap_uint64(0); return 0; } - " HAVE_MAC_BYTESWAP) + " HAVE_MSC_BYTESWAP) - if(NOT HAVE_MAC_BYTESWAP) + if(NOT HAVE_MSC_BYTESWAP) check_cxx_source_compiles(" - #include <sys/endian.h> + #include <libkern/OSByteOrder.h> int main() { - swap16(0); - swap32(0); - swap64(0); + OSSwapInt16(0); + OSSwapInt32(0); + OSSwapInt64(0); return 0; } - " HAVE_OPENBSD_BYTESWAP) + " HAVE_MAC_BYTESWAP) + + if(NOT HAVE_MAC_BYTESWAP) + check_cxx_source_compiles(" + #include <sys/endian.h> + int main() { + swap16(0); + swap32(0); + swap64(0); + return 0; + } + " HAVE_OPENBSD_BYTESWAP) + endif() endif() endif() endif() |