diff --git a/Installation/include/CGAL/config.h b/Installation/include/CGAL/config.h index ab512c9a624..3f0a03589af 100644 --- a/Installation/include/CGAL/config.h +++ b/Installation/include/CGAL/config.h @@ -108,14 +108,21 @@ namespace CGAL { // Big endian or little endian machine. // ==================================== -#include // provides endianness macros - -#ifdef BOOST_BIG_ENDIAN +// We used to have a config program for this, but it +// is much more convenient to use the preprocessor. +#if defined(__sparc) || defined(__sparc__) \ + || defined(_POWER) || defined(__powerpc__) \ + || defined(__ppc__) || defined(__hppa) \ + || defined(_MIPSEB) || defined(_POWER) \ + || defined(__s390__) # define CGAL_BIG_ENDIAN -#elif defined BOOST_LITTLE_ENDIAN +#elif defined(__i386__) || defined(__alpha__) \ + || defined(__ia64) || defined(__ia64__) \ + || defined(_M_IX86) || defined(_M_IA64) \ + || defined(_M_ALPHA) # define CGAL_LITTLE_ENDIAN #else -# error "Unknown endianness" +# error Unknown endianness #endif diff --git a/Installation/test/Installation/endian.cpp b/Installation/test/Installation/endian.cpp new file mode 100644 index 00000000000..23d557c8356 --- /dev/null +++ b/Installation/test/Installation/endian.cpp @@ -0,0 +1,32 @@ +// Run-time check that our endianness macro is correctly defined. + +#include +#include + +#if !defined CGAL_LITTLE_ENDIAN && !defined CGAL_BIG_ENDIAN +# error no endian macro defined +#endif + +union T { + int testWord; + char testByte[sizeof(int)]; +} endianTest; + +int main() +{ + endianTest.testWord = 1; + if (endianTest.testByte[0] == 1) { +#ifdef CGAL_LITTLE_ENDIAN + return 0; +#else + CGAL_test_assert(false); +#endif + } else { +#ifdef CGAL_BIG_ENDIAN + return 0; +#else + CGAL_test_assert(false); +#endif + } + return 0; +}