Migrate the build system to cmake

This commit is contained in:
Luis Ángel San Martín Rodríguez
2026-02-25 09:19:39 +01:00
parent 5f8951ac09
commit 865020fe11
63 changed files with 1859 additions and 2060 deletions

View File

@ -0,0 +1,158 @@
# Comic archive decompression backend (cbx_backend)
# Switched on DECOMPRESSION_BACKEND: unarr | 7zip | libarchive
add_library(cbx_backend STATIC)
if(DECOMPRESSION_BACKEND STREQUAL "unarr")
message(STATUS "Decompression backend: unarr")
target_sources(cbx_backend PRIVATE
unarr/compressed_archive.cpp
unarr/compressed_archive.h
unarr/extract_delegate.h
)
target_include_directories(cbx_backend PUBLIC unarr)
target_compile_definitions(cbx_backend PUBLIC use_unarr)
# Try CMake config first, then pkg-config, then system path
find_package(unarr QUIET)
if(unarr_FOUND)
message(STATUS " Found unarr via CMake config")
target_link_libraries(cbx_backend PRIVATE unarr::unarr)
else()
pkg_check_modules(UNARR QUIET IMPORTED_TARGET libunarr)
if(UNARR_FOUND)
message(STATUS " Found unarr via pkg-config")
target_link_libraries(cbx_backend PRIVATE PkgConfig::UNARR)
elseif(APPLE AND EXISTS "${CMAKE_SOURCE_DIR}/dependencies/unarr/macx/libunarr.a")
message(STATUS " Found prebuilt unarr in dependencies (macOS)")
target_include_directories(cbx_backend PRIVATE
"${CMAKE_SOURCE_DIR}/dependencies/unarr/macx")
target_link_directories(cbx_backend PRIVATE
"${CMAKE_SOURCE_DIR}/dependencies/unarr/macx")
target_link_libraries(cbx_backend PRIVATE unarr z bz2)
elseif(WIN32 AND EXISTS "${CMAKE_SOURCE_DIR}/dependencies/unarr/win/unarr.h")
message(STATUS " Found prebuilt unarr in dependencies (Windows)")
target_include_directories(cbx_backend PRIVATE
"${CMAKE_SOURCE_DIR}/dependencies/unarr/win")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
target_link_directories(cbx_backend PRIVATE
"${CMAKE_SOURCE_DIR}/dependencies/unarr/win/arm64")
else()
target_link_directories(cbx_backend PRIVATE
"${CMAKE_SOURCE_DIR}/dependencies/unarr/win/x64")
endif()
target_link_libraries(cbx_backend PRIVATE unarr)
target_compile_definitions(cbx_backend PRIVATE UNARR_IS_SHARED_LIBRARY)
elseif(EXISTS "/usr/include/unarr.h")
message(STATUS " Found system unarr at /usr/include")
target_link_libraries(cbx_backend PRIVATE unarr)
else()
message(FATAL_ERROR
"Could not find unarr. Install libunarr or use a different DECOMPRESSION_BACKEND.")
endif()
endif()
elseif(DECOMPRESSION_BACKEND STREQUAL "7zip")
message(STATUS "Decompression backend: 7zip (in-tree)")
# Auto-download 7zip source if not present
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib7zip/CPP")
include(FetchContent)
FetchContent_Declare(
lib7zip
URL "https://github.com/YACReader/yacreader-7z-deps/raw/main/7z2301-src.7z"
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/lib7zip"
DOWNLOAD_EXTRACT_TIMESTAMP ON
)
message(STATUS " Downloading 7zip source from yacreader-7z-deps...")
FetchContent_MakeAvailable(lib7zip)
endif()
target_sources(cbx_backend PRIVATE
compressed_archive.cpp
compressed_archive.h
extract_delegate.h
7z_includes.h
open_callbacks.h
extract_callbacks.h
lib7zip/CPP/Windows/FileIO.cpp
lib7zip/CPP/Windows/PropVariant.cpp
lib7zip/CPP/Windows/PropVariantConv.cpp
lib7zip/CPP/Common/IntToString.cpp
lib7zip/CPP/Common/MyString.cpp
lib7zip/CPP/Common/MyVector.cpp
lib7zip/CPP/Common/Wildcard.cpp
lib7zip/CPP/7zip/Common/FileStreams.cpp
lib7zip/C/Alloc.c
lib7zip/CPP/7zip/Common/StreamObjects.cpp
)
if(UNIX)
target_sources(cbx_backend PRIVATE
lib7zip/CPP/Common/NewHandler.cpp
lib7zip/CPP/Windows/DLL.cpp
lib7zip/CPP/Windows/FileDir.cpp
lib7zip/CPP/Windows/FileFind.cpp
lib7zip/CPP/Windows/FileName.cpp
lib7zip/CPP/Windows/TimeUtils.cpp
lib7zip/CPP/Common/UTFConvert.cpp
lib7zip/CPP/Common/MyWindows.cpp
lib7zip/CPP/Common/StringConvert.cpp
)
endif()
target_include_directories(cbx_backend
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
PRIVATE lib7zip/CPP
)
if(APPLE)
target_compile_definitions(cbx_backend PRIVATE
_FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE NDEBUG _REENTRANT
ENV_UNIX _7ZIP_LARGE_PAGES ENV_MACOSX _TCHAR_DEFINED
UNICODE _UNICODE UNIX_USE_WIN_FILE)
target_link_libraries(cbx_backend PRIVATE
"-framework IOKit" "-framework CoreFoundation")
elseif(UNIX)
target_compile_definitions(cbx_backend PRIVATE
_FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE NDEBUG _REENTRANT
ENV_UNIX _7ZIP_LARGE_PAGES UNICODE _UNICODE UNIX_USE_WIN_FILE)
endif()
elseif(DECOMPRESSION_BACKEND STREQUAL "libarchive")
message(STATUS "Decompression backend: libarchive")
if(WIN32 OR APPLE)
message(FATAL_ERROR "libarchive backend is not supported on Windows or macOS")
endif()
target_sources(cbx_backend PRIVATE
libarchive/compressed_archive.cpp
libarchive/compressed_archive.h
libarchive/extract_delegate.h
)
target_include_directories(cbx_backend PUBLIC libarchive)
target_compile_definitions(cbx_backend PUBLIC use_libarchive)
# Try pkg-config first, then system path
pkg_check_modules(LIBARCHIVE QUIET IMPORTED_TARGET libarchive)
if(LIBARCHIVE_FOUND)
message(STATUS " Found libarchive via pkg-config")
target_link_libraries(cbx_backend PRIVATE PkgConfig::LIBARCHIVE)
elseif(EXISTS "/usr/include/archive.h")
message(STATUS " Found system libarchive at /usr/include")
target_link_libraries(cbx_backend PRIVATE archive)
else()
message(FATAL_ERROR
"Could not find libarchive. Install it or use a different DECOMPRESSION_BACKEND.")
endif()
else()
message(FATAL_ERROR
"Unknown DECOMPRESSION_BACKEND: '${DECOMPRESSION_BACKEND}'. "
"Use: unarr, 7zip, or libarchive")
endif()
# Qt, yr_global, and QsLog are needed by all backends
target_link_libraries(cbx_backend PRIVATE Qt::Core yr_global QsLog)

