libmemcached: add MEMCACHED_BEHAVIOR_META_PROTOCOL
[m6w6/libmemcached] / CMake / CheckByteswap.cmake
1 # defines HAVE_BYTESWAP
2 # optionally defines BYTESWAP_HEADER
3 # optionally defines BYTESWAP_32
4 #
5 # checks whether the following compiles:
6 # __builtin_bswap32(): defines HAVE_BUILTIN_BSWAP32
7 #
8 # else checks:
9 # byteswap.h: defines HAVE_BYTESWAP_H
10 # bswap_32() in byteswap.h: defines HAVE_BSWAP_32
11 #
12 # else checks:
13 # sys/endian.h: defines HAVE_SYS_ENDIAN_H
14 # bswap32() in sys/endian.h: defines HAVE_BSWAP32
15 #
16
17 include(TestBigEndian)
18 test_big_endian(WORDS_BIGENDIAN)
19 configure_define(WORDS_BIGENDIAN)
20
21 configure_define(HAVE_BYTESWAP)
22 configure_define_header(BYTESWAP_HEADER)
23 configure_define_literal(BYTESWAP_32)
24
25 check_c_source("
26 #include <stdint.h>
27 int main() {
28 uint32_t a = 1, b = __builtin_bswap32(a);
29 return b;
30 }"
31 HAVE_BUILTIN_BSWAP32
32 )
33
34 if(HAVE_BUILTIN_BSWAP32)
35 configure_undef(BYTESWAP_HEADER)
36 set(BYTESWAP_32 __builtin_bswap32 CACHE INTERNAL "BYTESWAP_32")
37 set(HAVE_BYTESWAP 1 CACHE INTERNAL "HAVE_BYTESWAP")
38 return()
39 endif()
40
41 check_include(byteswap.h)
42 check_symbol(bswap_32 byteswap.h)
43
44 if(HAVE_BSWAP_32)
45 if(HAVE_BYTESWAP_H)
46 set(BYTESWAP_HEADER byteswap.h CACHE INTERNAL "BYTESWAP_HEADER")
47 endif()
48 set(BYTESWAP_32 bswap_32 CACHE INTERNAL "BYTESWAP_32")
49 set(HAVE_BYTESWAP 1 CACHE INSTERNAL "HAVE_BYTESWAP")
50 return()
51 endif()
52
53 check_include(sys/endian.h)
54 check_symbol(bswap32 sys/endian.h)
55
56 if(HAVE_BSWAP32)
57 if(HAVE_SYS_ENDIAN_H)
58 set(BYTESWAP_HEADER sys/endian.h CACHE INTERNAL "BYTESWAP_HEADER")
59 endif()
60 set(BYTESWAP_32 bswap32 CACHE INTERNAL "BYTESWAP_32")
61 set(HAVE_BYTESWAP 1 CACHE INTERNAL "HAVE_BYTESWAP")
62 return()
63 endif()
64
65 configure_undef(BYTESWAP_HEADER)
66 configure_undef(BYTESWAP_32)
67 set(HAVE_BYTESWAP 0)