diff --git a/.vscode/settings.json b/.vscode/settings.json index 3ff191a1..a9b95701 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,6 +19,7 @@ "inflate_zlib.h": "c", "unity.h": "c", "raiistring.h": "c", - "fileutils.h": "c" + "fileutils.h": "c", + "zip_minizip.h": "c" }, } \ No newline at end of file diff --git a/CoDeLib/CMakeLists.txt b/CoDeLib/CMakeLists.txt index 11ba318f..8149dfa7 100644 --- a/CoDeLib/CMakeLists.txt +++ b/CoDeLib/CMakeLists.txt @@ -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} diff --git a/CoDeLib/Config.cmake.in b/CoDeLib/Config.cmake.in index 5d530219..3adaf2f3 100644 --- a/CoDeLib/Config.cmake.in +++ b/CoDeLib/Config.cmake.in @@ -7,4 +7,6 @@ check_required_components(CoDeLib) include(CMakeFindDependencyMacro) set(ZLIB_USE_STATIC_LIBS "ON") -find_dependency(ZLIB REQUIRED) \ No newline at end of file +find_dependency(ZLIB REQUIRED) + +find_dependency(minizip REQUIRED) \ No newline at end of file diff --git a/CoDeLib/Deflate_zlib/CMakeLists.txt b/CoDeLib/Deflate_zlib/CMakeLists.txt index 1175f1a5..86654718 100644 --- a/CoDeLib/Deflate_zlib/CMakeLists.txt +++ b/CoDeLib/Deflate_zlib/CMakeLists.txt @@ -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 diff --git a/CoDeLib/Zip_minizip/CMakeLists.txt b/CoDeLib/Zip_minizip/CMakeLists.txt new file mode 100644 index 00000000..01a53c21 --- /dev/null +++ b/CoDeLib/Zip_minizip/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(Zip_minizip STATIC + src/Zip_minizip.c) + +target_include_directories(Zip_minizip PUBLIC + $ + $ +) + +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) diff --git a/CoDeLib/Zip_minizip/src/Zip_minizip.c b/CoDeLib/Zip_minizip/src/Zip_minizip.c new file mode 100644 index 00000000..36e83518 --- /dev/null +++ b/CoDeLib/Zip_minizip/src/Zip_minizip.c @@ -0,0 +1,18 @@ +#include + +#include // 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, +}; diff --git a/CoDeLib/include/CoDeLib/IZip.h b/CoDeLib/include/CoDeLib/IZip.h new file mode 100644 index 00000000..403e78ce --- /dev/null +++ b/CoDeLib/include/CoDeLib/IZip.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +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); +}; \ No newline at end of file diff --git a/CoDeLib/include/CoDeLib/Zip_minizip/Zip_minizip.h b/CoDeLib/include/CoDeLib/Zip_minizip/Zip_minizip.h new file mode 100644 index 00000000..bbd30a1d --- /dev/null +++ b/CoDeLib/include/CoDeLib/Zip_minizip/Zip_minizip.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +extern const struct IZip zip_minizip; \ No newline at end of file diff --git a/Scripts/BuildAndInstallCoDeLib.py b/Scripts/BuildAndInstallCoDeLib.py index ae581d86..25234997 100644 --- a/Scripts/BuildAndInstallCoDeLib.py +++ b/Scripts/BuildAndInstallCoDeLib.py @@ -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( @@ -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( diff --git a/Scripts/BuildAndInstallExternalLibs.py b/Scripts/BuildAndInstallExternalLibs.py index 2556f6ff..23eaa353 100644 --- a/Scripts/BuildAndInstallExternalLibs.py +++ b/Scripts/BuildAndInstallExternalLibs.py @@ -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) diff --git a/Scripts/BuildBenchmark.py b/Scripts/BuildBenchmark.py index fa6d04c7..965ba2dc 100644 --- a/Scripts/BuildBenchmark.py +++ b/Scripts/BuildBenchmark.py @@ -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( @@ -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, diff --git a/Scripts/CleanAll.py b/Scripts/CleanAll.py index ada4126e..7866e48d 100644 --- a/Scripts/CleanAll.py +++ b/Scripts/CleanAll.py @@ -16,6 +16,8 @@ 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, @@ -23,6 +25,8 @@ CoDeLibInstallPath, ExternalZlibLibBuildPath, ExternalZlibLibInstallPath, + ExternalMinizipNgLibBuildPath, + ExternalMinizipNgLibInstallPath, ]