View File

@ -7,9 +7,9 @@ This backend is currently only supported on the Linux platform.
## Using
Enabling this backend is achieved by adding the `libarchive` qmake configuration value:
Enable this backend by setting the `DECOMPRESSION_BACKEND` CMake option:
qmake CONFIG+=libarchive
cmake -B build -DDECOMPRESSION_BACKEND=libarchive
Upon success, the application can be built as normal.

View File

@ -1,31 +0,0 @@
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += $$PWD/extract_delegate.h \
$$PWD/compressed_archive.h
SOURCES += $$PWD/compressed_archive.cpp
if(mingw|unix):!macx:!contains(QT_CONFIG, no-pkg-config):packagesExist(libarchive) {
message(Using system provided libarchive installation found by pkg-config.)
!system(pkg-config --atleast-version=3.6.0 libarchive) {
LIBARCHIVE_WARNING = "libarchive < 3.6.0 found. Older versions of libarchive DO NOT SUPPORT RARv4 files. This is probably not what you want"
warning($$LIBARCHIVE_WARNING)
message($$LIBARCHIVE_WARNING)
}
CONFIG += link_pkgconfig
PKGCONFIG += libarchive
DEFINES += use_libarchive
}
else:unix:!macx:exists(/usr/include/archive.h) {
message(Using system provided libarchive installation.)
LIBS += -larchive
DEFINES += use_libarchive
}
else:if(win32|macx) {
error(Unsupported: the libarchive decompression backend is not currently supported on this system.)
}
else {
error(Missing dependency: libarchive decompression backend. Please install libarchive on your system)
}

