diff --git a/3rdparty/find_dependencies.cmake b/3rdparty/find_dependencies.cmake index c3dc3885565..7cdde4b52c9 100644 --- a/3rdparty/find_dependencies.cmake +++ b/3rdparty/find_dependencies.cmake @@ -853,6 +853,25 @@ if (BUILD_LIBREALSENSE) endif() endif() +if(USE_SYSTEM_ZLIB) + open3d_find_package_3rdparty_library(3rdparty_zlib + PACKAGE ZLIB + TARGETS ZLIB::ZLIB + ) + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_zlib) +endif() +if(NOT USE_SYSTEM_ZLIB) + include(${Open3D_3RDPARTY_DIR}/zlib/zlib.cmake) + open3d_import_3rdparty_library(3rdparty_zlib + HIDDEN + INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS} + LIB_DIR ${ZLIB_LIB_DIR} + LIBRARIES ${ZLIB_LIBRARIES} + DEPENDS ext_zlib + ) + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_zlib) +endif() + # Curl # - Curl should be linked before PNG, otherwise it will have undefined symbols. # - openssl.cmake needs to be included before curl.cmake, for the @@ -925,15 +944,6 @@ if(USE_SYSTEM_PNG) endif() endif() if(NOT USE_SYSTEM_PNG) - include(${Open3D_3RDPARTY_DIR}/zlib/zlib.cmake) - open3d_import_3rdparty_library(3rdparty_zlib - HIDDEN - INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS} - LIB_DIR ${ZLIB_LIB_DIR} - LIBRARIES ${ZLIB_LIBRARIES} - DEPENDS ext_zlib - ) - include(${Open3D_3RDPARTY_DIR}/libpng/libpng.cmake) open3d_import_3rdparty_library(3rdparty_png INCLUDE_DIRS ${LIBPNG_INCLUDE_DIRS} @@ -1136,12 +1146,24 @@ open3d_import_3rdparty_library(3rdparty_poisson list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_poisson) # Minizip -if(WITH_MINIZIP) - open3d_pkg_config_3rdparty_library(3rdparty_minizip - SEARCH_ARGS minizip +if(USE_SYSTEM_MINIZIP) + open3d_find_package_3rdparty_library(3rdparty_zlib + PACKAGE minizip + TARGETS MINIZIP::minizip ) list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_SYSTEM Open3D::3rdparty_minizip) endif() +if(NOT USE_SYSTEM_MINIZIP) + include(${Open3D_3RDPARTY_DIR}/zlib/minizip.cmake) + open3d_import_3rdparty_library(3rdparty_minizip + HIDDEN + INCLUDE_DIRS ${MINIZIP_INCLUDE_DIRS} + LIB_DIR ${MINIZIP_LIB_DIR} + LIBRARIES ${MINIZIP_LIBRARIES} + DEPENDS ext_minizip + ) + list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS_FROM_CUSTOM Open3D::3rdparty_minizip) +endif() # Googletest if (BUILD_UNIT_TESTS) diff --git a/3rdparty/zlib/0001-patch-zlib-to-enable-unzip.patch b/3rdparty/zlib/0001-patch-zlib-to-enable-unzip.patch deleted file mode 100644 index caaf2152442..00000000000 --- a/3rdparty/zlib/0001-patch-zlib-to-enable-unzip.patch +++ /dev/null @@ -1,63 +0,0 @@ -From 896883f4dc22d26db653bb92739ca77c4f330389 Mon Sep 17 00:00:00 2001 -From: reyanshsolis -Date: Sat, 25 Dec 2021 00:10:42 +0530 -Subject: [PATCH] patch zlib to enable unzip - ---- - CMakeLists.txt | 4 ++++ - contrib/minizip/ioapi.c | 3 +-- - contrib/minizip/unzip.c | 2 +- - 3 files changed, 6 insertions(+), 3 deletions(-) - -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 0fe939d..20f25bb 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -93,6 +93,8 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) - set(ZLIB_PUBLIC_HDRS - ${CMAKE_CURRENT_BINARY_DIR}/zconf.h - zlib.h -+ contrib/minizip/unzip.h -+ contrib/minizip/ioapi.h - ) - set(ZLIB_PRIVATE_HDRS - crc32.h -@@ -121,6 +123,8 @@ set(ZLIB_SRCS - trees.c - uncompr.c - zutil.c -+ contrib/minizip/unzip.c -+ contrib/minizip/ioapi.c - ) - - if(NOT MINGW) -diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c -index 7f5c191..c2b536f 100644 ---- a/contrib/minizip/ioapi.c -+++ b/contrib/minizip/ioapi.c -@@ -221,8 +221,7 @@ static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) - return ret; - } - --void fill_fopen_filefunc (pzlib_filefunc_def) -- zlib_filefunc_def* pzlib_filefunc_def; -+void fill_fopen_filefunc (zlib_filefunc_def* pzlib_filefunc_def) - { - pzlib_filefunc_def->zopen_file = fopen_file_func; - pzlib_filefunc_def->zread_file = fread_file_func; -diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c -index bcfb941..9319186 100644 ---- a/contrib/minizip/unzip.c -+++ b/contrib/minizip/unzip.c -@@ -69,7 +69,7 @@ - #include - - #ifndef NOUNCRYPT -- #define NOUNCRYPT -+ // #define NOUNCRYPT - #endif - - #include "zlib.h" --- -2.25.1 - diff --git a/3rdparty/zlib/LICENSE b/3rdparty/zlib/LICENSE index e7b8045b7f4..626bba38e27 100644 --- a/3rdparty/zlib/LICENSE +++ b/3rdparty/zlib/LICENSE @@ -37,3 +37,21 @@ Gailly and Mark Adler; it does not include third-party code. If you redistribute modified sources, we would appreciate that you include in the file ChangeLog history information documenting your changes. Please read the FAQ for more information on the distribution of modified source versions. + +Condition of use and distribution are the same as zlib: + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgement in the product documentation would be + appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. diff --git a/3rdparty/zlib/minizip.cmake b/3rdparty/zlib/minizip.cmake new file mode 100644 index 00000000000..a87c51d6573 --- /dev/null +++ b/3rdparty/zlib/minizip.cmake @@ -0,0 +1,40 @@ +include(ExternalProject) + +find_package(Git QUIET REQUIRED) + +ExternalProject_Get_Property(ext_zlib INSTALL_DIR) +set(ZLIB_INSTALL_DIR ${INSTALL_DIR}) +unset(INSTALL_DIR) + +set(lib_name minizip) + +ExternalProject_Add(ext_minizip + PREFIX minizip-ng + URL https://github.com/zlib-ng/minizip-ng/archive/refs/tags/4.0.7.tar.gz + URL_HASH SHA256=a87f1f734f97095fe1ef0018217c149d53d0f78438bcb77af38adc21dff2dfbc + DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/minizip-ng" + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX= + -DMZ_COMPAT:BOOL=ON + -DMZ_ZLIB:BOOL=ON + -DMZ_BZIP2:BOOL=OFF + -DMZ_LZMA:BOOL=OFF + -DMZ_ZSTD:BOOL=OFF + -DMZ_LIBCOMP:BOOL=OFF + -DMZ_FETCH_LIBS:BOOL=OFF + -DMZ_FORCE_FETCH_LIBS:BOOL=OFF + -DMZ_PKCRYPT:BOOL=OFF + -DMZ_WZAES:BOOL=OFF + -DMZ_OPENSSL:BOOL=OFF + -DMZ_LIBBSD:BOOL=OFF + -DMZ_ICONV:BOOL=OFF + -DZLIB_ROOT:PATH=${ZLIB_INSTALL_DIR} + ${ExternalProject_CMAKE_ARGS} + BUILD_BYPRODUCTS + /lib/${CMAKE_STATIC_LIBRARY_PREFIX}${lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX} +) + +ExternalProject_Get_Property(ext_minizip INSTALL_DIR) +set(MINIZIP_INCLUDE_DIRS ${INSTALL_DIR}/include/minizip/) # "/" is critical. +set(MINIZIP_LIB_DIR ${INSTALL_DIR}/lib) +set(MINIZIP_LIBRARIES ${lib_name}) diff --git a/3rdparty/zlib/zlib.cmake b/3rdparty/zlib/zlib.cmake index f0d756b5e75..b05dbe7534c 100644 --- a/3rdparty/zlib/zlib.cmake +++ b/3rdparty/zlib/zlib.cmake @@ -10,16 +10,16 @@ find_package(Git QUIET REQUIRED) ExternalProject_Add( ext_zlib - PREFIX zlib - URL https://github.com/madler/zlib/archive/refs/tags/v1.2.13.tar.gz - URL_HASH SHA256=1525952a0a567581792613a9723333d7f8cc20b87a81f920fb8bc7e3f2251428 + PREFIX zlib-ng + URL https://github.com/zlib-ng/zlib-ng/archive/refs/tags/2.2.2.tar.gz + URL_HASH SHA256=fcb41dd59a3f17002aeb1bb21f04696c9b721404890bb945c5ab39d2cb69654c DOWNLOAD_DIR "${OPEN3D_THIRD_PARTY_DOWNLOAD_DIR}/zlib" - UPDATE_COMMAND "" - PATCH_COMMAND ${GIT_EXECUTABLE} init - COMMAND ${GIT_EXECUTABLE} apply --ignore-space-change --ignore-whitespace - ${CMAKE_CURRENT_LIST_DIR}/0001-patch-zlib-to-enable-unzip.patch CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= + -DZLIB_COMPAT:BOOL=ON + -DZLIB_ENABLE_TESTS:BOOL=OFF + -DZLIBNG_ENABLE_TESTS:BOOL=OFF + -DWITH_GTEST:BOOL=OFF # zlib needs visiible symbols for examples. Disabling example building causes # assember error in GPU CI. zlib symbols are hidden during linking. ${ExternalProject_CMAKE_ARGS} diff --git a/CHANGELOG.md b/CHANGELOG.md index c52a549add6..f18c9a2a370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ - Fix tensor EstimatePointWiseNormalsWithFastEigen3x3 (PR #6980) - Fix alpha shape reconstruction if alpha too small for point scale (PR #6998) - Fix render to depth image on Apple Retina displays (PR #7001) +- Update the ZLib provider to not use a patched version, instead it uses the new separate minizip provider. The WITH_MINIZIP option is now USE_SYSTEM_MINIZIP. (PR #7022) ## 0.13 diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b047cd0b82..7c4fe414e59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,6 +97,7 @@ option(USE_SYSTEM_IMGUI "Use system pre-installed imgui" OFF option(USE_SYSTEM_JPEG "Use system pre-installed jpeg" OFF) option(USE_SYSTEM_JSONCPP "Use system pre-installed jsoncpp" OFF) option(USE_SYSTEM_LIBLZF "Use system pre-installed liblzf" OFF) +option(USE_SYSTEM_MINIZIP "Use system pre-installed minizip" OFF) option(USE_SYSTEM_MSGPACK "Use system pre-installed msgpack" OFF) option(USE_SYSTEM_NANOFLANN "Use system pre-installed nanoflann" OFF) option(USE_SYSTEM_OPENSSL "Use system pre-installed OpenSSL" OFF) @@ -109,6 +110,7 @@ option(USE_SYSTEM_TINYGLTF "Use system pre-installed tinygltf" OFF option(USE_SYSTEM_TINYOBJLOADER "Use system pre-installed tinyobjloader" OFF) option(USE_SYSTEM_VTK "Use system pre-installed VTK" OFF) option(USE_SYSTEM_ZEROMQ "Use system pre-installed ZeroMQ" OFF) +option(USE_SYSTEM_ZLIB "Use system pre-installed ZLib" OFF) if(LINUX_AARCH64 OR APPLE_AARCH64) option(BUILD_VTK_FROM_SOURCE "Build VTK from source" ON ) else() @@ -121,7 +123,6 @@ else() endif() option(PREFER_OSX_HOMEBREW "Prefer Homebrew libs over frameworks" ON ) -option(WITH_MINIZIP "Enable MiniZIP" OFF) # Sensor options option(BUILD_LIBREALSENSE "Build support for Intel RealSense camera" OFF) diff --git a/cpp/open3d/utility/CMakeLists.txt b/cpp/open3d/utility/CMakeLists.txt index d7211a0cefc..7ccb5ca05c6 100644 --- a/cpp/open3d/utility/CMakeLists.txt +++ b/cpp/open3d/utility/CMakeLists.txt @@ -19,6 +19,11 @@ target_sources(utility PRIVATE Timer.cpp ) +target_compile_definitions(utility PRIVATE + _FILE_OFFSET_BITS=64 + _LARGEFILE_SOURCE=1 +) + if (BUILD_ISPC_MODULE) target_sources(utility PRIVATE ISAInfo.ispc diff --git a/cpp/open3d/utility/ExtractZIP.cpp b/cpp/open3d/utility/ExtractZIP.cpp index eba295992c2..b54303ffe2c 100644 --- a/cpp/open3d/utility/ExtractZIP.cpp +++ b/cpp/open3d/utility/ExtractZIP.cpp @@ -20,14 +20,6 @@ #include "open3d/utility/FileSystem.h" #include "open3d/utility/Logging.h" -#ifdef __APPLE__ -// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no -// need for specific 64 bit functions -#define FOPEN_FUNC(filename, mode) fopen(filename, mode) -#else -#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) -#endif - // If required in future, the `WRITEBUFFERSIZE` size can be increased to 16384. #define WRITEBUFFERSIZE (8192) @@ -43,7 +35,7 @@ static int ExtractCurrentFile(unzFile uf, int err = UNZ_OK; FILE *fout = nullptr; void *buf; - uInt size_buf; + std::uint32_t size_buf; unz_file_info64 file_info; err = unzGetCurrentFileInfo64(uf, &file_info, filename_inzip, @@ -97,14 +89,14 @@ static int ExtractCurrentFile(unzFile uf, if (err == UNZ_OK) { std::string file_path = extract_dir + "/" + static_cast(write_filename); - fout = FOPEN_FUNC(file_path.c_str(), "wb"); + fout = fopen(file_path.c_str(), "wb"); // Some zipfile don't contain directory alone before file. if ((fout == nullptr) && filename_withoutpath == (char *)filename_inzip) { utility::filesystem::MakeDirectoryHierarchy(extract_dir); - fout = FOPEN_FUNC(file_path.c_str(), "wb"); + fout = fopen(file_path.c_str(), "wb"); } if (fout == nullptr) { @@ -179,7 +171,7 @@ void ExtractFromZIP(const std::string &file_path, // ExtractFromZIP supports password. Can be exposed if required in future. const std::string password = ""; - for (uLong i = 0; i < gi.number_entry; ++i) { + for (std::uint64_t i = 0; i < gi.number_entry; ++i) { err = ExtractCurrentFile(uf, extract_dir, password); if (err != UNZ_OK) { // Close file, before throwing exception.