mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2025-07-20 09:25:45 +00:00
(and core5compat) Signed-off-by: crueter <crueter@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/71
400 lines
14 KiB
Diff
400 lines
14 KiB
Diff
"Debloats" QuaZip by removing some unneeded stuff (Qt <6, bzip2, emscripten...)
|
|
|
|
This is completely optional.
|
|
|
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index b376fb2..4aac4ec 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -3,64 +3,16 @@ cmake_minimum_required(VERSION 3.15...3.18)
|
|
|
|
project(QuaZip VERSION 1.5)
|
|
|
|
-include(cmake/clone-repo.cmake)
|
|
-
|
|
set(QUAZIP_LIB_VERSION ${QuaZip_VERSION})
|
|
set(QUAZIP_LIB_SOVERSION 1.5.0)
|
|
|
|
-if(EMSCRIPTEN)
|
|
- #option(ZLIB_INCLUDE "Path to include dir" "")
|
|
- #option(ZLIB_LIBRARY "Path to library dir" "")
|
|
- option(BUILD_SHARED_LIBS "" OFF)
|
|
- option(QUAZIP_INSTALL "" OFF)
|
|
- option(QUAZIP_USE_QT_ZLIB "" OFF)
|
|
- option(QUAZIP_ENABLE_TESTS "Build QuaZip tests" OFF)
|
|
-else()
|
|
- option(BUILD_SHARED_LIBS "" ON)
|
|
- option(QUAZIP_INSTALL "" ON)
|
|
- option(QUAZIP_USE_QT_ZLIB "" OFF)
|
|
- option(QUAZIP_ENABLE_TESTS "Build QuaZip tests" OFF)
|
|
-endif()
|
|
+option(BUILD_SHARED_LIBS "" ON)
|
|
+option(QUAZIP_INSTALL "" ON)
|
|
+option(QUAZIP_ENABLE_TESTS "Build QuaZip tests" OFF)
|
|
|
|
OPTION(ZLIB_CONST "Sets ZLIB_CONST preprocessor definition" OFF)
|
|
|
|
-# Make BZIP2 optional
|
|
-option(QUAZIP_BZIP2 "Enables BZIP2 compression" ON)
|
|
-option(QUAZIP_BZIP2_STDIO "Output BZIP2 errors to stdio" ON)
|
|
-
|
|
-option(QUAZIP_FETCH_LIBS "Enables fetching third-party libraries if not found" ${WIN32})
|
|
-option(QUAZIP_FORCE_FETCH_LIBS "Enables fetching third-party libraries always" OFF)
|
|
-
|
|
-if (QUAZIP_USE_QT_ZLIB AND BUILD_SHARED_LIBS)
|
|
- message(FATAL_ERROR "Using BUILD_SHARED_LIBS=ON together with QUAZIP_USE_QT_ZLIB=ON is not supported." )
|
|
-endif()
|
|
-
|
|
-# Set the default value of `${QUAZIP_QT_MAJOR_VERSION}`.
|
|
-# We search quietly for Qt6, Qt5 and Qt4 in that order.
|
|
-# Qt6 and Qt5 provide config files for CMake.
|
|
-# Qt4 relies on `FindQt4.cmake`.
|
|
-find_package(
|
|
- QT NAMES Qt6 Qt5
|
|
- QUIET COMPONENTS Core
|
|
-)
|
|
-if (NOT QT_FOUND)
|
|
- find_package(Qt4 QUIET COMPONENTS QtCore)
|
|
- if (Qt4_FOUND)
|
|
- set(QT_VERSION_MAJOR 4)
|
|
- else()
|
|
- # If neither 6, 5 nor 4 are found, we default to 5.
|
|
- # The setup will fail further down.
|
|
- set(QT_VERSION_MAJOR 5)
|
|
- endif()
|
|
-endif()
|
|
-
|
|
-set(QUAZIP_QT_MAJOR_VERSION ${QT_VERSION_MAJOR} CACHE STRING "Qt version to use (4, 5 or 6), defaults to ${QT_VERSION_MAJOR}")
|
|
-
|
|
-if (QUAZIP_QT_MAJOR_VERSION EQUAL 6)
|
|
- set(CMAKE_CXX_STANDARD 17)
|
|
-else()
|
|
- set(CMAKE_CXX_STANDARD 14)
|
|
-endif()
|
|
+set(CMAKE_CXX_STANDARD 17)
|
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
set(CMAKE_BUILD_TYPE RELEASE)
|
|
@@ -77,92 +29,17 @@ set(QUAZIP_LIB_TARGET_NAME QuaZip)
|
|
set(QUAZIP_DIR_NAME QuaZip-Qt${QUAZIP_QT_MAJOR_VERSION}-${QUAZIP_LIB_VERSION})
|
|
set(QUAZIP_PACKAGE_NAME QuaZip-Qt${QUAZIP_QT_MAJOR_VERSION})
|
|
|
|
-message(STATUS "QUAZIP_QT_MAJOR_VERSION set to ${QUAZIP_QT_MAJOR_VERSION}")
|
|
-message(STATUS "CMAKE_CXX_STANDARD set to ${CMAKE_CXX_STANDARD}")
|
|
-
|
|
-if(QUAZIP_QT_MAJOR_VERSION EQUAL 6)
|
|
- find_package(Qt6 REQUIRED COMPONENTS Core Core5Compat
|
|
- OPTIONAL_COMPONENTS Network Test)
|
|
- message(STATUS "Found Qt version ${Qt6_VERSION} at ${Qt6_DIR}")
|
|
- set(QUAZIP_QT_ZLIB_COMPONENT BundledZLIB)
|
|
- set(QUAZIP_QT_ZLIB_HEADER_COMPONENT ZlibPrivate)
|
|
- set(QUAZIP_LIB_LIBRARIES Qt6::Core Qt6::Core5Compat)
|
|
- set(QUAZIP_TEST_QT_LIBRARIES Qt6::Core Qt6::Core5Compat Qt6::Network Qt6::Test)
|
|
- set(QUAZIP_PKGCONFIG_REQUIRES "zlib, Qt6Core")
|
|
-elseif(QUAZIP_QT_MAJOR_VERSION EQUAL 5)
|
|
- find_package(Qt5 REQUIRED COMPONENTS Core
|
|
- OPTIONAL_COMPONENTS Network Test)
|
|
- message(STATUS "Found Qt version ${Qt5_VERSION} at ${Qt5_DIR}")
|
|
- set(QUAZIP_QT_ZLIB_COMPONENT Zlib)
|
|
- set(QUAZIP_LIB_LIBRARIES Qt5::Core)
|
|
- set(QUAZIP_TEST_QT_LIBRARIES Qt5::Core Qt5::Network Qt5::Test)
|
|
- set(QUAZIP_PKGCONFIG_REQUIRES "zlib, Qt5Core")
|
|
-elseif(QUAZIP_QT_MAJOR_VERSION EQUAL 4)
|
|
- find_package(Qt4 4.5.0 REQUIRED COMPONENTS QtCore
|
|
- OPTIONAL_COMPONENTS QtNetwork QtTest)
|
|
- set(QUAZIP_QT_ZLIB_COMPONENT Zlib)
|
|
- set(QUAZIP_LIB_LIBRARIES Qt4::QtCore)
|
|
- set(QUAZIP_TEST_QT_LIBRARIES Qt4::QtCore Qt4::QtNetwork Qt4::QtTest)
|
|
- set(QUAZIP_PKGCONFIG_REQUIRES "zlib, QtCore")
|
|
-else()
|
|
- message(FATAL_ERROR "Qt version ${QUAZIP_QT_MAJOR_VERSION} is not supported")
|
|
-endif()
|
|
-
|
|
-message(STATUS "Using Qt version ${QUAZIP_QT_MAJOR_VERSION}")
|
|
-
|
|
-set(QUAZIP_QT_ZLIB_USED OFF)
|
|
-if(QUAZIP_USE_QT_ZLIB)
|
|
- find_package(Qt${QUAZIP_QT_MAJOR_VERSION} OPTIONAL_COMPONENTS ${QUAZIP_QT_ZLIB_COMPONENT})
|
|
- set(QUAZIP_QT_ZLIB_COMPONENT_FOUND Qt${QUAZIP_QT_MAJOR_VERSION}${QUAZIP_QT_ZLIB_COMPONENT}_FOUND)
|
|
- if (DEFINED QUAZIP_QT_ZLIB_HEADER_COMPONENT)
|
|
- find_package(Qt${QUAZIP_QT_MAJOR_VERSION} OPTIONAL_COMPONENTS ${QUAZIP_QT_ZLIB_HEADER_COMPONENT})
|
|
- set(QUAZIP_QT_ZLIB_HEADER_COMPONENT_FOUND Qt${QUAZIP_QT_MAJOR_VERSION}${QUAZIP_QT_ZLIB_HEADER_COMPONENT}_FOUND)
|
|
- else()
|
|
- set(QUAZIP_QT_ZLIB_HEADER_COMPONENT_FOUND ON)
|
|
- endif()
|
|
- if(QUAZIP_QT_ZLIB_COMPONENT_FOUND AND QUAZIP_QT_ZLIB_HEADER_COMPONENT_FOUND)
|
|
- message(STATUS "Qt component ${QUAZIP_QT_ZLIB_COMPONENT} found")
|
|
- set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} Qt${QUAZIP_QT_MAJOR_VERSION}::${QUAZIP_QT_ZLIB_COMPONENT})
|
|
- if(DEFINED QUAZIP_QT_ZLIB_HEADER_COMPONENT)
|
|
- message(STATUS "Qt component ${QUAZIP_QT_ZLIB_HEADER_COMPONENT} found")
|
|
- set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} Qt${QUAZIP_QT_MAJOR_VERSION}::${QUAZIP_QT_ZLIB_HEADER_COMPONENT})
|
|
- endif()
|
|
- set(QUAZIP_QT_ZLIB_USED ON)
|
|
- else()
|
|
- message(FATAL_ERROR "QUAZIP_USE_QT_ZLIB was set but bundled zlib was not found. Terminating to prevent accidental linking to system libraries.")
|
|
- endif()
|
|
-endif()
|
|
-
|
|
-if(QUAZIP_QT_ZLIB_USED AND QUAZIP_QT_ZLIB_COMPONENT STREQUAL BundledZLIB)
|
|
- # Qt's new BundledZLIB uses z-prefix in zlib
|
|
- add_compile_definitions(Z_PREFIX)
|
|
-endif()
|
|
-
|
|
-if(NOT QUAZIP_QT_ZLIB_USED)
|
|
-
|
|
- if(EMSCRIPTEN)
|
|
- if(NOT DEFINED ZLIB_LIBRARY)
|
|
- message(WARNING "ZLIB_LIBRARY is not set")
|
|
- endif()
|
|
+find_package(Qt6 REQUIRED COMPONENTS Core Core5Compat
|
|
+ OPTIONAL_COMPONENTS Network Test)
|
|
+message(STATUS "Found Qt version ${Qt6_VERSION} at ${Qt6_DIR}")
|
|
+set(QUAZIP_QT_ZLIB_COMPONENT BundledZLIB)
|
|
+set(QUAZIP_QT_ZLIB_HEADER_COMPONENT ZlibPrivate)
|
|
+set(QUAZIP_LIB_LIBRARIES Qt6::Core Qt6::Core5Compat)
|
|
+set(QUAZIP_TEST_QT_LIBRARIES Qt6::Core Qt6::Core5Compat Qt6::Network Qt6::Test)
|
|
+set(QUAZIP_PKGCONFIG_REQUIRES "zlib, Qt6Core")
|
|
|
|
- if(NOT DEFINED ZLIB_INCLUDE)
|
|
- message(WARNING "ZLIB_INCLUDE is not set")
|
|
- else()
|
|
- include_directories(${ZLIB_INCLUDE})
|
|
- endif()
|
|
-
|
|
- if(NOT DEFINED ZCONF_INCLUDE)
|
|
- message(WARNING "ZCONF_INCLUDE is not set")
|
|
- else()
|
|
- include_directories(${ZCONF_INCLUDE})
|
|
- endif()
|
|
-
|
|
- set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} ${ZLIB_LIBRARY})
|
|
- else()
|
|
- find_package(ZLIB REQUIRED)
|
|
- set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} ZLIB::ZLIB)
|
|
- endif()
|
|
-endif()
|
|
+find_package(ZLIB REQUIRED)
|
|
+set(QUAZIP_LIB_LIBRARIES ${QUAZIP_LIB_LIBRARIES} ZLIB::ZLIB)
|
|
|
|
if (ZLIB_CONST)
|
|
add_compile_definitions(ZLIB_CONST)
|
|
@@ -173,65 +50,4 @@ set(QUAZIP_INC)
|
|
set(QUAZIP_LIB)
|
|
set(QUAZIP_LBD)
|
|
|
|
-if(QUAZIP_BZIP2)
|
|
- # Check if bzip2 is present
|
|
- set(QUAZIP_BZIP2 ON)
|
|
-
|
|
- if(NOT QUAZIP_FORCE_FETCH_LIBS)
|
|
- find_package(BZip2 QUIET)
|
|
- endif()
|
|
-
|
|
- if(BZIP2_FOUND AND NOT QUAZIP_FORCE_FETCH_LIBS)
|
|
- message(STATUS "Using BZIP2 ${BZIP2_VERSION_STRING}")
|
|
-
|
|
- list(APPEND QUAZIP_INC ${BZIP2_INCLUDE_DIRS})
|
|
- list(APPEND QUAZIP_LIB ${BZIP2_LIBRARIES})
|
|
- list(APPEND QUAZIP_LBD ${BZIP2_LIBRARY_DIRS})
|
|
-
|
|
- set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -lbzip2")
|
|
- elseif(QUAZIP_FETCH_LIBS)
|
|
- clone_repo(bzip2 https://sourceware.org/git/bzip2.git)
|
|
-
|
|
- # BZip2 repository does not support cmake so we have to create
|
|
- # the bzip2 library ourselves
|
|
- set(BZIP2_SRC
|
|
- ${BZIP2_SOURCE_DIR}/blocksort.c
|
|
- ${BZIP2_SOURCE_DIR}/bzlib.c
|
|
- ${BZIP2_SOURCE_DIR}/compress.c
|
|
- ${BZIP2_SOURCE_DIR}/crctable.c
|
|
- ${BZIP2_SOURCE_DIR}/decompress.c
|
|
- ${BZIP2_SOURCE_DIR}/huffman.c
|
|
- ${BZIP2_SOURCE_DIR}/randtable.c)
|
|
-
|
|
- set(BZIP2_HDR
|
|
- ${BZIP2_SOURCE_DIR}/bzlib.h
|
|
- ${BZIP2_SOURCE_DIR}/bzlib_private.h)
|
|
-
|
|
- add_library(bzip2 STATIC ${BZIP2_SRC} ${BZIP2_HDR})
|
|
-
|
|
- if(NOT QUAZIP_BZIP2_STDIO)
|
|
- target_compile_definitions(bzip2 PRIVATE -DBZ_NO_STDIO)
|
|
- endif()
|
|
-
|
|
- list(APPEND QUAZIP_DEP bzip2)
|
|
- list(APPEND QUAZIP_LIB bzip2)
|
|
- list(APPEND QUAZIP_INC ${BZIP2_SOURCE_DIR})
|
|
- else()
|
|
- message(STATUS "BZip2 library not found")
|
|
-
|
|
- set(QUAZIP_BZIP2 OFF)
|
|
- endif()
|
|
-
|
|
- if(QUAZIP_BZIP2)
|
|
- find_package(BZip2)
|
|
- add_compile_definitions(HAVE_BZIP2)
|
|
- endif()
|
|
-endif()
|
|
-
|
|
add_subdirectory(quazip)
|
|
-
|
|
-if(QUAZIP_ENABLE_TESTS)
|
|
- message(STATUS "Building QuaZip tests")
|
|
- enable_testing()
|
|
- add_subdirectory(qztest)
|
|
-endif()
|
|
diff --git a/quazip/CMakeLists.txt b/quazip/CMakeLists.txt
|
|
index 6cfdf4e..66bc4cb 100644
|
|
--- a/quazip/CMakeLists.txt
|
|
+++ b/quazip/CMakeLists.txt
|
|
@@ -46,10 +46,6 @@ set(QUAZIP_INCLUDE_PATH ${QUAZIP_DIR_NAME}/quazip)
|
|
set(QUAZIP_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake)
|
|
set(QUAZIP_PKGCONFIG_NAME quazip${QuaZip_VERSION_MAJOR}-qt${QUAZIP_QT_MAJOR_VERSION})
|
|
|
|
-if(EMSCRIPTEN)
|
|
- set(BUILD_SHARED_LIBS OFF)
|
|
-endif()
|
|
-
|
|
add_library(${QUAZIP_LIB_TARGET_NAME} ${QUAZIP_SOURCES})
|
|
add_library(QuaZip::QuaZip ALIAS ${QUAZIP_LIB_TARGET_NAME})
|
|
|
|
diff --git a/quazip/quazip_qt_compat.h b/quazip/quazip_qt_compat.h
|
|
index 0dde011..41f9dd1 100644
|
|
--- a/quazip/quazip_qt_compat.h
|
|
+++ b/quazip/quazip_qt_compat.h
|
|
@@ -14,16 +14,11 @@
|
|
|
|
// Legacy encodings are still everywhere, but the Qt team decided we
|
|
// don't need them anymore and moved them out of Core in Qt 6.
|
|
-#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
-# include <QtCore5Compat/QTextCodec>
|
|
-#else
|
|
-# include <QtCore/QTextCodec>
|
|
-#endif
|
|
+#include <QtCore5Compat/QTextCodec>
|
|
|
|
// QSaveFile terribly breaks the is-a idiom (Liskov substitution principle):
|
|
// QSaveFile is-a QIODevice, but it makes close() private and aborts
|
|
// if you call it through the base class. Hence this ugly hack:
|
|
-#if (QT_VERSION >= 0x050100)
|
|
#include <QtCore/QSaveFile>
|
|
inline bool quazip_close(QIODevice *device) {
|
|
QSaveFile *file = qobject_cast<QSaveFile*>(device);
|
|
@@ -34,74 +29,35 @@ inline bool quazip_close(QIODevice *device) {
|
|
device->close();
|
|
return true;
|
|
}
|
|
-#else
|
|
-inline bool quazip_close(QIODevice *device) {
|
|
- device->close();
|
|
- return true;
|
|
-}
|
|
-#endif
|
|
|
|
-// this is yet another stupid move and deprecation
|
|
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
|
using Qt::SkipEmptyParts;
|
|
-#else
|
|
-#include <QtCore/QString>
|
|
-const auto SkipEmptyParts = QString::SplitBehavior::SkipEmptyParts;
|
|
-#endif
|
|
|
|
// and yet another... (why didn't they just make qSort delegate to std::sort?)
|
|
#include <QtCore/QList>
|
|
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
|
#include <algorithm>
|
|
template<typename T, typename C>
|
|
inline void quazip_sort(T begin, T end, C comparator) {
|
|
std::sort(begin, end, comparator);
|
|
}
|
|
-#else
|
|
-#include <QtCore/QtAlgorithms>
|
|
-template<typename T, typename C>
|
|
-inline void quazip_sort(T begin, T end, C comparator) {
|
|
- qSort(begin, end, comparator);
|
|
-}
|
|
-#endif
|
|
|
|
// this is a stupid rename...
|
|
#include <QtCore/QDateTime>
|
|
#include <QtCore/QFileInfo>
|
|
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
|
|
inline QDateTime quazip_ctime(const QFileInfo &fi) {
|
|
return fi.birthTime();
|
|
}
|
|
-#else
|
|
-inline QDateTime quazip_ctime(const QFileInfo &fi) {
|
|
- return fi.created();
|
|
-}
|
|
-#endif
|
|
|
|
// this is just a slightly better alternative
|
|
#include <QtCore/QFileInfo>
|
|
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
|
inline bool quazip_is_symlink(const QFileInfo &fi) {
|
|
return fi.isSymbolicLink();
|
|
}
|
|
-#else
|
|
-inline bool quazip_is_symlink(const QFileInfo &fi) {
|
|
- // also detects *.lnk on Windows, but better than nothing
|
|
- return fi.isSymLink();
|
|
-}
|
|
-#endif
|
|
|
|
// I'm not even sure what this one is, but nevertheless
|
|
#include <QtCore/QFileInfo>
|
|
-#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
|
|
inline QString quazip_symlink_target(const QFileInfo &fi) {
|
|
return fi.symLinkTarget();
|
|
}
|
|
-#else
|
|
-inline QString quazip_symlink_target(const QFileInfo &fi) {
|
|
- return fi.readLink(); // What's the difference? I've no idea.
|
|
-}
|
|
-#endif
|
|
|
|
// deprecation
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
|
|
@@ -125,40 +81,19 @@ inline QDateTime quazip_since_epoch_ntfs() {
|
|
|
|
// this is not a deprecation but an improvement, for a change
|
|
#include <QtCore/QDateTime>
|
|
-#if (QT_VERSION >= 0x040700)
|
|
inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) {
|
|
QDateTime base = quazip_since_epoch_ntfs();
|
|
return base.msecsTo(time) * 10000 + fineTicks;
|
|
}
|
|
-#else
|
|
-inline quint64 quazip_ntfs_ticks(const QDateTime &time, int fineTicks) {
|
|
- QDateTime base = quazip_since_epoch_ntfs();
|
|
- QDateTime utc = time.toUTC();
|
|
- return (static_cast<qint64>(base.date().daysTo(utc.date()))
|
|
- * Q_INT64_C(86400000)
|
|
- + static_cast<qint64>(base.time().msecsTo(utc.time())))
|
|
- * Q_INT64_C(10000) + fineTicks;
|
|
-}
|
|
-#endif
|
|
|
|
// yet another improvement...
|
|
#include <QtCore/QDateTime>
|
|
-#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0) // Yay! Finally a way to get time as qint64!
|
|
inline qint64 quazip_to_time64_t(const QDateTime &time) {
|
|
return time.toSecsSinceEpoch();
|
|
}
|
|
-#else
|
|
-inline qint64 quazip_to_time64_t(const QDateTime &time) {
|
|
- return static_cast<qint64>(time.toTime_t()); // 32 bits only, but better than nothing
|
|
-}
|
|
-#endif
|
|
|
|
#include <QtCore/QTextStream>
|
|
-// and another stupid move
|
|
-#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
|
|
const auto quazip_endl = Qt::endl;
|
|
-#else
|
|
-const auto quazip_endl = endl;
|
|
-#endif
|
|
|
|
#endif // QUAZIP_QT_COMPAT_H
|
|
+
|