View File

@ -1,52 +0,0 @@
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
HEADERS += $$PWD/extract_delegate.h \
$$PWD/compressed_archive.h
SOURCES += $$PWD/compressed_archive.cpp
if(mingw|unix):!macx:!contains(QT_CONFIG, no-pkg-config):packagesExist(libunarr) {
message(Using system provided unarr installation found by pkg-config.)
CONFIG += link_pkgconfig
PKGCONFIG += libunarr
DEFINES += use_unarr
}
else:unix:!macx:exists(/usr/include/unarr.h) {
message(Using system provided unarr installation.)
LIBS += -lunarr
DEFINES += use_unarr
}
else:macx:exists(../../dependencies/unarr/macx/libunarr.a) {
message(Found prebuilt unarr library in dependencies directory.)
INCLUDEPATH += $$PWD/../../dependencies/unarr/macx
LIBS += -L$$PWD/../../dependencies/unarr/macx -lunarr -lz -lbz2
DEFINES += use_unarr
}
else:win32:exists(../../dependencies/unarr/win/unarr.h) {
message(Found prebuilt unarr library in dependencies directory.)
INCLUDEPATH += $$PWD/../../dependencies/unarr/win
contains(QMAKE_TARGET.arch, x86_64): {
LIBS += -L$$PWD/../../dependencies/unarr/win/x64 -lunarr
} else {
LIBS += -L$$PWD/../../dependencies/unarr/win/x86 -lunarr
}
DEFINES += use_unarr UNARR_IS_SHARED_LIBRARY
}
else:exists ($$PWD/unarr-master) {
message(Found unarr source-code)
message(Unarr will be build as a part of YACReader)
# qmake based unarr build system
# this should only be used for testing or as a last resort
include(unarr.pro)
DEFINES += use_unarr
}
else {
error(Missing dependency: unarr decrompression backend. Please install libunarr on your system\
or provide a copy of the unarr source code in compressed_archive/unarr/unarr-master)
}

View File

