diff options
| -rw-r--r-- | CMakeLists.txt | 9 | ||||
| -rw-r--r-- | include/compat/endian.h | 17 |
2 files changed, 25 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f8cbb4..199c00e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
| @@ -140,6 +140,15 @@ endif() | |||
| 140 | if(MSVC) | 140 | if(MSVC) |
| 141 | add_definitions(-Dinline=__inline) | 141 | add_definitions(-Dinline=__inline) |
| 142 | message(STATUS "Using [${CMAKE_C_COMPILER_ID}] compiler") | 142 | message(STATUS "Using [${CMAKE_C_COMPILER_ID}] compiler") |
| 143 | |||
| 144 | include(TestBigEndian) | ||
| 145 | TEST_BIG_ENDIAN(HAVE_BIG_ENDIAN) | ||
| 146 | if(HAVE_BIG_ENDIAN) | ||
| 147 | add_definitions(-DHAVE_BIG_ENDIAN) | ||
| 148 | else() | ||
| 149 | add_definitions(-DHAVE_LITTLE_ENDIAN) | ||
| 150 | endif() | ||
| 151 | |||
| 143 | if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR CMAKE_C_COMPILER_ID MATCHES "Clang") | 152 | if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR CMAKE_C_COMPILER_ID MATCHES "Clang") |
| 144 | set(MSVC_DISABLED_WARNINGS_LIST | 153 | set(MSVC_DISABLED_WARNINGS_LIST |
| 145 | "C4018" # 'expression' : signed/unsigned mismatch | 154 | "C4018" # 'expression' : signed/unsigned mismatch |
diff --git a/include/compat/endian.h b/include/compat/endian.h index d0dcfe3..5376c1a 100644 --- a/include/compat/endian.h +++ b/include/compat/endian.h | |||
| @@ -13,13 +13,28 @@ | |||
| 13 | #define PDP_ENDIAN 3412 | 13 | #define PDP_ENDIAN 3412 |
| 14 | 14 | ||
| 15 | /* | 15 | /* |
| 16 | * Use GCC and Visual Studio compiler defines to determine endian. | 16 | * Use GCC compiler defines to determine endianness. |
| 17 | */ | 17 | */ |
| 18 | #if defined(__BYTE_ORDER__) | ||
| 18 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | 19 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 19 | #define BYTE_ORDER LITTLE_ENDIAN | 20 | #define BYTE_ORDER LITTLE_ENDIAN |
| 20 | #else | 21 | #else |
| 21 | #define BYTE_ORDER BIG_ENDIAN | 22 | #define BYTE_ORDER BIG_ENDIAN |
| 22 | #endif | 23 | #endif |
| 24 | #endif | ||
| 25 | |||
| 26 | /* | ||
| 27 | * Use build system defines to determine endianness. | ||
| 28 | */ | ||
| 29 | #if !defined(BYTE_ORDER) | ||
| 30 | #if defined(HAVE_LITTLE_ENDIAN) | ||
| 31 | #define BYTE_ORDER LITTLE_ENDIAN | ||
| 32 | #elif defined(HAVE_BIG_ENDIAN) | ||
| 33 | #define BYTE_ORDER BIG_ENDIAN | ||
| 34 | #else | ||
| 35 | #error "Could not detect endianness." | ||
| 36 | #endif | ||
| 37 | #endif | ||
| 23 | 38 | ||
| 24 | #elif defined(HAVE_ENDIAN_H) | 39 | #elif defined(HAVE_ENDIAN_H) |
| 25 | #include_next <endian.h> | 40 | #include_next <endian.h> |
