From 139e36f0fc7c2e60e4d1fe6f9d4c554ca8cb63ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= <105517825+cedrik-fuoco-adsk@users.noreply.github.com> Date: Mon, 5 Dec 2022 17:33:12 -0500 Subject: [PATCH] Adsk contrib - Fix issue with minizip build (#1725) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * - Refactoring how OCIO search for minizip-ng. The first step is to search for an external minizip-ng. If not found, search for minizip-ng with MZ_COMPAT=ON (libminizip). If it is not found either, download and install minizip-ng with MZ_COMPAT=OFF. - Removing the minizip-ng part for the includes for minizip-ng headers. Signed-off-by: Cédrik Fuoco * Update comments Signed-off-by: Cédrik Fuoco * Improved find_package in Config mode (adding it back) Added missing scripts to install minizip-ng and zlib for the analysis workflow Signed-off-by: Cédrik Fuoco * Adding +x permissions for install_minizip_ng and zlib Fixing path to find zlib in install_minizip-ng.sh Signed-off-by: Cédrik Fuoco * Changing target name to match the one used by minizip-ng library (+ using the imported target instead of creating a new one when minizip-ng is found) Signed-off-by: Cédrik Fuoco Signed-off-by: Cédrik Fuoco Co-authored-by: Doug Walker (cherry picked from commit 811902b37d844b91ad6fb0535f3cb7ef2e8c65e8) --- .github/workflows/analysis_workflow.yml | 9 + share/ci/scripts/multi/install_minizip-ng.sh | 57 ++++ share/ci/scripts/multi/install_zlib.sh | 40 +++ share/cmake/modules/Findminizip-ng.cmake | 289 ++++++++++++------- share/cmake/modules/Findminizip.cmake | 172 +++++++++++ src/OpenColorIO/CMakeLists.txt | 2 +- src/OpenColorIO/OCIOZArchive.cpp | 20 +- src/apps/ocioarchive/CMakeLists.txt | 2 +- src/apps/ocioarchive/main.cpp | 10 +- tests/cpu/CMakeLists.txt | 2 +- 10 files changed, 479 insertions(+), 124 deletions(-) create mode 100755 share/ci/scripts/multi/install_minizip-ng.sh create mode 100755 share/ci/scripts/multi/install_zlib.sh create mode 100644 share/cmake/modules/Findminizip.cmake diff --git a/.github/workflows/analysis_workflow.yml b/.github/workflows/analysis_workflow.yml index fb5d8313b7..3b7443da57 100644 --- a/.github/workflows/analysis_workflow.yml +++ b/.github/workflows/analysis_workflow.yml @@ -104,12 +104,15 @@ jobs: run: | share/ci/scripts/multi/install_pugixml.sh latest - name: Install fixed ext package versions + # Minizip-ng depends on ZLIB. ZLIB must be installed first. run: | share/ci/scripts/multi/install_expat.sh 2.4.1 $EXT_PATH share/ci/scripts/multi/install_lcms2.sh 2.2 $EXT_PATH share/ci/scripts/multi/install_yaml-cpp.sh 0.7.0 $EXT_PATH share/ci/scripts/multi/install_pystring.sh 1.1.3 $EXT_PATH share/ci/scripts/multi/install_pybind11.sh 2.9.2 $EXT_PATH + share/ci/scripts/multi/install_zlib.sh 1.2.12 $EXT_PATH + share/ci/scripts/multi/install_minizip-ng.sh 3.0.6 $EXT_PATH - name: Install latest ext package versions run: | share/ci/scripts/multi/install_imath.sh latest $EXT_PATH @@ -206,12 +209,15 @@ jobs: share/ci/scripts/macos/install_boost.sh latest share/ci/scripts/multi/install_pugixml.sh latest $EXT_PATH - name: Install fixed ext package versions + # Minizip-ng depends on ZLIB. ZLIB must be installed first. run: | share/ci/scripts/multi/install_expat.sh 2.4.1 $EXT_PATH share/ci/scripts/multi/install_lcms2.sh 2.2 $EXT_PATH share/ci/scripts/multi/install_yaml-cpp.sh 0.7.0 $EXT_PATH share/ci/scripts/multi/install_pystring.sh 1.1.3 $EXT_PATH share/ci/scripts/multi/install_pybind11.sh 2.9.2 $EXT_PATH + share/ci/scripts/multi/install_zlib.sh 1.2.12 $EXT_PATH + share/ci/scripts/multi/install_minizip-ng.sh 3.0.6 $EXT_PATH - name: Install latest ext package versions run: | share/ci/scripts/multi/install_imath.sh latest $EXT_PATH @@ -325,12 +331,15 @@ jobs: share/ci/scripts/multi/install_pugixml.sh latest $EXT_PATH shell: bash - name: Install fixed ext package versions + # Minizip-ng depends on ZLIB. ZLIB must be installed first. run: | share/ci/scripts/multi/install_lcms2.sh 2.2 $EXT_PATH share/ci/scripts/multi/install_yaml-cpp.sh 0.7.0 $EXT_PATH share/ci/scripts/multi/install_pystring.sh 1.1.3 $EXT_PATH share/ci/scripts/multi/install_pybind11.sh 2.9.2 $EXT_PATH share/ci/scripts/multi/install_expat.sh 2.4.1 $EXT_PATH + share/ci/scripts/multi/install_zlib.sh 1.2.12 $EXT_PATH + share/ci/scripts/multi/install_minizip-ng.sh 3.0.6 $EXT_PATH shell: bash # OSL not installed due to LLVM compilation time. - name: Install latest ext package versions diff --git a/share/ci/scripts/multi/install_minizip-ng.sh b/share/ci/scripts/multi/install_minizip-ng.sh new file mode 100755 index 0000000000..b8c5aab75a --- /dev/null +++ b/share/ci/scripts/multi/install_minizip-ng.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. + +set -ex + +MINIZIPNG_VERSION="$1" +INSTALL_TARGET="$2" + +MINIZIPNG_MAJOR_MINOR=$(echo "${MINIZIPNG_VERSION}" | cut -d. -f-2) +MINIZIPNG_MAJOR=$(echo "${MINIZIPNG_VERSION}" | cut -d. -f-1) +MINIZIPNG_MINOR=$(echo "${MINIZIPNG_MAJOR_MINOR}" | cut -d. -f2-) +MINIZIPNG_PATCH=$(echo "${MINIZIPNG_VERSION}" | cut -d. -f3-) +MINIZIPNG_VERSION_U="${MINIZIPNG_MAJOR}.${MINIZIPNG_MINOR}.${MINIZIPNG_PATCH}" + +git clone https://github.com/zlib-ng/minizip-ng +cd minizip-ng + +if [ "$MINIZIPNG_VERSION" == "latest" ]; then + LATEST_TAG=$(git describe --abbrev=0 --tags) + git checkout tags/${LATEST_TAG} -b ${LATEST_TAG} +else + git checkout tags/${MINIZIPNG_VERSION_U} -b ${MINIZIPNG_VERSION_U} +fi + +mkdir build +cd build + +cmake -DCMAKE_BUILD_TYPE=Release \ + ${INSTALL_TARGET:+"-DCMAKE_INSTALL_PREFIX="${INSTALL_TARGET}""} \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DBUILD_SHARED_LIBS=OFF \ + -DMZ_OPENSSL=OFF \ + -DMZ_LIBBSD=OFF \ + -DMZ_BUILD_TESTS=OFF \ + -DMZ_COMPAT=OFF \ + -DMZ_BZIP2=OFF \ + -DMZ_LZMA=OFF \ + -DMZ_LIBCOMP=OFF \ + -DMZ_ZSTD=OFF \ + -DMZ_PKCRYPT=OFF \ + -DMZ_WZAES=OFF \ + -DMZ_SIGNING=OFF \ + -DMZ_ZLIB=ON \ + -DMZ_ICONV=OFF \ + -DMZ_FETCH_LIBS=OFF \ + -DMZ_FORCE_FETCH_LIBS=OFF \ + -DZLIB_LIBRARY=${INSTALL_TARGET}/${CMAKE_INSTALL_LIBDIR} \ + -DZLIB_INCLUDE_DIR=${INSTALL_TARGET}/include \ + ../. +cmake --build . \ + --target install \ + --config Release \ + --parallel 2 + +cd ../.. +rm -rf minizip-ng diff --git a/share/ci/scripts/multi/install_zlib.sh b/share/ci/scripts/multi/install_zlib.sh new file mode 100755 index 0000000000..1bd5460641 --- /dev/null +++ b/share/ci/scripts/multi/install_zlib.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. + +set -ex + +ZLIB_VERSION="$1" +INSTALL_TARGET="$2" + +ZLIB_MAJOR_MINOR=$(echo "${ZLIB_VERSION}" | cut -d. -f-2) +ZLIB_MAJOR=$(echo "${ZLIB_VERSION}" | cut -d. -f-1) +ZLIB_MINOR=$(echo "${ZLIB_MAJOR_MINOR}" | cut -d. -f2-) +ZLIB_PATCH=$(echo "${ZLIB_VERSION}" | cut -d. -f3-) +ZLIB_VERSION_U="${ZLIB_MAJOR}.${ZLIB_MINOR}.${ZLIB_PATCH}" + +git clone https://github.com/madler/zlib +cd zlib + +if [ "$ZLIB_VERSION" == "latest" ]; then + LATEST_TAG=$(git describe --abbrev=0 --tags) + git checkout tags/${LATEST_TAG} -b ${LATEST_TAG} +else + git checkout tags/v${ZLIB_VERSION_U} -b v${ZLIB_VERSION_U} +fi + +mkdir build +cd build + +cmake -DCMAKE_BUILD_TYPE=Release \ + ${INSTALL_TARGET:+"-DCMAKE_INSTALL_PREFIX="${INSTALL_TARGET}""} \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DBUILD_SHARED_LIBS=OFF \ + ../. +cmake --build . \ + --target install \ + --config Release \ + --parallel 2 + +cd ../.. +rm -rf zlib diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index 528d1d0d3e..b0136abc5f 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -3,6 +3,12 @@ # # Locate or install minizip-ng # +# This module will try to do the following: +# 1) Locate minizip-ng +# 2) If minizip-ng cannot be found, it will try to find minizip (minizip-ng with MZ_COMPAT=ON) +# 3) If minizip-ng with MZ_COMPAT=ON cannot be found, minizip-ng will be downloaded, built and +# installed. +# # Variables defined by this module: # minizip-ng_FOUND - If FALSE, do not try to link to minizip-ng # minizip-ng_LIBRARY - minizip-ng library to link to @@ -10,7 +16,18 @@ # minizip-ng_VERSION - The version of the library # # Targets defined by this module: -# minizip-ng::minizip-ng - IMPORTED target, if found +# MINIZIP::minizip-ng - IMPORTED target, if found +# +# If minizip-ng is not installed in a standard path, you can use the minizip-ng_ROOT +# variable to tell CMake where to find it. If it is not found and +# OCIO_INSTALL_EXT_PACKAGES is set to MISSING or ALL, minizip-ng will be downloaded, +# built, and statically-linked into libOpenColorIO at build time. +# +# For external builds of minizip-ng, please note that the same build options should be used. +# Using more options, such as enabling other compression methods, will provoke linking issue +# since OCIO is not linking to those libraries. +# +# e.g. Setting MZ_BZIP2=ON will cause linking issue since OCIO will not be linked against BZIP2. # ############################################################################### ### Try to find package ### @@ -18,13 +35,58 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) if(NOT DEFINED minizip-ng_ROOT) # Search for minizip-ng-config.cmake - find_package(minizip-ng ${minizip-ng_FIND_VERSION} CONFIG) + find_package(minizip-ng ${minizip-ng_FIND_VERSION} CONFIG QUIET) endif() if (minizip-ng_FOUND) - get_target_property(minizip-ng_LIBRARY MINIZIP::minizip-ng LOCATION) get_target_property(minizip-ng_INCLUDE_DIR MINIZIP::minizip-ng INTERFACE_INCLUDE_DIRECTORIES) - else () + get_target_property(minizip-ng_LIBRARY MINIZIP::minizip-ng LOCATION) + + # Depending on the options used when minizip-ng was built, it could have multiple libraries + # listed in INTERFACE_LINK_LIBRARIES. OCIO only needs ZLIB. + # Only add custom zlib target ZLIB::ZLIB to INTERFACE_LINK_LIBRARIES. + set_target_properties(MINIZIP::minizip-ng PROPERTIES INTERFACE_LINK_LIBRARIES "ZLIB::ZLIB") + + if (NOT minizip-ng_LIBRARY) + # Lib names to search for + set(_minizip-ng_LIB_NAMES minizip-ng) + + if(BUILD_TYPE_DEBUG) + # Prefer Debug lib names (Windows only) + list(INSERT _minizip-ng_LIB_NAMES 0 minizip-ngd) + endif() + + if(minizip-ng_STATIC_LIBRARY) + # Prefer static lib names + set(_minizip-ng_STATIC_LIB_NAMES + "${CMAKE_STATIC_LIBRARY_PREFIX}minizip-ng${CMAKE_STATIC_LIBRARY_SUFFIX}") + if(WIN32 AND BUILD_TYPE_DEBUG) + # Prefer static Debug lib names (Windows only) + list(INSERT _minizip-ng_STATIC_LIB_NAMES 0 + "${CMAKE_STATIC_LIBRARY_PREFIX}minizip-ngd${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() + endif() + + # Find library + find_library(minizip-ng_LIBRARY + NAMES + ${_minizip-ng_STATIC_LIB_NAMES} + ${_minizip-ng_LIB_NAMES} + HINTS + ${minizip-ng_ROOT} + ${PC_minizip-ng_LIBRARY_DIRS} + PATH_SUFFIXES + lib64 lib + ) + + # Set IMPORTED_LOCATION property for MINIZIP::minizip-ng target. + if (TARGET MINIZIP::minizip-ng) + set_target_properties(MINIZIP::minizip-ng PROPERTIES + IMPORTED_LOCATION "${minizip-ng_LIBRARY}" + ) + endif() + endif() + else() list(APPEND _minizip-ng_REQUIRED_VARS minizip-ng_INCLUDE_DIR) # Search for minizip-ng.pc @@ -40,11 +102,13 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) ${PC_minizip-ng_INCLUDE_DIRS} PATH_SUFFIXES include + include/minizip-ng minizip-ng/include ) # Lib names to search for - set(_minizip-ng_LIB_NAMES minizip-ng libminizip-ng) + set(_minizip-ng_LIB_NAMES minizip-ng) + if(BUILD_TYPE_DEBUG) # Prefer Debug lib names (Windows only) list(INSERT _minizip-ng_LIB_NAMES 0 minizip-ngd) @@ -92,127 +156,140 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) ) endif() -############################################################################### -### Create target - -if(NOT TARGET minizip-ng::minizip-ng) - add_library(minizip-ng::minizip-ng UNKNOWN IMPORTED GLOBAL) - set(_minizip-ng_TARGET_CREATE TRUE) +if(NOT minizip-ng_FOUND) + # Looking for an external minizip-ng that might be built using MZ_COMPAT=ON. + # But do not download it if it cannot be found. + find_package(minizip ${minizip-ng_FIND_VERSION} REQUIRED) endif() -############################################################################### -### Install package from source ### -if(NOT minizip-ng_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - include(ExternalProject) - include(GNUInstallDirs) - - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - - # Set find_package standard args - set(minizip-ng_FOUND TRUE) - set(minizip-ng_VERSION ${minizip-ng_FIND_VERSION}) - set(minizip-ng_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") - - # Minizip-ng use a hardcoded lib prefix instead of CMAKE_STATIC_LIBRARY_PREFIX - set(_minizip-ng_LIB_PREFIX "lib") - - set(minizip-ng_LIBRARY - "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${_minizip-ng_LIB_PREFIX}minizip-ng${_minizip-ng_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") - - if(_minizip-ng_TARGET_CREATE) - set(MINIZIP-NG_CMAKE_ARGS - ${MINIZIP-NG_CMAKE_ARGS} - -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} - -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} - -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} - -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} - -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} - -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}/minizip-ng - -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} - -DBUILD_SHARED_LIBS=OFF - -DMZ_OPENSSL=OFF - -DMZ_LIBBSD=OFF - -DMZ_BUILD_TESTS=OFF - -DMZ_COMPAT=OFF - -DMZ_BZIP2=OFF - -DMZ_LZMA=OFF - -DMZ_LIBCOMP=OFF - -DMZ_ZSTD=OFF - -DMZ_PKCRYPT=OFF - -DMZ_WZAES=OFF - -DMZ_SIGNING=OFF - -DMZ_ZLIB=ON - -DMZ_ICONV=OFF - -DMZ_FETCH_LIBS=OFF - -DMZ_FORCE_FETCH_LIBS=OFF - -DZLIB_LIBRARY=${ZLIB_LIBRARIES} - -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIRS} - ) +if(NOT minizip_FOUND AND NOT TARGET MINIZIP::minizip) + ############################################################################### + ### Create target - if(CMAKE_TOOLCHAIN_FILE) - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) - endif() + if(NOT TARGET MINIZIP::minizip-ng) + add_library(MINIZIP::minizip-ng UNKNOWN IMPORTED GLOBAL) + set(_minizip-ng_TARGET_CREATE TRUE) + endif() + + ############################################################################### + ### Install package from source ### + if(NOT minizip-ng_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(ExternalProject) + include(GNUInstallDirs) + + set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") + set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") - if(APPLE) - string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + # Set find_package standard args + set(minizip-ng_FOUND TRUE) + set(minizip-ng_VERSION ${minizip-ng_FIND_VERSION}) - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} - -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} - -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} + set(minizip-ng_INCLUDE_DIR "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}/minizip-ng") + + # Minizip-ng use a hardcoded lib prefix instead of CMAKE_STATIC_LIBRARY_PREFIX + set(_minizip-ng_LIB_PREFIX "lib") + + set(minizip-ng_LIBRARY + "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_LIBDIR}/${_minizip-ng_LIB_PREFIX}minizip-ng${_minizip-ng_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") + + if(_minizip-ng_TARGET_CREATE) + set(MINIZIP-NG_CMAKE_ARGS + ${MINIZIP-NG_CMAKE_ARGS} + -DCMAKE_CXX_VISIBILITY_PRESET=${CMAKE_CXX_VISIBILITY_PRESET} + -DCMAKE_VISIBILITY_INLINES_HIDDEN=${CMAKE_VISIBILITY_INLINES_HIDDEN} + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DCMAKE_INSTALL_MESSAGE=${CMAKE_INSTALL_MESSAGE} + -DCMAKE_INSTALL_PREFIX=${_EXT_DIST_ROOT} + -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} + -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} + -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} + # Since the other modules create a subfolder for the includes by default and since + # minizip-ng does not, a suffix is added to CMAKE_INSTALL_INCLUDEDIR in order to + # install the headers under a subdirectory named "minizip-ng". + # Note that this does not affect external builds for minizip-ng. + -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}/minizip-ng + -DCMAKE_OBJECT_PATH_MAX=${CMAKE_OBJECT_PATH_MAX} + -DBUILD_SHARED_LIBS=OFF + -DMZ_OPENSSL=OFF + -DMZ_LIBBSD=OFF + -DMZ_BUILD_TESTS=OFF + -DMZ_COMPAT=OFF + -DMZ_BZIP2=OFF + -DMZ_LZMA=OFF + -DMZ_LIBCOMP=OFF + -DMZ_ZSTD=OFF + -DMZ_PKCRYPT=OFF + -DMZ_WZAES=OFF + -DMZ_SIGNING=OFF + -DMZ_ZLIB=ON + -DMZ_ICONV=OFF + -DMZ_FETCH_LIBS=OFF + -DMZ_FORCE_FETCH_LIBS=OFF + -DZLIB_LIBRARY=${ZLIB_LIBRARIES} + -DZLIB_INCLUDE_DIR=${ZLIB_INCLUDE_DIRS} ) - endif() - if (ANDROID) - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_STL=${ANDROID_STL}) + if(CMAKE_TOOLCHAIN_FILE) + set(minizip-ng_CMAKE_ARGS + ${minizip-ng_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + endif() + + if(APPLE) + string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") + + set(minizip-ng_CMAKE_ARGS + ${minizip-ng_CMAKE_ARGS} + -DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET} + -DCMAKE_OSX_ARCHITECTURES=${ESCAPED_CMAKE_OSX_ARCHITECTURES} + ) + endif() + + if (ANDROID) + set(minizip-ng_CMAKE_ARGS + ${minizip-ng_CMAKE_ARGS} + -DANDROID_PLATFORM=${ANDROID_PLATFORM} + -DANDROID_ABI=${ANDROID_ABI} + -DANDROID_STL=${ANDROID_STL}) + endif() endif() - endif() - # Hack to let imported target be built from ExternalProject_Add - file(MAKE_DIRECTORY ${minizip-ng_INCLUDE_DIR}) - - ExternalProject_Add(minizip-ng_install - GIT_REPOSITORY "https://github.com/zlib-ng/minizip-ng.git" - GIT_TAG "${minizip-ng_VERSION}" - GIT_CONFIG advice.detachedHead=false - GIT_SHALLOW TRUE - PREFIX "${_EXT_BUILD_ROOT}/libminizip-ng" - BUILD_BYPRODUCTS ${minizip-ng_LIBRARY} - CMAKE_ARGS ${MINIZIP-NG_CMAKE_ARGS} - EXCLUDE_FROM_ALL TRUE - BUILD_COMMAND "" - INSTALL_COMMAND - ${CMAKE_COMMAND} --build . - --config ${CMAKE_BUILD_TYPE} - --target install - --parallel - ) + # Hack to let imported target be built from ExternalProject_Add + file(MAKE_DIRECTORY ${minizip-ng_INCLUDE_DIR}) - add_dependencies(minizip-ng::minizip-ng minizip-ng_install) - message(STATUS "Installing minizip-ng: ${minizip-ng_LIBRARY} (version \"${minizip-ng_VERSION}\")") + ExternalProject_Add(minizip-ng_install + GIT_REPOSITORY "https://github.com/zlib-ng/minizip-ng.git" + GIT_TAG "${minizip-ng_VERSION}" + GIT_CONFIG advice.detachedHead=false + GIT_SHALLOW TRUE + PREFIX "${_EXT_BUILD_ROOT}/libminizip-ng" + BUILD_BYPRODUCTS ${minizip-ng_LIBRARY} + CMAKE_ARGS ${MINIZIP-NG_CMAKE_ARGS} + EXCLUDE_FROM_ALL TRUE + BUILD_COMMAND "" + INSTALL_COMMAND + ${CMAKE_COMMAND} --build . + --config ${CMAKE_BUILD_TYPE} + --target install + --parallel + ) + + add_dependencies(MINIZIP::minizip-ng minizip-ng_install) + message(STATUS "Installing minizip-ng: ${minizip-ng_LIBRARY} (version \"${minizip-ng_VERSION}\")") + endif() endif() ############################################################################### ### Configure target ### if(_minizip-ng_TARGET_CREATE) - set_target_properties(minizip-ng::minizip-ng PROPERTIES + set_target_properties(MINIZIP::minizip-ng PROPERTIES IMPORTED_LOCATION "${minizip-ng_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${minizip-ng_INCLUDE_DIR}" ) mark_as_advanced(minizip-ng_INCLUDE_DIR minizip-ng_LIBRARY minizip-ng_VERSION) - target_link_libraries(minizip-ng::minizip-ng INTERFACE ZLIB::ZLIB) + target_link_libraries(MINIZIP::minizip-ng INTERFACE ZLIB::ZLIB) endif() \ No newline at end of file diff --git a/share/cmake/modules/Findminizip.cmake b/share/cmake/modules/Findminizip.cmake new file mode 100644 index 0000000000..1a75747177 --- /dev/null +++ b/share/cmake/modules/Findminizip.cmake @@ -0,0 +1,172 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright Contributors to the OpenColorIO Project. +# +# Locate minizip-ng with MZ_COMPAT=ON. +# +# This module DOES NOT install minizip-ng with MZ_COMPAT=ON if it is not found. +# +# Note: This option changes the name for the library file to "libminizip", but it is still +# actually minizip-ng. OCIO uses the API from minizip-ng. +# +# Variables defined by this module: +# minizip_FOUND - If FALSE, do not try to link to minizip +# minizip_LIBRARY - minizip library to link to +# minizip_INCLUDE_DIR - Where to find mz.h and other headers +# minizip_VERSION - The version of the library +# +# This module set the variables below because this is still minizip-ng. The librarie become +# "minizip" because of the cmake option MZ_COMPAT=ON. +# +# minizip-ng_FOUND - If FALSE, do not try to link to minizip-ng +# minizip-ng_LIBRARY - minizip-ng library to link to +# minizip-ng_INCLUDE_DIR - Where to find mz.h and other headers +# minizip-ng_VERSION - The version of the library +# +# Targets defined by this module: +# MINIZIP::minizip-ng - IMPORTED target, if found +# +############################################################################### +### Try to find package ### + +if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) + + if(NOT DEFINED minizip_ROOT) + # Search for minizip-config.cmake + find_package(minizip ${minizip_FIND_VERSION} CONFIG QUIET) + endif() + + if (minizip_FOUND) + get_target_property(minizip_INCLUDE_DIR MINIZIP::minizip INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(minizip_LIBRARY MINIZIP::minizip LOCATION) + + if (NOT minizip_LIBRARY) + # Lib names to search for + set(_minizip_LIB_NAMES minizip) + + if(BUILD_TYPE_DEBUG) + # Prefer Debug lib names (Windows only) + list(INSERT _minizip_LIB_NAMES 0 minizipd) + endif() + + if(minizip_STATIC_LIBRARY) + # Prefer static lib names + set(_minizip_STATIC_LIB_NAMES + "${CMAKE_STATIC_LIBRARY_PREFIX}minizip${CMAKE_STATIC_LIBRARY_SUFFIX}") + if(WIN32 AND BUILD_TYPE_DEBUG) + # Prefer static Debug lib names (Windows only) + list(INSERT _minizip_STATIC_LIB_NAMES 0 + "${CMAKE_STATIC_LIBRARY_PREFIX}minizipd${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() + endif() + + # Find library + find_library(minizip_LIBRARY + NAMES + ${_minizip_STATIC_LIB_NAMES} + ${_minizip_LIB_NAMES} + HINTS + ${minizip_ROOT} + ${PC_minizip_LIBRARY_DIRS} + PATH_SUFFIXES + lib64 lib + ) + endif() + else() + list(APPEND _minizip_REQUIRED_VARS minizip_INCLUDE_DIR) + + # Search for minizip.pc + find_package(PkgConfig QUIET) + pkg_check_modules(PC_minizip QUIET "minizip>=${minizip_FIND_VERSION}") + + # Find include directory + find_path(minizip_INCLUDE_DIR + NAMES + mz.h + HINTS + ${minizip_ROOT} + ${PC_minizip_INCLUDE_DIRS} + PATH_SUFFIXES + include + minizip/include + ) + + # Lib names to search for + set(_minizip_LIB_NAMES minizip) + + if(BUILD_TYPE_DEBUG) + # Prefer Debug lib names (Windows only) + list(INSERT _minizip_LIB_NAMES 0 minizipd) + endif() + + if(minizip_STATIC_LIBRARY) + # Prefer static lib names + set(_minizip_STATIC_LIB_NAMES + "${CMAKE_STATIC_LIBRARY_PREFIX}minizip${CMAKE_STATIC_LIBRARY_SUFFIX}") + if(WIN32 AND BUILD_TYPE_DEBUG) + # Prefer static Debug lib names (Windows only) + list(INSERT _minizip_STATIC_LIB_NAMES 0 + "${CMAKE_STATIC_LIBRARY_PREFIX}minizipd${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() + endif() + + # Find library + find_library(minizip_LIBRARY + NAMES + ${_minizip_STATIC_LIB_NAMES} + ${_minizip_LIB_NAMES} + HINTS + ${minizip_ROOT} + ${PC_minizip_LIBRARY_DIRS} + PATH_SUFFIXES + lib64 + lib + ) + + # Get version from header or pkg-config + set(minizip_VERSION "${minizip_FIND_VERSION}") + endif() + + # Override REQUIRED if package can be installed + if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) + set(minizip_FIND_REQUIRED FALSE) + endif() + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(minizip + REQUIRED_VARS + minizip_LIBRARY + minizip_INCLUDE_DIR + VERSION_VAR + minizip_VERSION + ) +endif() + +############################################################################### +### Create target + +if(minizip_FOUND AND NOT TARGET MINIZIP::minizip-ng) + add_library(MINIZIP::minizip-ng UNKNOWN IMPORTED GLOBAL) + set(_minizip_TARGET_CREATE TRUE) +endif() + +############################################################################### + +############################################################################### +### Configure target ### + +if(minizip_FOUND AND _minizip_TARGET_CREATE) + set_target_properties(MINIZIP::minizip-ng PROPERTIES + IMPORTED_LOCATION "${minizip_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${minizip_INCLUDE_DIR}" + ) + + # This is still minizip-ng even though the library is called minizip because of MZ_COMPAT=ON. + set(minizip-ng_LIBRARY ${minizip_LIBRARY}) + set(minizip-ng_INCLUDE_DIR ${minizip_INCLUDE_DIR}) + set(minizip-ng_FOUND ${minizip_FOUND}) + set(minizip-ng_VERSION ${minizip_VERSION}) + + mark_as_advanced(minizip_INCLUDE_DIR minizip_LIBRARY minizip_VERSION) + + target_link_libraries(MINIZIP::minizip-ng INTERFACE ZLIB::ZLIB) +endif() \ No newline at end of file diff --git a/src/OpenColorIO/CMakeLists.txt b/src/OpenColorIO/CMakeLists.txt index ab9c048126..2bc379e118 100755 --- a/src/OpenColorIO/CMakeLists.txt +++ b/src/OpenColorIO/CMakeLists.txt @@ -277,7 +277,7 @@ target_link_libraries(OpenColorIO "$" "$" yaml-cpp - minizip-ng::minizip-ng + MINIZIP::minizip-ng ) if(APPLE) diff --git a/src/OpenColorIO/OCIOZArchive.cpp b/src/OpenColorIO/OCIOZArchive.cpp index 52e292ef77..85fc7bb76d 100644 --- a/src/OpenColorIO/OCIOZArchive.cpp +++ b/src/OpenColorIO/OCIOZArchive.cpp @@ -17,16 +17,16 @@ #include "OCIOZArchive.h" -#include "minizip-ng/mz.h" -#include "minizip-ng/mz_os.h" -#include "minizip-ng/mz_strm.h" -#include "minizip-ng/mz_strm_buf.h" -#include "minizip-ng/mz_strm_mem.h" -#include "minizip-ng/mz_strm_os.h" -#include "minizip-ng/mz_strm_split.h" -#include "minizip-ng/mz_strm_zlib.h" -#include "minizip-ng/mz_zip.h" -#include "minizip-ng/mz_zip_rw.h" +#include "mz.h" +#include "mz_os.h" +#include "mz_strm.h" +#include "mz_strm_buf.h" +#include "mz_strm_mem.h" +#include "mz_strm_os.h" +#include "mz_strm_split.h" +#include "mz_strm_zlib.h" +#include "mz_zip.h" +#include "mz_zip_rw.h" namespace OCIO_NAMESPACE { diff --git a/src/apps/ocioarchive/CMakeLists.txt b/src/apps/ocioarchive/CMakeLists.txt index d71d719aeb..6b868d1979 100644 --- a/src/apps/ocioarchive/CMakeLists.txt +++ b/src/apps/ocioarchive/CMakeLists.txt @@ -19,7 +19,7 @@ target_link_libraries(ocioarchive PRIVATE apputils OpenColorIO - minizip-ng::minizip-ng + MINIZIP::minizip-ng ) install(TARGETS ocioarchive diff --git a/src/apps/ocioarchive/main.cpp b/src/apps/ocioarchive/main.cpp index bf222fc8aa..190cadee54 100644 --- a/src/apps/ocioarchive/main.cpp +++ b/src/apps/ocioarchive/main.cpp @@ -13,11 +13,11 @@ namespace OCIO = OCIO_NAMESPACE; #include "apputils/argparse.h" // Config archive functionality. -#include "minizip-ng/mz.h" -#include "minizip-ng/mz_os.h" -#include "minizip-ng/mz_strm.h" -#include "minizip-ng/mz_zip.h" -#include "minizip-ng/mz_zip_rw.h" +#include "mz.h" +#include "mz_os.h" +#include "mz_strm.h" +#include "mz_zip.h" +#include "mz_zip_rw.h" // Array of non OpenColorIO arguments. static std::vector args; diff --git a/tests/cpu/CMakeLists.txt b/tests/cpu/CMakeLists.txt index ff3b19dc78..e78a86bede 100755 --- a/tests/cpu/CMakeLists.txt +++ b/tests/cpu/CMakeLists.txt @@ -23,7 +23,7 @@ function(add_ocio_test NAME SOURCES PRIVATE_INCLUDES) utils::strings yaml-cpp testutils - minizip-ng::minizip-ng + MINIZIP::minizip-ng xxHash )