Skip to content

Commit

Permalink
Using CMake TestBigEndian module to check endianness
Browse files Browse the repository at this point in the history
  • Loading branch information
ktakashi committed Nov 27, 2023
1 parent bd03e1f commit a86690e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 44 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
PROJECT(Sagittarius)

### options
Expand Down Expand Up @@ -33,6 +33,7 @@ INCLUDE(${CMAKE_ROOT}/Modules/CheckCSourceRuns.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CheckCSourceCompiles.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CheckCCompilerFlag.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/CheckAlloca.cmake)
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/CheckVariable.cmake)
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/Triple.cmake)
Expand Down Expand Up @@ -165,6 +166,9 @@ HAVE_CPU_COUNT)
STRING(TOLOWER ${CMAKE_SYSTEM_NAME} SAGITTARIUS_PLATFORM)
STRING(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} SAGITTARIUS_PROCESSOR)

TEST_BIG_ENDIAN(PLATFORM_BIGENDIAN)
MESSAGE(STATUS "Is big endian ... ${PLATFORM_BIGENDIAN}")

TRIPLE(SAGITTARIUS_PROCESSOR SAGITTARIUS_PLATFORM
SAGITTARIUS_OS SAGITTARIUS_VENDOR SAGITTARIUS_TRIPLE)

Expand Down
2 changes: 2 additions & 0 deletions cmake/config-cmake.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
#cmakedefine SAGITTARIUS_PLATFORM "@SAGITTARIUS_PLATFORM@"
#cmakedefine SAGITTARIUS_PROCESSOR "@SAGITTARIUS_PROCESSOR@"

#cmakedefine PLATFORM_BIGENDIAN

#ifdef _MSC_VER
#define PRIdPTR "Id"
#endif
Expand Down
44 changes: 1 addition & 43 deletions src/sagittarius/private/sagittariusdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,49 +158,7 @@ char *alloca ();
# endif
#endif


/* detect endianness(from boost/detail/endian.hpp) */
#if defined (__GLIBC__)
# include <endian.h>
# if (__BYTE_ORDER == __LITTLE_ENDIAN)
# define BOOST_LITTLE_ENDIAN
# elif (__BYTE_ORDER == __BIG_ENDIAN)
# define BOOST_BIG_ENDIAN
# elif (__BYTE_ORDER == __PDP_ENDIAN)
# define BOOST_PDP_ENDIAN
# else
# error Unknown machine endianness detected.
# endif
# define BOOST_BYTE_ORDER __BYTE_ORDER
#elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
# define BOOST_BIG_ENDIAN
# define BOOST_BYTE_ORDER 4321
#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
# define BOOST_LITTLE_ENDIAN
# define BOOST_BYTE_ORDER 1234
#elif defined(__sparc) || defined(__sparc__) \
|| defined(_POWER) || defined(__powerpc__) \
|| defined(__ppc__) || defined(__hpux) || defined(__hppa) \
|| defined(_MIPSEB) || defined(_POWER) \
|| defined(__s390__)
# define BOOST_BIG_ENDIAN
# define BOOST_BYTE_ORDER 4321
#elif defined(__i386__) || defined(__alpha__) \
|| defined(__ia64) || defined(__ia64__) \
|| defined(_M_IX86) || defined(_M_IA64) \
|| defined(_M_ALPHA) || defined(__amd64) \
|| defined(__amd64__) || defined(_M_AMD64) \
|| defined(__x86_64) || defined(__x86_64__) \
|| defined(_M_X64) || defined(__bfin__) \
|| defined(__arm__) || defined(__arm64__)

# define BOOST_LITTLE_ENDIAN
# define BOOST_BYTE_ORDER 1234
#else
# error Failed to detect endian
#endif

#if defined BOOST_BIG_ENDIAN
#if defined PLATFORM_BIGENDIAN
# ifdef MAC
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
Expand Down

0 comments on commit a86690e

Please sign in to comment.