@ -1,46 +0,0 @@
INCLUDEPATH += $$PWD/unarr-master/
DEPENDPATH += $$PWD/unarr-master/
unix:QMAKE_CFLAGS_RELEASE -= "-O2"
unix:QMAKE_CFLAGS_RELEASE += "-O3"
unix:QMAKE_CFLAGS_RELEASE += "-DNDEBUG"
unix:QMAKE_CFLAGS += "-D_FILE_OFFSET_BITS=64"
win32:QMAKE_CFLAGS_RELEASE += "/DNDEBUG"
HEADERS+=$$PWD/unarr-master/common/allocator.h\
$$PWD/unarr-master/common/unarr-imp.h\
$$PWD/unarr-master/lzmasdk/7zTypes.h\
$$PWD/unarr-master/lzmasdk/CpuArch.h\
$$PWD/unarr-master/lzmasdk/Ppmd7.h\
$$PWD/unarr-master/lzmasdk/Ppmd.h\
$$PWD/unarr-master/lzmasdk/LzmaDec.h\
$$PWD/unarr-master/lzmasdk/Ppmd8.h\
$$PWD/unarr-master/tar/tar.h\
$$PWD/unarr-master/_7z/_7z.h\
$$PWD/unarr-master/unarr.h
SOURCES+=$$PWD/unarr-master/common/conv.c\
$$PWD/unarr-master/common/custalloc.c\
$$PWD/unarr-master/common/unarr.c\
$$PWD/unarr-master/common/crc32.c\
$$PWD/unarr-master/common/stream.c\
$$PWD/unarr-master/lzmasdk/CpuArch.c\
$$PWD/unarr-master/lzmasdk/Ppmd7.c\
$$PWD/unarr-master/lzmasdk/Ppmd8.c\
$$PWD/unarr-master/lzmasdk/LzmaDec.c\
$$PWD/unarr-master/lzmasdk/Ppmd7Dec.c\
$$PWD/unarr-master/lzmasdk/Ppmd8Dec.c\
$$PWD/unarr-master/zip/inflate.c\
$$PWD/unarr-master/zip/parse-zip.c\
$$PWD/unarr-master/zip/uncompress-zip.c\
$$PWD/unarr-master/zip/zip.c\
$$PWD/unarr-master/rar/filter-rar.c\
$$PWD/unarr-master/rar/parse-rar.c\
$$PWD/unarr-master/rar/rarvm.c\
$$PWD/unarr-master/rar/huffman-rar.c\
$$PWD/unarr-master/rar/rar.c\
$$PWD/unarr-master/rar/uncompress-rar.c\
$$PWD/unarr-master/tar/parse-tar.c\
$$PWD/unarr-master/tar/tar.c\
$$PWD/unarr-master/_7z/_7z.c

View File

@ -1,62 +0,0 @@
INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD
exists (../compressed_archive/lib7zip) {
message(Using 7zip)
} else {
error(You\'ll need 7zip source code to compile YACReader. \
Please check the compressed_archive folder for further instructions.)
}
INCLUDEPATH += \
$$PWD/lib7zip/CPP \
SOURCES += \
$$PWD/compressed_archive.cpp \
$$PWD/lib7zip/CPP/Windows/FileIO.cpp \
$$PWD/lib7zip/CPP/Windows/PropVariant.cpp \
$$PWD/lib7zip/CPP/Windows/PropVariantConv.cpp \
$$PWD/lib7zip/CPP/Common/IntToString.cpp \
$$PWD/lib7zip/CPP/Common/MyString.cpp \
$$PWD/lib7zip/CPP/Common/MyVector.cpp \
$$PWD/lib7zip/CPP/Common/Wildcard.cpp \
$$PWD/lib7zip/CPP/7zip/Common/FileStreams.cpp \
$$PWD/lib7zip/C/Alloc.c \
$$PWD/lib7zip/CPP/7zip/Common/StreamObjects.cpp
unix{
SOURCES += \
$$PWD/lib7zip/CPP/Common/NewHandler.cpp \
$$PWD/lib7zip/CPP/Windows/DLL.cpp \
$$PWD/lib7zip/CPP/Windows/FileDir.cpp \
$$PWD/lib7zip/CPP/Windows/FileFind.cpp \
$$PWD/lib7zip/CPP/Windows/FileName.cpp \
$$PWD/lib7zip/CPP/Windows/TimeUtils.cpp \
$$PWD/lib7zip/CPP/Common/UTFConvert.cpp \
$$PWD/lib7zip/CPP/Common/MyWindows.cpp \
$$PWD/lib7zip/CPP/Common/StringConvert.cpp \
}
HEADERS += \
$$PWD/lib7zip/CPP/Common/Common.h \
$$PWD/compressed_archive.h \
$$PWD/extract_delegate.h \
$$PWD/7z_includes.h \
$$PWD/open_callbacks.h \
$$PWD/extract_callbacks.h \
macx{
LIBS += -framework IOKit -framework CoreFoundation
DEFINES += _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE \
NDEBUG _REENTRANT ENV_UNIX \
_7ZIP_LARGE_PAGES ENV_MACOSX _TCHAR_DEFINED \
UNICODE _UNICODE UNIX_USE_WIN_FILE
}
unix:!macx{
DEFINES += _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE \
NDEBUG _REENTRANT ENV_UNIX \
_7ZIP_LARGE_PAGES \
UNICODE _UNICODE UNIX_USE_WIN_FILE
}