mirror of
https://github.com/dhewm/dhewm3.git
synced 2024-12-02 09:13:51 +00:00
Detect endianess in CMakeLists.txt, get rid of most SDL_endian.h uses
.. except where SDL_Swap* is actually used (idlib/Lib.cpp). Otherwise #if D3_IS_BIG_ENDIAN suffices, (NOT #ifdef, it's always set, but to either 0 or 1!)
This commit is contained in:
parent
0b0a08d7c4
commit
5d3f143220
6 changed files with 50 additions and 12 deletions
|
@ -46,6 +46,7 @@ set(DHEWM3BINARY "dhewm3")
|
|||
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(GNUInstallDirs OPTIONAL RESULT_VARIABLE GNUINSTALLDIRS)
|
||||
include(TestBigEndian)
|
||||
|
||||
option(CORE "Build the core" ON)
|
||||
option(BASE "Build the base game code" ON)
|
||||
|
@ -313,6 +314,15 @@ unset(compiler_id_lower)
|
|||
|
||||
endif() # not MSVC
|
||||
|
||||
TEST_BIG_ENDIAN(is_big_endian)
|
||||
if(is_big_endian)
|
||||
message(STATUS "Detected Big Endian architecture, setting -DD3_IS_BIG_ENDIAN=1")
|
||||
add_definitions(-DD3_IS_BIG_ENDIAN=1)
|
||||
else()
|
||||
message(STATUS "Detected Little Endian architecture, setting -DD3_IS_BIG_ENDIAN=0")
|
||||
add_definitions(-DD3_IS_BIG_ENDIAN=0)
|
||||
endif()
|
||||
|
||||
# compiler specific flags
|
||||
if(D3_COMPILER_IS_GCC_OR_CLANG)
|
||||
add_compile_options(-pipe)
|
||||
|
|
|
@ -26,8 +26,6 @@ If you have questions concerning this license or the applicable additional terms
|
|||
===========================================================================
|
||||
*/
|
||||
|
||||
#include <SDL_endian.h>
|
||||
|
||||
#include "sys/platform.h"
|
||||
#include "idlib/LangDict.h"
|
||||
#include "idlib/Timer.h"
|
||||
|
@ -527,7 +525,12 @@ void idGameLocal::SaveGame( idFile *f ) {
|
|||
savegame.WriteString( D3_ARCH ); // CPU architecture (e.g. "x86" or "x86_64") - from CMake
|
||||
savegame.WriteString( ENGINE_VERSION );
|
||||
savegame.WriteShort( (short)sizeof(void*) ); // tells us if it's from a 32bit (4) or 64bit system (8)
|
||||
savegame.WriteShort( SDL_BYTEORDER ) ; // SDL_LIL_ENDIAN or SDL_BIG_ENDIAN
|
||||
#if D3_IS_BIG_ENDIAN
|
||||
const short byteOrder = 4321; // SDL_BIG_ENDIAN
|
||||
#else
|
||||
const short byteOrder = 1234; // SDL_LIL_ENDIAN
|
||||
#endif
|
||||
savegame.WriteShort( byteOrder ) ;
|
||||
// DG end
|
||||
|
||||
// go through all entities and threads and add them to the object list
|
||||
|
|
|
@ -26,8 +26,6 @@ If you have questions concerning this license or the applicable additional terms
|
|||
===========================================================================
|
||||
*/
|
||||
|
||||
#include <SDL_endian.h>
|
||||
|
||||
#include "sys/platform.h"
|
||||
#include "idlib/LangDict.h"
|
||||
#include "idlib/Timer.h"
|
||||
|
@ -469,7 +467,12 @@ void idGameLocal::SaveGame( idFile *f ) {
|
|||
savegame.WriteString( D3_ARCH ); // CPU architecture (e.g. "x86" or "x86_64") - from CMake
|
||||
savegame.WriteString( ENGINE_VERSION );
|
||||
savegame.WriteShort( (short)sizeof(void*) ); // tells us if it's from a 32bit (4) or 64bit system (8)
|
||||
savegame.WriteShort( SDL_BYTEORDER ) ; // SDL_LIL_ENDIAN or SDL_BIG_ENDIAN
|
||||
#if D3_IS_BIG_ENDIAN
|
||||
const short byteOrder = 4321; // SDL_BIG_ENDIAN
|
||||
#else
|
||||
const short byteOrder = 1234; // SDL_LIL_ENDIAN
|
||||
#endif
|
||||
savegame.WriteShort( byteOrder ) ;
|
||||
// DG end
|
||||
|
||||
// go through all entities and threads and add them to the object list
|
||||
|
|
|
@ -35,7 +35,32 @@ If you have questions concerning this license or the applicable additional terms
|
|||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <SDL_endian.h>
|
||||
#ifdef D3_SDL3
|
||||
#include <SDL3/SDL_endian.h>
|
||||
// some defines for backwards-compat with SDL2
|
||||
#define SDL_SwapBE16(X) SDL_Swap16BE(X)
|
||||
#define SDL_SwapLE16(X) SDL_Swap16LE(X)
|
||||
#define SDL_SwapBE32(X) SDL_Swap32BE(X)
|
||||
#define SDL_SwapLE32(X) SDL_Swap32LE(X)
|
||||
#else // SDL1.2 or SDL2
|
||||
#include <SDL_endian.h>
|
||||
#endif
|
||||
|
||||
#ifndef D3_IS_BIG_ENDIAN
|
||||
#error "D3_IS_BIG_ENDIAN should be defined by the build system (CMake)!"
|
||||
#endif
|
||||
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
#if D3_IS_BIG_ENDIAN != 1
|
||||
#error "CMake (which sets D3_IS_BIG_ENDIAN) and SDL disagree about the endianess! CMake says little, SDL says big"
|
||||
#endif
|
||||
#elif SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||
#if D3_IS_BIG_ENDIAN != 0
|
||||
#error "CMake (which sets D3_IS_BIG_ENDIAN) and SDL disagree about the endianess! CMake says big, SDL says little"
|
||||
#endif
|
||||
#else
|
||||
#error "According to SDL, endianess is neither Big nor Little - dhewm3 doesn't support other byteorders!"
|
||||
#endif
|
||||
|
||||
#include "sys/platform.h"
|
||||
#include "idlib/math/Vector.h"
|
||||
|
|
|
@ -26,9 +26,7 @@ If you have questions concerning this license or the applicable additional terms
|
|||
===========================================================================
|
||||
*/
|
||||
|
||||
|
||||
#include "SDL_endian.h"
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
#if D3_IS_BIG_ENDIAN
|
||||
#define STB_VORBIS_BIG_ENDIAN
|
||||
#endif
|
||||
#define STB_VORBIS_NO_STDIO
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
// (I'm doing this instead of renaming stb_vorbis.h to stb_vorbis.c so the configuration
|
||||
// like STB_VORBIS_BIG_ENDIAN etc can be done here in code)
|
||||
|
||||
#include "SDL_endian.h"
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
#if D3_IS_BIG_ENDIAN
|
||||
#define STB_VORBIS_BIG_ENDIAN
|
||||
#endif
|
||||
#define STB_VORBIS_NO_STDIO
|
||||
|
|
Loading…
Reference in a new issue