Skip to content

Commit 70e9eba

Browse files
authored
[CORE] Build non-vcpkg builds with zlib-1.1.4 again (#770)
1 parent 16343f3 commit 70e9eba

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

Core/Libraries/Source/Compression/CMakeLists.txt

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ target_link_libraries(core_compression PUBLIC
4141

4242
find_package(ZLIB)
4343
if (ZLIB_FOUND)
44+
# Adds zlib from vcpkg
4445
target_link_libraries(core_compression PUBLIC ZLIB::ZLIB)
45-
target_compile_definitions(core_compression PUBLIC RTS_HAS_ZLIB)
46-
endif()
46+
else()
47+
# Adds zlib from github repository
48+
include(${CMAKE_SOURCE_DIR}/cmake/zlib.cmake)
49+
target_link_libraries(core_compression PUBLIC libzlib)
50+
endif()

Core/Libraries/Source/Compression/Compression.h

-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ enum CompressionType
3333
COMPRESSION_NONE = COMPRESSION_MIN,
3434
COMPRESSION_REFPACK,
3535
COMPRESSION_NOXLZH,
36-
#ifdef RTS_HAS_ZLIB
3736
COMPRESSION_ZLIB1,
3837
COMPRESSION_ZLIB2,
3938
COMPRESSION_ZLIB3,
@@ -43,7 +42,6 @@ enum CompressionType
4342
COMPRESSION_ZLIB7,
4443
COMPRESSION_ZLIB8,
4544
COMPRESSION_ZLIB9,
46-
#endif
4745
COMPRESSION_BTREE,
4846
COMPRESSION_HUFF,
4947
COMPRESSION_MAX = COMPRESSION_HUFF,

Core/Libraries/Source/Compression/CompressionManager.cpp

+2-16
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
#include "Compression.h"
2525
#include "LZHCompress/NoxCompress.h"
26-
#ifdef RTS_HAS_ZLIB
26+
2727
#define __MACTYPES__
2828
#include <zlib.h>
29-
#endif
29+
3030
#include "EAC/codex.h"
3131
#include "EAC/btreecodex.h"
3232
#include "EAC/huffcodex.h"
@@ -47,7 +47,6 @@ const char *CompressionManager::getCompressionNameByType( CompressionType compTy
4747
"No compression",
4848
"RefPack",
4949
"LZHL",
50-
#ifdef RTS_HAS_ZLIB
5150
"ZLib 1 (fast)",
5251
"ZLib 2",
5352
"ZLib 3",
@@ -57,7 +56,6 @@ const char *CompressionManager::getCompressionNameByType( CompressionType compTy
5756
"ZLib 7",
5857
"ZLib 8",
5958
"ZLib 9 (slow)",
60-
#endif
6159
"BTree",
6260
"Huff",
6361
};
@@ -71,7 +69,6 @@ const char *CompressionManager::getDecompressionNameByType( CompressionType comp
7169
"d_None",
7270
"d_RefPack",
7371
"d_NoxLZW",
74-
#ifdef RTS_HAS_ZLIB
7572
"d_ZLib1",
7673
"d_ZLib2",
7774
"d_ZLib3",
@@ -81,7 +78,6 @@ const char *CompressionManager::getDecompressionNameByType( CompressionType comp
8178
"d_ZLib7",
8279
"d_ZLib8",
8380
"d_ZLib9",
84-
#endif
8581
"d_BTree",
8682
"d_Huff",
8783
};
@@ -109,7 +105,6 @@ CompressionType CompressionManager::getCompressionType( const void *mem, Int len
109105

110106
if ( memcmp( mem, "NOX\0", 4 ) == 0 )
111107
return COMPRESSION_NOXLZH;
112-
#ifdef RTS_HAS_ZLIB
113108
if ( memcmp( mem, "ZL1\0", 4 ) == 0 )
114109
return COMPRESSION_ZLIB1;
115110
if ( memcmp( mem, "ZL2\0", 4 ) == 0 )
@@ -128,7 +123,6 @@ CompressionType CompressionManager::getCompressionType( const void *mem, Int len
128123
return COMPRESSION_ZLIB8;
129124
if ( memcmp( mem, "ZL9\0", 4 ) == 0 )
130125
return COMPRESSION_ZLIB9;
131-
#endif
132126
if ( memcmp( mem, "EAB\0", 4 ) == 0 )
133127
return COMPRESSION_BTREE;
134128
if ( memcmp( mem, "EAH\0", 4 ) == 0 )
@@ -150,7 +144,6 @@ Int CompressionManager::getMaxCompressedSize( Int uncompressedLen, CompressionTy
150144
case COMPRESSION_HUFF: // guessing here
151145
case COMPRESSION_REFPACK: // guessing here
152146
return uncompressedLen + 8;
153-
#ifdef RTS_HAS_ZLIB
154147
case COMPRESSION_ZLIB1:
155148
case COMPRESSION_ZLIB2:
156149
case COMPRESSION_ZLIB3:
@@ -161,7 +154,6 @@ Int CompressionManager::getMaxCompressedSize( Int uncompressedLen, CompressionTy
161154
case COMPRESSION_ZLIB8:
162155
case COMPRESSION_ZLIB9:
163156
return (Int)(ceil(uncompressedLen * 1.1 + 12 + 8));
164-
#endif
165157
}
166158

167159
return 0;
@@ -176,7 +168,6 @@ Int CompressionManager::getUncompressedSize( const void *mem, Int len )
176168
switch (compType)
177169
{
178170
case COMPRESSION_NOXLZH:
179-
#ifdef RTS_HAS_ZLIB
180171
case COMPRESSION_ZLIB1:
181172
case COMPRESSION_ZLIB2:
182173
case COMPRESSION_ZLIB3:
@@ -186,7 +177,6 @@ Int CompressionManager::getUncompressedSize( const void *mem, Int len )
186177
case COMPRESSION_ZLIB7:
187178
case COMPRESSION_ZLIB8:
188179
case COMPRESSION_ZLIB9:
189-
#endif
190180
case COMPRESSION_BTREE:
191181
case COMPRESSION_HUFF:
192182
case COMPRESSION_REFPACK:
@@ -260,7 +250,6 @@ Int CompressionManager::compressData( CompressionType compType, void *srcVoid, I
260250
return 0;
261251
}
262252

263-
#ifdef RTS_HAS_ZLIB
264253
if (compType >= COMPRESSION_ZLIB1 && compType <= COMPRESSION_ZLIB9)
265254
{
266255
Int level = compType - COMPRESSION_ZLIB1 + 1; // 1-9
@@ -282,7 +271,6 @@ Int CompressionManager::compressData( CompressionType compType, void *srcVoid, I
282271
return 0;
283272
}
284273
}
285-
#endif
286274

287275
return 0;
288276
}
@@ -334,7 +322,6 @@ Int CompressionManager::decompressData( void *srcVoid, Int srcLen, void *destVoi
334322
return 0;
335323
}
336324

337-
#ifdef RTS_HAS_ZLIB
338325
if (compType >= COMPRESSION_ZLIB1 && compType <= COMPRESSION_ZLIB9)
339326
{
340327
unsigned long outLen = destLen;
@@ -350,7 +337,6 @@ Int CompressionManager::decompressData( void *srcVoid, Int srcLen, void *destVoi
350337
return 0;
351338
}
352339
}
353-
#endif
354340

355341
return 0;
356342
}

cmake/zlib.cmake

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
set(ZLIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/_deps/zlib-1.1.4-src/ZLib)
2+
3+
FetchContent_Populate(zlib DOWNLOAD_EXTRACT_TIMESTAMP
4+
GIT_REPOSITORY https://github.com/TheSuperHackers/zlib-1.1.4
5+
GIT_TAG ac753eee3990a2f592bd4807ff0b30ff572c2104
6+
SOURCE_DIR ${ZLIB_DIR}
7+
)
8+
9+
add_library(libzlib STATIC)
10+
11+
target_sources(libzlib PRIVATE
12+
"${ZLIB_DIR}/adler32.c"
13+
"${ZLIB_DIR}/compress.c"
14+
"${ZLIB_DIR}/crc32.c"
15+
"${ZLIB_DIR}/gzio.c"
16+
"${ZLIB_DIR}/uncompr.c"
17+
"${ZLIB_DIR}/deflate.c"
18+
"${ZLIB_DIR}/trees.c"
19+
"${ZLIB_DIR}/zutil.c"
20+
"${ZLIB_DIR}/inflate.c"
21+
"${ZLIB_DIR}/infblock.c"
22+
"${ZLIB_DIR}/inftrees.c"
23+
"${ZLIB_DIR}/infcodes.c"
24+
"${ZLIB_DIR}/infutil.c"
25+
"${ZLIB_DIR}/inffast.c"
26+
)
27+
28+
target_include_directories(libzlib PUBLIC ${ZLIB_DIR})
29+
30+
target_compile_definitions(libzlib PUBLIC Z_PREFIX)

0 commit comments

Comments
 (0)