diff --git a/CMakeLists.txt b/CMakeLists.txt index a4abb7e..2c1b799 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,6 +146,7 @@ set(LIBSOUNDIO_SOURCES set(CONFIGURE_OUT_FILE "${CMAKE_BINARY_DIR}/config.h") set(LIBSOUNDIO_HEADERS "${CMAKE_SOURCE_DIR}/soundio/soundio.h" + "${CMAKE_SOURCE_DIR}/soundio/endian.h" ${CONFIGURE_OUT_FILE} ) @@ -207,15 +208,6 @@ set(EXAMPLE_CFLAGS "-std=c99 -Wall") set(TEST_CFLAGS "${LIB_CFLAGS} -fprofile-arcs -ftest-coverage") set(TEST_LDFLAGS "-fprofile-arcs -ftest-coverage") -include(TestBigEndian) -test_big_endian(IS_BIG_ENDIAN) -if(IS_BIG_ENDIAN) - set(SOUNDIO_OS_BIG_ENDIAN true) - set(SOUNDIO_OS_LITTLE_ENDIAN false) -else() - set(SOUNDIO_OS_BIG_ENDIAN false) - set(SOUNDIO_OS_LITTLE_ENDIAN true) -endif() configure_file( "${CMAKE_SOURCE_DIR}/src/config.h.in" ${CONFIGURE_OUT_FILE} diff --git a/soundio/endian.h b/soundio/endian.h new file mode 100644 index 0000000..f69072f --- /dev/null +++ b/soundio/endian.h @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2015 Andrew Kelley + * + * This file is part of libsoundio, which is MIT licensed. + * See http://opensource.org/licenses/MIT + */ + +#ifndef SOUNDIO_ENDIAN_H +#define SOUNDIO_ENDIAN_H + +#if defined(__BIG_ENDIAN__) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__ARMEB__) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__THUMBEB__) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__AARCH64EB__) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(_MIPSEB) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__MIPSEB) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__MIPSEB__) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(_BIG_ENDIAN) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__sparc) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__sparc__) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(_POWER) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__powerpc__) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__ppc__) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__hpux) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__hppa) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(_POWER) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__s390__) +#define SOUNDIO_OS_BIG_ENDIAN +#elif defined(__LITTLE_ENDIAN__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__ARMEL__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__THUMBEL__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__AARCH64EL__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(_MIPSEL) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__MIPSEL) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__MIPSEL__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(_LITTLE_ENDIAN) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__i386__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__alpha__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__ia64) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__ia64__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(_M_IX86) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(_M_IA64) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(_M_ALPHA) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__amd64) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__amd64__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(_M_AMD64) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__x86_64) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__x86_64__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(_M_X64) +#define SOUNDIO_OS_LITTLE_ENDIAN +#elif defined(__bfin__) +#define SOUNDIO_OS_LITTLE_ENDIAN +#else +#error unable to detect endianness +#endif + +#endif diff --git a/soundio/soundio.h b/soundio/soundio.h index e39af12..e0fd252 100644 --- a/soundio/soundio.h +++ b/soundio/soundio.h @@ -9,6 +9,7 @@ #define SOUNDIO_SOUNDIO_H #include "config.h" +#include "endian.h" #include /// \cond diff --git a/src/config.h.in b/src/config.h.in index 49bede1..ff22769 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -13,9 +13,6 @@ #define SOUNDIO_VERSION_PATCH @LIBSOUNDIO_VERSION_PATCH@ #define SOUNDIO_VERSION_STRING "@LIBSOUNDIO_VERSION@" -#cmakedefine SOUNDIO_OS_BIG_ENDIAN -#cmakedefine SOUNDIO_OS_LITTLE_ENDIAN - #cmakedefine SOUNDIO_HAVE_JACK #cmakedefine SOUNDIO_HAVE_PULSEAUDIO #cmakedefine SOUNDIO_HAVE_ALSA