Skip to content

Commit

Permalink
dev: Create Zip_minizip
Browse files Browse the repository at this point in the history
  • Loading branch information
enzoevers committed Nov 29, 2024
1 parent 878fc90 commit 8b5e034
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"inflate_zlib.h": "c",
"unity.h": "c",
"raiistring.h": "c",
"fileutils.h": "c"
"fileutils.h": "c",
"zip_minizip.h": "c"
},
}
4 changes: 3 additions & 1 deletion CoDeLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ set(CoDeLib_PUBLIC_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/include/CoDeLib)
set(COMMON_HEADERS
${CoDeLib_PUBLIC_INCLUDE_PATH}/IDeflate.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IInflate.h
${CoDeLib_PUBLIC_INCLUDE_PATH}/IZip.h
)
install(FILES ${COMMON_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CoDeLib)

add_subdirectory(Deflate_zlib)
add_subdirectory(Inflate_zlib)
add_subdirectory(Zip_minizip)
add_subdirectory(RaiiString)
add_subdirectory(Test)

install(
TARGETS CoDeLib Deflate_zlib Inflate_zlib RaiiString Utility
TARGETS CoDeLib Deflate_zlib Inflate_zlib Zip_minizip RaiiString Utility
EXPORT CoDeLibTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
Expand Down
4 changes: 3 additions & 1 deletion CoDeLib/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ check_required_components(CoDeLib)
include(CMakeFindDependencyMacro)

set(ZLIB_USE_STATIC_LIBS "ON")
find_dependency(ZLIB REQUIRED)
find_dependency(ZLIB REQUIRED)

find_dependency(minizip REQUIRED)
1 change: 0 additions & 1 deletion CoDeLib/Deflate_zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ set(ZLIB_USE_STATIC_LIBS "ON")
find_package(ZLIB REQUIRED)
target_link_libraries(Deflate_zlib PRIVATE ZLIB::ZLIB)

message(STATUS "CoDeLib_PUBLIC_INCLUDE_PATH: ${CoDeLib_PUBLIC_INCLUDE_PATH}")
set(Deflate_zlib_PUBLIC_INCLUDE_PATH ${CoDeLib_PUBLIC_INCLUDE_PATH}/Deflate_zlib)
set(Deflate_zlib_PUBLIC_HEADERS
${Deflate_zlib_PUBLIC_INCLUDE_PATH}/Deflate_zlib.h
Expand Down
16 changes: 16 additions & 0 deletions CoDeLib/Zip_minizip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
add_library(Zip_minizip STATIC
src/Zip_minizip.c)

target_include_directories(Zip_minizip PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

find_package(MINIZIP REQUIRED)
target_link_libraries(Zip_minizip PRIVATE MINIZIP::minizip)

set(Zip_minizip_PUBLIC_INCLUDE_PATH ${CoDeLib_PUBLIC_INCLUDE_PATH}/Zip_minizip)
set(Zip_minizip_PUBLIC_HEADERS
${Zip_minizip_PUBLIC_INCLUDE_PATH}/Zip_minizip.h
)
install(FILES ${Zip_minizip_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/CoDeLib/Zip_minizip)
18 changes: 18 additions & 0 deletions CoDeLib/Zip_minizip/src/Zip_minizip.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <CoDeLib/Zip_minizip/Zip_minizip.h>

#include <zip.h> // minizip

ZIP_RETURN_CODES Zip(FILE *inputs[] __attribute__((unused)),
FILE *output __attribute__((unused)),
void *options __attribute__((unused))) {

// TODO: Dummy code to test if it compiles and links
if (ZIP_OK) {
return ZIP_SUCCESS;
}
return ZIP_ERROR;
}

const struct IZip zip_minizip = {
.Zip = Zip,
};
19 changes: 19 additions & 0 deletions CoDeLib/include/CoDeLib/IZip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <stdio.h>

typedef enum { ZIP_SUCCESS, ZIP_ERROR } ZIP_RETURN_CODES;

struct IZip {
/*!
* @brief Zips the input file(s) and write the output to the output file.
*
* @param inputs The input files.
* @param output The output file.
* @param options The options for the zipping.
*
* @return ZIP_SUCCESS if the zipping was successful, ZIP_ERROR
* otherwise.
*/
ZIP_RETURN_CODES (*Zip)(FILE *inputs[], FILE *output, void *options);
};
5 changes: 5 additions & 0 deletions CoDeLib/include/CoDeLib/Zip_minizip/Zip_minizip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <CoDeLib/IZip.h>

extern const struct IZip zip_minizip;
8 changes: 6 additions & 2 deletions Scripts/BuildAndInstallCoDeLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def BuildAndInstallCoDeLib(
ExternalZlibLibInstallPath = Path(
ExternalLibPath / "zlib/Install" / targetPlatformString / BuildTypeString
)
ExternalMinizipNgLibInstallPath = Path(
ExternalLibPath / "minizip-ng/Install" / targetPlatformString / BuildTypeString
)

CoDeLibRootPath = Path(RepositoryRootPath / ProjectName)
BuildDirectory = Path(
Expand All @@ -70,14 +73,15 @@ def BuildAndInstallCoDeLib(
print("==============================")
print(ProjectName + ": Configuring ({})".format(BuildTypeString))
print("==============================")
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S "{2}" -B "{3}" -DCMAKE_INSTALL_PREFIX="{4}" -DZLIB_ROOT="{5}" -DCMAKE_BUILD_TYPE={6}'.format(
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S "{2}" -B "{3}" -DCMAKE_INSTALL_PREFIX="{4}" -DCMAKE_BUILD_TYPE={5} -DZLIB_ROOT="{6}" -DCMAKE_PREFIX_PATH="{7}"'.format(
buildEnv.GetCmakeGenerator(),
buildEnv.GetCustomToolChainPath(),
CoDeLibRootPath,
BuildDirectory,
InstallDirectory,
ExternalZlibLibInstallPath,
BuildTypeString,
ExternalZlibLibInstallPath,
ExternalMinizipNgLibInstallPath,
)
print(configureCommand)
subprocess.run(
Expand Down
84 changes: 84 additions & 0 deletions Scripts/BuildAndInstallExternalLibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,92 @@ def BuildAndInstallZlib(
)


##############################
# minizip-ng
##############################
def BuildAndInstallMinizipNg(
buildEnv: EnvironmentConfig.EnvironmentConfiguration,
buildConfig: EnvironmentConfig.BuildConfig = EnvironmentConfig.BuildConfig.DEBUG,
):
ProjectName = "minizip-ng"

BuildTypeString = EnvironmentConfig.BuildConfig.ToCMakeBuildType(buildConfig)
targetPlatformString = EnvironmentConfig.Platform.PlatformToOsName(
buildEnv.GetTargetPlatform()
)

TopLevelCMakeListsDirectory = Path(ExternalLibPath / ProjectName)
BuildDirectory = Path(
ExternalLibPath / ProjectName / "Build" / targetPlatformString / BuildTypeString
)
InstallDirectory = Path(
ExternalLibPath
/ ProjectName
/ "Install"
/ targetPlatformString
/ BuildTypeString
)

if not BuildDirectory.exists():
BuildDirectory.mkdir(parents=True)

if InstallDirectory.exists():
shutil.rmtree(InstallDirectory)
InstallDirectory.mkdir(parents=True)

os.chdir(RepositoryRootPath)

# All options for minizip-ng that are not needed are turned off (all off them) except for MZ_COMPAT
# In this project minizing-ng is used only for zip file creation and extraction
print("==============================")
print(ProjectName + ": Configuring ({})".format(BuildTypeString))
print("==============================")
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S {2} -B {3} -DCMAKE_INSTALL_PREFIX="{4}" -DCMAKE_BUILD_TYPE={5} -DBUILD_SHARED_LIBS=OFF -DMZ_COMPAT=ON -DMZ_ZLIB=OFF -DMZ_BZIP2=OFF -DMZ_LZMA=OFF -DMZ_ZSTD=OFF -DMZ_LIBCOMP=OFF -DMZ_FETCH_LIBS=OFF -DMZ_PKCRYPT=OFF -DMZ_WZAES=OFF -DMZ_OPENSSL=OFF -DMZ_LIBBSD=OFF -DMZ_ICONV=OFF'.format(
buildEnv.GetCmakeGenerator(),
buildEnv.GetCustomToolChainPath(),
TopLevelCMakeListsDirectory,
BuildDirectory,
InstallDirectory,
BuildTypeString,
)
print(configureCommand)
subprocess.run(
configureCommand,
shell=True,
check=True,
)

print("==============================")
print(ProjectName + ": Building ({})".format(BuildTypeString))
print("==============================")
buildCommand = "cmake --build {0}".format(BuildDirectory)
print(buildCommand)
subprocess.run(
buildCommand,
shell=True,
check=True,
)

print("==============================")
print(ProjectName + ": Installing ({})".format(BuildTypeString))
print("==============================")
installCommand = "cmake --install {0}".format(BuildDirectory)
print(installCommand)
subprocess.run(
installCommand,
shell=True,
check=True,
)


BuildEnv = EnvironmentConfig.EnvironmentConfiguration(
RepositoryRootPath, targetPlatform
)

# zlib
BuildAndInstallZlib(BuildEnv, EnvironmentConfig.BuildConfig.DEBUG)
BuildAndInstallZlib(BuildEnv, EnvironmentConfig.BuildConfig.RELEASE)

# minizip-ng
BuildAndInstallMinizipNg(BuildEnv, EnvironmentConfig.BuildConfig.DEBUG)
BuildAndInstallMinizipNg(BuildEnv, EnvironmentConfig.BuildConfig.RELEASE)
10 changes: 7 additions & 3 deletions Scripts/BuildBenchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def BuildBenchmark(
ExternalZlibLibInstallPath = Path(
ExternalLibPath / "zlib/Install" / targetPlatformString / BuildTypeString
)
ExternalMinizipNgLibInstallPath = Path(
ExternalLibPath / "minizip-ng/Install" / targetPlatformString / BuildTypeString
)

BenchmarkRootPath = Path(RepositoryRootPath / ProjectName)
BuildDirectory = Path(
Expand All @@ -69,14 +72,15 @@ def BuildBenchmark(
print("==============================")
print(ProjectName + ": Configuring ({})".format(BuildTypeString))
print("==============================")
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -DCMAKE_PREFIX_PATH="{2}" -S {3} -B {4} -DZLIB_ROOT="{5}" -DCMAKE_BUILD_TYPE={6}'.format(
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S {2} -B {3} -DCMAKE_BUILD_TYPE={4} -DZLIB_ROOT="{5}" -DCMAKE_PREFIX_PATH="{6};{7}"'.format(
buildEnv.GetCmakeGenerator(),
buildEnv.GetCustomToolChainPath(),
CoDeLibInstallDirectory,
BenchmarkRootPath,
BuildDirectory,
ExternalZlibLibInstallPath,
BuildTypeString,
ExternalZlibLibInstallPath,
CoDeLibInstallDirectory,
ExternalMinizipNgLibInstallPath,
)
subprocess.run(
configureCommand,
Expand Down
4 changes: 4 additions & 0 deletions Scripts/CleanAll.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
ExternalLibPath = Path(ProjectRootPath / "External")
ExternalZlibLibBuildPath = Path(ExternalLibPath / "zlib/Build")
ExternalZlibLibInstallPath = Path(ExternalLibPath / "zlib/Install")
ExternalMinizipNgLibBuildPath = Path(ExternalLibPath / "minizip-ng/Build")
ExternalMinizipNgLibInstallPath = Path(ExternalLibPath / "minizip-ng/Install")

DirectoriesToRemove = [
BenchmarkBuildPath,
CoDeLibBuildPath,
CoDeLibInstallPath,
ExternalZlibLibBuildPath,
ExternalZlibLibInstallPath,
ExternalMinizipNgLibBuildPath,
ExternalMinizipNgLibInstallPath,
]


Expand Down

0 comments on commit 8b5e034

Please sign in to comment.