diff --git a/CMakeLists.txt b/CMakeLists.txt index aec633ff8..423f47817 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,18 @@ set(CMAKE_XCODE_ATTRIBUTE_MARKETING_VERSION ${APP_SHORT_VERSION}) set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO) set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=Debug] YES) +#Check for endian +if(${CMAKE_VERSION} VERSION_LESS "3.20.0") + include(TestBigEndian) + test_big_endian(VCMI_ENDIAN_BIG) + if(VCMI_ENDIAN_BIG) + add_definitions(-DVCMI_ENDIAN_BIG) + endif() +elseif(${CMAKE_CXX_BYTE_ORDER} EQUAL "BIG_ENDIAN") + add_definitions(-DVCMI_ENDIAN_BIG) +endif() + + if(ENABLE_LAUNCHER) add_definitions(-DENABLE_LAUNCHER) endif() diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index fd3e66a38..d9306edab 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -475,7 +475,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE) PUBLIC ${MAIN_LIB_DIR}/.. PUBLIC ${MAIN_LIB_DIR}/../include PUBLIC ${MAIN_LIB_DIR} - PRIVATE ${SDL2_INCLUDE_DIR} ) if(WIN32) diff --git a/lib/filesystem/CBinaryReader.cpp b/lib/filesystem/CBinaryReader.cpp index a3c7fc706..7385a903d 100644 --- a/lib/filesystem/CBinaryReader.cpp +++ b/lib/filesystem/CBinaryReader.cpp @@ -10,14 +10,12 @@ #include "StdInc.h" #include "CBinaryReader.h" -//FIXME:library file depends on SDL - make cause troubles -#include #include "CInputStream.h" #include "../CGeneralTextHandler.h" VCMI_LIB_NAMESPACE_BEGIN -#if SDL_BYTEORDER == SDL_BIG_ENDIAN +#ifdef VCMI_ENDIAN_BIG template CData readLE(CData data) { diff --git a/lib/vcmi_endian.h b/lib/vcmi_endian.h index 2686261f8..e270b8eec 100644 --- a/lib/vcmi_endian.h +++ b/lib/vcmi_endian.h @@ -9,8 +9,7 @@ */ #pragma once -//FIXME:library file depends on SDL - may cause troubles -#include +#include //FIXME: use std::byteswap in C++23 VCMI_LIB_NAMESPACE_BEGIN @@ -45,15 +44,15 @@ static inline ui32 read_unaligned_u32(const void *p) return v->val; } -#define read_le_u16(p) (SDL_SwapLE16(read_unaligned_u16(p))) -#define read_le_u32(p) (SDL_SwapLE32(read_unaligned_u32(p))) +#define read_le_u16(p) (boost::endian::native_to_little(read_unaligned_u16(p))) +#define read_le_u32(p) (boost::endian::native_to_little(read_unaligned_u32(p))) #else #warning UB: unaligned memory access -#define read_le_u16(p) (SDL_SwapLE16(* reinterpret_cast(p))) -#define read_le_u32(p) (SDL_SwapLE32(* reinterpret_cast(p))) +#define read_le_u16(p) (boost::endian::native_to_little(* reinterpret_cast(p))) +#define read_le_u32(p) (boost::endian::native_to_little(* reinterpret_cast(p))) #define PACKED_STRUCT_BEGIN #define PACKED_STRUCT_END