Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ZLib 3rdparty library to use ZLib-ng and Minizip-ng so patching is not necessary #7022

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions 3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think You should set USE_SYSTEM_ZLIB to OFF if the package can't be found.

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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
63 changes: 0 additions & 63 deletions 3rdparty/zlib/0001-patch-zlib-to-enable-unzip.patch

This file was deleted.

18 changes: 18 additions & 0 deletions 3rdparty/zlib/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.
40 changes: 40 additions & 0 deletions 3rdparty/zlib/minizip.cmake
Original file line number Diff line number Diff line change
@@ -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=<INSTALL_DIR>
-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
<INSTALL_DIR>/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})
14 changes: 7 additions & 7 deletions 3rdparty/zlib/zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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=<INSTALL_DIR>
-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}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cpp/open3d/utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions cpp/open3d/utility/ExtractZIP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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,
Expand Down Expand Up @@ -97,14 +89,14 @@ static int ExtractCurrentFile(unzFile uf,
if (err == UNZ_OK) {
std::string file_path = extract_dir + "/" +
static_cast<std::string>(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) {
Expand Down Expand Up @@ -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.
Expand Down
Loading