SHA256
1
0
forked from pool/gzdoom
gzdoom/0001-Revert-Switch-to-miniz-from-zlib.patch

332 lines
12 KiB
Diff

From b0910739a3fe9ade92356f2ed510049ebbccbec9 Mon Sep 17 00:00:00 2001
From: Jan Engelhardt <jengelh@inai.de>
Date: Fri, 27 Oct 2023 09:01:47 +0200
Subject: [PATCH] Revert "Switch to miniz from zlib"
This reverts commit ba9ce0e83f6e25e3ddef5000bd51d53f2e3947a2.
---
CMakeLists.txt | 13 ++++++++++++-
src/CMakeLists.txt | 4 ++--
src/common/audio/music/i_music.cpp | 2 +-
src/common/engine/serializer.cpp | 2 +-
src/common/filesystem/source/files_decompress.cpp | 2 +-
src/common/filesystem/source/filesystem.cpp | 2 +-
src/common/filesystem/source/resourcefile.cpp | 2 +-
src/common/models/model.cpp | 13 +++++++++++--
src/common/platform/win32/i_crash.cpp | 2 +-
src/common/textures/m_png.cpp | 2 +-
src/common/thirdparty/m_crc32.h | 5 +++--
src/g_pch.h | 2 +-
src/g_pch2.h | 2 +-
src/maploader/glnodes.cpp | 2 +-
src/serializer_doom.cpp | 2 +-
tools/zipdir/CMakeLists.txt | 4 ++--
tools/zipdir/zipdir.c | 2 +-
vcpkg.json | 4 ++++
18 files changed, 46 insertions(+), 21 deletions(-)
Index: gzdoom-g4.12.2/CMakeLists.txt
===================================================================
--- gzdoom-g4.12.2.orig/CMakeLists.txt
+++ gzdoom-g4.12.2/CMakeLists.txt
@@ -216,6 +216,7 @@ option( NO_OPENAL "Disable OpenAL sound
find_package( BZip2 )
find_package( VPX )
+find_package( ZLIB )
include( TargetArch )
@@ -333,6 +334,7 @@ set( CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE
set( CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${REL_C_FLAGS}" )
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEB_C_FLAGS} -D_DEBUG" )
+option(FORCE_INTERNAL_ZLIB "Use internal zlib")
option(FORCE_INTERNAL_BZIP2 "Use internal bzip2")
option(FORCE_INTERNAL_ASMJIT "Use internal asmjit" ON)
mark_as_advanced( FORCE_INTERNAL_ASMJIT )
@@ -349,6 +351,16 @@ set( DRPC_INCLUDE_DIR "-I/ignore" )
set( DRPC_LIBRARIES -ldiscord-rpc )
set( DRPC_LIBRARY -ldiscord-rpc )
+if( ZLIB_FOUND AND NOT FORCE_INTERNAL_ZLIB )
+ message( STATUS "Using system zlib, includes found at ${ZLIB_INCLUDE_DIR}" )
+else()
+ message( STATUS "Using internal zlib" )
+ set( SKIP_INSTALL_ALL TRUE ) # Avoid installing zlib
+ set( ZLIB_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libraries/zlib )
+ set( ZLIB_LIBRARIES z )
+ set( ZLIB_LIBRARY z )
+endif()
+
if( HAVE_VM_JIT AND UNIX )
check_symbol_exists( "backtrace" "execinfo.h" HAVE_BACKTRACE )
if( NOT HAVE_BACKTRACE )
@@ -406,7 +418,6 @@ install(DIRECTORY docs/
option( DYN_OPENAL "Dynamically load OpenAL" ON )
-add_subdirectory( libraries/miniz )
add_subdirectory( tools )
add_subdirectory( wadsrc )
add_subdirectory( wadsrc_bm )
Index: gzdoom-g4.12.2/src/CMakeLists.txt
===================================================================
--- gzdoom-g4.12.2.orig/src/CMakeLists.txt
+++ gzdoom-g4.12.2/src/CMakeLists.txt
@@ -344,7 +344,7 @@ add_custom_target( revision_check ALL
# required libraries
-set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} miniz "${BZIP2_LIBRARIES}" "${CMAKE_DL_LIBS}" "${DRPC_LIBRARIES}")
+set( PROJECT_LIBRARIES ${PROJECT_LIBRARIES} "${ZLIB_LIBRARIES}" "${BZIP2_LIBRARIES}" "${CMAKE_DL_LIBS}" "${DRPC_LIBRARIES}")
if (HAVE_VULKAN)
list( APPEND PROJECT_LIBRARIES "zvulkan" )
endif()
@@ -408,7 +408,7 @@ else()
message( SEND_ERROR "Could not find libvpx" )
endif()
-include_directories( SYSTEM "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIRS}" "${ZMUSIC_INCLUDE_DIR}" "${DRPC_INCLUDE_DIR}")
+include_directories( SYSTEM "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIRS}" "${ZMUSIC_INCLUDE_DIR}" "${DRPC_INCLUDE_DIR}")
if( ${HAVE_VM_JIT} )
add_definitions( -DHAVE_VM_JIT )
Index: gzdoom-g4.12.2/src/common/audio/music/i_music.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/common/audio/music/i_music.cpp
+++ gzdoom-g4.12.2/src/common/audio/music/i_music.cpp
@@ -37,7 +37,7 @@
#include <sys/wait.h>
#endif
-#include <miniz.h>
+#include <zlib.h>
#include <zmusic.h>
#include "filesystem.h"
Index: gzdoom-g4.12.2/src/common/engine/serializer.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/common/engine/serializer.cpp
+++ gzdoom-g4.12.2/src/common/engine/serializer.cpp
@@ -37,7 +37,7 @@
#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
#define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseFullPrecisionFlag
-#include <miniz.h>
+#include <zlib.h>
#include "rapidjson/rapidjson.h"
#include "rapidjson/writer.h"
#include "rapidjson/prettywriter.h"
Index: gzdoom-g4.12.2/src/common/filesystem/source/files_decompress.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/common/filesystem/source/files_decompress.cpp
+++ gzdoom-g4.12.2/src/common/filesystem/source/files_decompress.cpp
@@ -39,7 +39,7 @@
#include "Xz.h"
// CRC table needs to be generated prior to reading XZ compressed files.
#include "7zCrc.h"
-#include <miniz.h>
+#include <zlib.h>
#include <bzlib.h>
#include <algorithm>
#include <stdexcept>
Index: gzdoom-g4.12.2/src/common/filesystem/source/filesystem.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/common/filesystem/source/filesystem.cpp
+++ gzdoom-g4.12.2/src/common/filesystem/source/filesystem.cpp
@@ -36,7 +36,7 @@
// HEADER FILES ------------------------------------------------------------
-#include <miniz.h>
+#include <zlib.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
Index: gzdoom-g4.12.2/src/common/filesystem/source/resourcefile.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/common/filesystem/source/resourcefile.cpp
+++ gzdoom-g4.12.2/src/common/filesystem/source/resourcefile.cpp
@@ -35,7 +35,7 @@
*/
#include <algorithm>
-#include <miniz.h>
+#include <zlib.h>
#include "resourcefile.h"
#include "md5.hpp"
#include "fs_stringpool.h"
Index: gzdoom-g4.12.2/src/common/models/model.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/common/models/model.cpp
+++ gzdoom-g4.12.2/src/common/models/model.cpp
@@ -25,7 +25,6 @@
** General model handling code
**
**/
-#include <stddef.h> // offsetof() macro.
#include "filesystem.h"
#include "cmdlib.h"
@@ -132,7 +131,17 @@ FTextureID LoadSkin(const char * path, c
int ModelFrameHash(FSpriteModelFrame * smf)
{
- return crc32(0, (const unsigned char *)(&smf->type), offsetof(FSpriteModelFrame, hashnext) - offsetof(FSpriteModelFrame, type));
+ const uint32_t *table = GetCRCTable ();
+ uint32_t hash = 0xffffffff;
+
+ const char * s = (const char *)(&smf->type); // this uses type, sprite and frame for hashing
+ const char * se= (const char *)(&smf->hashnext);
+
+ for (; s<se; s++)
+ {
+ hash = CRC1 (hash, *s, table);
+ }
+ return hash ^ 0xffffffff;
}
//===========================================================================
Index: gzdoom-g4.12.2/src/common/platform/win32/i_crash.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/common/platform/win32/i_crash.cpp
+++ gzdoom-g4.12.2/src/common/platform/win32/i_crash.cpp
@@ -68,7 +68,7 @@
#include "i_mainwindow.h"
#include <time.h>
-#include <miniz.h>
+#include <zlib.h>
// MACROS ------------------------------------------------------------------
Index: gzdoom-g4.12.2/src/common/textures/m_png.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/common/textures/m_png.cpp
+++ gzdoom-g4.12.2/src/common/textures/m_png.cpp
@@ -36,7 +36,7 @@
#include <algorithm>
#include <stdlib.h>
-#include <miniz.h>
+#include <zlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <malloc.h> // for alloca()
Index: gzdoom-g4.12.2/src/common/thirdparty/m_crc32.h
===================================================================
--- gzdoom-g4.12.2.orig/src/common/thirdparty/m_crc32.h
+++ gzdoom-g4.12.2/src/common/thirdparty/m_crc32.h
@@ -32,11 +32,12 @@
**
*/
#pragma once
-#include <miniz.h>
+#include <zlib.h>
#include <stdint.h>
-// miniz includes some CRC32 stuff, so just use that
+// zlib includes some CRC32 stuff, so just use that
+inline const uint32_t *GetCRCTable () { return (const uint32_t *)get_crc_table(); }
inline uint32_t CalcCRC32 (const uint8_t *buf, unsigned int len)
{
return crc32 (0, buf, len);
Index: gzdoom-g4.12.2/src/g_pch.h
===================================================================
--- gzdoom-g4.12.2.orig/src/g_pch.h
+++ gzdoom-g4.12.2/src/g_pch.h
@@ -10,7 +10,7 @@
#include <errno.h>
#include <ctype.h>
#include <stdint.h>
-#include <miniz.h>
+#include <zlib.h>
#include <new>
#include <algorithm>
#include <forward_list>
Index: gzdoom-g4.12.2/src/g_pch2.h
===================================================================
--- gzdoom-g4.12.2.orig/src/g_pch2.h
+++ gzdoom-g4.12.2/src/g_pch2.h
@@ -11,7 +11,7 @@
#include <errno.h>
#include <ctype.h>
#include <stdint.h>
-#include <miniz.h>
+#include <zlib.h>
#include <new>
#include <algorithm>
#include <sys/stat.h>
Index: gzdoom-g4.12.2/src/maploader/glnodes.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/maploader/glnodes.cpp
+++ gzdoom-g4.12.2/src/maploader/glnodes.cpp
@@ -42,7 +42,7 @@
#endif
-#include <miniz.h>
+#include <zlib.h>
#include "m_argv.h"
#include "c_dispatch.h"
Index: gzdoom-g4.12.2/src/serializer_doom.cpp
===================================================================
--- gzdoom-g4.12.2.orig/src/serializer_doom.cpp
+++ gzdoom-g4.12.2/src/serializer_doom.cpp
@@ -38,7 +38,7 @@
#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
#define RAPIDJSON_PARSE_DEFAULT_FLAGS kParseFullPrecisionFlag
-#include <miniz.h>
+#include <zlib.h>
#include "rapidjson/rapidjson.h"
#include "rapidjson/writer.h"
#include "rapidjson/prettywriter.h"
Index: gzdoom-g4.12.2/tools/zipdir/CMakeLists.txt
===================================================================
--- gzdoom-g4.12.2.orig/tools/zipdir/CMakeLists.txt
+++ gzdoom-g4.12.2/tools/zipdir/CMakeLists.txt
@@ -1,9 +1,9 @@
cmake_minimum_required( VERSION 3.16 )
if( NOT CMAKE_CROSSCOMPILING )
- include_directories( SYSTEM "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIRS}" )
+ include_directories( SYSTEM "${ZLIB_INCLUDE_DIR}" "${BZIP2_INCLUDE_DIR}" "${LZMA_INCLUDE_DIRS}" )
add_executable( zipdir
zipdir.c )
- target_link_libraries( zipdir miniz ${BZIP2_LIBRARIES} ${LZMA_LDFLAGS} )
+ target_link_libraries( zipdir ${ZLIB_LIBRARIES} ${BZIP2_LIBRARIES} ${LZMA_LDFLAGS} )
set( CROSS_EXPORTS ${CROSS_EXPORTS} zipdir PARENT_SCOPE )
endif()
Index: gzdoom-g4.12.2/tools/zipdir/zipdir.c
===================================================================
--- gzdoom-g4.12.2.orig/tools/zipdir/zipdir.c
+++ gzdoom-g4.12.2/tools/zipdir/zipdir.c
@@ -46,7 +46,7 @@
#include <errno.h>
#include <stdlib.h>
#include <time.h>
-#include <miniz.h>
+#include "zlib.h"
#include "bzlib.h"
#include "LzmaEnc.h"
#include "7zVersion.h"
Index: gzdoom-g4.12.2/vcpkg.json
===================================================================
--- gzdoom-g4.12.2.orig/vcpkg.json
+++ gzdoom-g4.12.2/vcpkg.json
@@ -28,6 +28,10 @@
},
"dependencies": [
{
+ "name": "zlib",
+ "platform": "!windows | (windows & static & staticcrt)"
+ },
+ {
"name": "bzip2",
"platform": "(!windows & static) | (windows & static & staticcrt)"
},