Skip to content

Commit bfa9891

Browse files
authored
[CMAKE] Add VCPKG package manager and use for ZLib (#605)
1 parent 0bc50ad commit bfa9891

File tree

8 files changed

+45
-43
lines changed

8 files changed

+45
-43
lines changed

.github/workflows/build-toolchain.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ jobs:
102102
with:
103103
arch: x86
104104

105+
- name: Setup vcpkg
106+
uses: lukka/run-vcpkg@v11
107+
105108
- name: Configure ${{ inputs.game }} with CMake Using ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Preset
106109
shell: pwsh
107110
run: |
@@ -138,7 +141,7 @@ jobs:
138141
} else {
139142
$files = Get-ChildItem -Path "$buildDir\Core","$buildDir\${{ inputs.game }}" -File | Where-Object { $_.Extension -in @(".exe", ".dll", ".pdb") } -Verbose
140143
}
141-
$files | Move-Item -Destination $artifactsDir -Verbose
144+
$files | Move-Item -Destination $artifactsDir -Verbose -Force
142145
143146
- name: Upload ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
144147
uses: actions/upload-artifact@v4

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ endif()
5656
include(cmake/config.cmake)
5757
include(cmake/gamespy.cmake)
5858
include(cmake/lzhl.cmake)
59-
include(cmake/zlib.cmake)
6059

6160
add_subdirectory(Dependencies/Benchmark)
6261
if (IS_VS6_BUILD)

