From f1cb2402734567b84e2b55129f98f9764167e13e Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 8 Sep 2024 09:37:50 -0700 Subject: Endianness improvements. This adds endian awareness at compile time, and defines some little endian versions of some macros. We antiicpate making more use of little endian in new protocols to reduce the "endian tax", as nearly every modern system is little endian these days. --- CMakeLists.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dca028c..f859a7d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,6 +207,24 @@ if (NOT WIN32 AND NOT CYGWIN) endif () endif () +# Detect endianness -- this only handles little and big endian. +# PDP users, sorry, but you're out of luck.' +if (DEFINED CMAKE_LANG_C_BYTE_ORDER) + if (CMAKE_LANG_BYTE_ORDER EQUAL BIG_ENDIAN) + add_definitions(-DNNG_BIG_ENDIAN=1) + else() + add_definitions(-DNNG_LITTLE_ENDIAN=1) + endif() +else() + include(TestBigEndian) + test_big_endian(NNG_BIG_ENDIAN) + if (NNG_BIG_ENDIAN) + add_definitions(-DNNG_BIG_EDNDIAN=1) + else() + add_definitions(-DNNG_LITTLE_ENDIAN=1) + endif() +endif() + if (CMAKE_SYSTEM_NAME MATCHES "Linux") add_definitions(-DNNG_PLATFORM_POSIX) add_definitions(-DNNG_PLATFORM_LINUX) -- cgit v1.2.3-70-g09d2