From 9dcfb54438822c0955da98077f63e36ce3d19dd8 Mon Sep 17 00:00:00 2001 From: Alexander Sokolov Date: Sat, 1 Jun 2024 15:47:51 +0300 Subject: [PATCH] Use CMake to determine endianness --- CMakeLists.txt | 26 ++++++++++++++++++++++++++ vendor/alac/codec/EndianPortable.c | 14 ++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53e9cf3..529c190 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,32 @@ LIST(APPEND SOURCES ) +# Defining the bit order for different architectures +if(CMAKE_VERSION VERSION_LESS "3.20.0") + include(TestBigEndian) + TEST_BIG_ENDIAN(big_endian) + if (${big_endian}) + set(TARGET_RT_LITTLE_ENDIAN 0) + else() + set(TARGET_RT_LITTLE_ENDIAN 1) + endif() +else() + if (${CMAKE_CXX_BYTE_ORDER} STREQUAL "LITTLE_ENDIAN") + set(TARGET_RT_LITTLE_ENDIAN 1) + else() + set(TARGET_RT_LITTLE_ENDIAN 0) + endif() +endif() + +if (${TARGET_RT_LITTLE_ENDIAN}) + message(STATUS "Use little endian") +else() + message(STATUS "Use big endian") +endif() + +add_definitions(-DTARGET_RT_LITTLE_ENDIAN=${TARGET_RT_LITTLE_ENDIAN}) +# Defining the bit order for different architectures + add_definitions(-DPROJECT_NAME=\"${PROJECT_NAME}\") add_definitions(-DPROJECT_VERSION=\"${CMAKE_PROJECT_VERSION}\") add_definitions(-DPROJECT_DESCRIPTION=\"${PROJECT_DESCRIPTION}\") diff --git a/vendor/alac/codec/EndianPortable.c b/vendor/alac/codec/EndianPortable.c index da9423d..971bd6c 100644 --- a/vendor/alac/codec/EndianPortable.c +++ b/vendor/alac/codec/EndianPortable.c @@ -28,18 +28,8 @@ #include "EndianPortable.h" // ***************************************** -// Defining the bit order for different architectures -#include - -#if defined(__linux__) || defined(__unix__) -#include -#endif - -#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#define TARGET_RT_LITTLE_ENDIAN 1 -#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ -#define TARGET_RT_LITTLE_ENDIAN 0 -#else +// The TARGET_RT_LITTLE_ENDIAN macro is defined in CMakeList +#ifndef TARGET_RT_LITTLE_ENDIAN #error Cannot determine endianness! #endif // *****************************************