Skip to content

Commit

Permalink
Use CMake to determine endianness
Browse files Browse the repository at this point in the history
  • Loading branch information
SokoloffA committed Jun 1, 2024
1 parent f31da0f commit 9dcfb54
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}\")
Expand Down
14 changes: 2 additions & 12 deletions vendor/alac/codec/EndianPortable.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,8 @@
#include "EndianPortable.h"

// *****************************************
// Defining the bit order for different architectures
#include <stdint.h>

#if defined(__linux__) || defined(__unix__)
#include <endian.h>
#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
// *****************************************
Expand Down

0 comments on commit 9dcfb54

Please sign in to comment.