CMakePresets.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL",
1818
"CMAKE_MSVC_DEBUG_INFORMATION_FORMAT": "$<$<CONFIG:Release,Debug,RelWithDebInfo>:ProgramDatabase>",
1919
"CMAKE_BUILD_TYPE": "Release",
20-
"RTS_FLAGS": "/W3"
20+
"RTS_FLAGS": "/W3",
21+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
22+
"VCPKG_TARGET_TRIPLET": "x86-windows"
2123
},
2224
"vendor": {
2325
"jetbrains.com/clion": {
@@ -61,7 +63,8 @@
6163
"cacheVariables": {
6264
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
6365
"CMAKE_MSVC_DEBUG_INFORMATION_FORMAT": "$<$<CONFIG:Release,Debug,RelWithDebInfo>:Embedded>",
64-
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL"
66+
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL",
67+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
6568
}
6669
},
6770
{

Core/Libraries/Source/Compression/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ target_link_libraries(core_compression PRIVATE
3434
corei_libraries_include
3535
)
3636

37+
3738
target_link_libraries(core_compression PUBLIC
3839
liblzhl
39-
libzlib
4040
)
41+
42+
find_package(ZLIB)
43+
if (ZLIB_FOUND)
44+
target_link_libraries(core_compression PUBLIC ZLIB::ZLIB)
45+
target_compile_definitions(core_compression PUBLIC RTS_HAS_ZLIB)
46+
endif()

Core/Libraries/Source/Compression/Compression.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ enum CompressionType
3333
COMPRESSION_NONE = COMPRESSION_MIN,
3434
COMPRESSION_REFPACK,
3535
COMPRESSION_NOXLZH,
36+
#ifdef RTS_HAS_ZLIB
3637
COMPRESSION_ZLIB1,
3738
COMPRESSION_ZLIB2,
3839
COMPRESSION_ZLIB3,
@@ -42,6 +43,7 @@ enum CompressionType
4243
COMPRESSION_ZLIB7,
4344
COMPRESSION_ZLIB8,
4445
COMPRESSION_ZLIB9,
46+
#endif
4547
COMPRESSION_BTREE,
4648
COMPRESSION_HUFF,
4749
COMPRESSION_MAX = COMPRESSION_HUFF,

Core/Libraries/Source/Compression/CompressionManager.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@
2323

2424
#include "Compression.h"
2525
#include "LZHCompress/NoxCompress.h"
26-
extern "C" {
27-
#include "ZLib/zlib.h"
28-
}
26+
#ifdef RTS_HAS_ZLIB
27+
#define __MACTYPES__
28+
#include <zlib.h>
29+
#endif
2930
#include "EAC/codex.h"
3031
#include "EAC/btreecodex.h"
3132
#include "EAC/huffcodex.h"
@@ -46,6 +47,7 @@ const char *CompressionManager::getCompressionNameByType( CompressionType compTy
4647
"No compression",
4748
"RefPack",
4849
"LZHL",
50+
#ifdef RTS_HAS_ZLIB
4951
"ZLib 1 (fast)",
5052
"ZLib 2",
5153
"ZLib 3",
@@ -55,6 +57,7 @@ const char *CompressionManager::getCompressionNameByType( CompressionType compTy
5557
"ZLib 7",
5658
"ZLib 8",
5759
"ZLib 9 (slow)",
60+
#endif
5861
"BTree",
5962
"Huff",
6063
};
@@ -68,6 +71,7 @@ const char *CompressionManager::getDecompressionNameByType( CompressionType comp
6871
"d_None",
6972
"d_RefPack",
7073
"d_NoxLZW",
74+
#ifdef RTS_HAS_ZLIB
7175
"d_ZLib1",
7276
"d_ZLib2",
7377
"d_ZLib3",
@@ -77,6 +81,7 @@ const char *CompressionManager::getDecompressionNameByType( CompressionType comp
7781
"d_ZLib7",
7882
"d_ZLib8",
7983
"d_ZLib9",
84+
#endif
8085
"d_BTree",
8186
"d_Huff",
8287
};
@@ -104,7 +109,7 @@ CompressionType CompressionManager::getCompressionType( const void *mem, Int len
104109

105110
if ( memcmp( mem, "NOX\0", 4 ) == 0 )
106111
return COMPRESSION_NOXLZH;
107-
112+
#ifdef RTS_HAS_ZLIB
108113
if ( memcmp( mem, "ZL1\0", 4 ) == 0 )
109114
return COMPRESSION_ZLIB1;
110115
if ( memcmp( mem, "ZL2\0", 4 ) == 0 )
@@ -123,6 +128,7 @@ CompressionType CompressionManager::getCompressionType( const void *mem, Int len
123128
return COMPRESSION_ZLIB8;
124129
if ( memcmp( mem, "ZL9\0", 4 ) == 0 )
125130
return COMPRESSION_ZLIB9;
131+
#endif
126132
if ( memcmp( mem, "EAB\0", 4 ) == 0 )
127133
return COMPRESSION_BTREE;
128134
if ( memcmp( mem, "EAH\0", 4 ) == 0 )
@@ -144,7 +150,7 @@ Int CompressionManager::getMaxCompressedSize( Int uncompressedLen, CompressionTy
144150
case COMPRESSION_HUFF: // guessing here
145151
case COMPRESSION_REFPACK: // guessing here
146152
return uncompressedLen + 8;
147-
153+
#ifdef RTS_HAS_ZLIB
148154
case COMPRESSION_ZLIB1:
149155
case COMPRESSION_ZLIB2:
150156
case COMPRESSION_ZLIB3:
@@ -155,6 +161,7 @@ Int CompressionManager::getMaxCompressedSize( Int uncompressedLen, CompressionTy
155161
case COMPRESSION_ZLIB8:
156162
case COMPRESSION_ZLIB9:
157163
return (Int)(ceil(uncompressedLen * 1.1 + 12 + 8));
164+
#endif
158165
}
159166

160167
return 0;
@@ -169,6 +176,7 @@ Int CompressionManager::getUncompressedSize( const void *mem, Int len )
169176
switch (compType)
170177
{
171178
case COMPRESSION_NOXLZH:
179+
#ifdef RTS_HAS_ZLIB
172180
case COMPRESSION_ZLIB1:
173181
case COMPRESSION_ZLIB2:
174182
case COMPRESSION_ZLIB3:
@@ -178,6 +186,7 @@ Int CompressionManager::getUncompressedSize( const void *mem, Int len )
178186
case COMPRESSION_ZLIB7:
179187
case COMPRESSION_ZLIB8:
180188
case COMPRESSION_ZLIB9:
189+
#endif
181190
case COMPRESSION_BTREE:
182191
case COMPRESSION_HUFF:
183192
case COMPRESSION_REFPACK:
@@ -251,6 +260,7 @@ Int CompressionManager::compressData( CompressionType compType, void *srcVoid, I
251260
return 0;
252261
}
253262

263+
#ifdef RTS_HAS_ZLIB
254264
if (compType >= COMPRESSION_ZLIB1 && compType <= COMPRESSION_ZLIB9)
255265
{
256266
Int level = compType - COMPRESSION_ZLIB1 + 1; // 1-9
@@ -259,7 +269,7 @@ Int CompressionManager::compressData( CompressionType compType, void *srcVoid, I
259269
*(Int *)(dest+4) = 0;
260270

261271
unsigned long outLen = destLen;
262-
Int err = z_compress2( dest+8, &outLen, src, srcLen, level );
272+
Int err = compress2( (Bytef*)dest+8, &outLen, (const Bytef*)src, srcLen, level );
263273

264274
if (err == Z_OK || err == Z_STREAM_END)
265275
{
@@ -272,6 +282,7 @@ Int CompressionManager::compressData( CompressionType compType, void *srcVoid, I
272282
return 0;
273283
}
274284
}
285+
#endif
275286

276287
return 0;
277288
}
@@ -323,10 +334,11 @@ Int CompressionManager::decompressData( void *srcVoid, Int srcLen, void *destVoi
323334
return 0;
324335
}
325336

337+
#ifdef RTS_HAS_ZLIB
326338
if (compType >= COMPRESSION_ZLIB1 && compType <= COMPRESSION_ZLIB9)
327339
{
328340
unsigned long outLen = destLen;
329-
Int err = z_uncompress(dest, &outLen, src+8, srcLen-8);
341+
Int err = uncompress((Bytef*)dest, &outLen, (const Bytef*)src+8, srcLen-8);
330342
if (err == Z_OK || err == Z_STREAM_END)
331343
{
332344
return outLen;
@@ -338,6 +350,7 @@ Int CompressionManager::decompressData( void *srcVoid, Int srcLen, void *destVoi
338350
return 0;
339351
}
340352
}
353+
#endif
341354

342355
return 0;
343356
}

cmake/zlib.cmake

Lines changed: 0 additions & 31 deletions
This file was deleted.

vcpkg.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
3+
"builtin-baseline": "b02e341c927f16d991edbd915d8ea43eac52096c",
4+
"dependencies": [
5+
"zlib"
6+
]
7+
}

0 commit comments

Comments
 (0)