From b9d1cbc241100143a154b5f4ac8c82c6ce466ddd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Mon, 7 Nov 2022 11:44:58 -0500 Subject: [PATCH 1/5] - 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. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- share/cmake/modules/Findminizip-ng.cmake | 334 ++++++++++++----------- share/cmake/modules/Findminizip.cmake | 128 +++++++++ src/OpenColorIO/OCIOZArchive.cpp | 20 +- src/apps/ocioarchive/main.cpp | 10 +- 4 files changed, 316 insertions(+), 176 deletions(-) create mode 100644 share/cmake/modules/Findminizip.cmake diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index 528d1d0d3e..eb2ea48223 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 @@ -16,66 +22,58 @@ ### Try to find package ### 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) - endif() + list(APPEND _minizip-ng_REQUIRED_VARS minizip-ng_INCLUDE_DIR) + + # Search for minizip-ng.pc + find_package(PkgConfig QUIET) + pkg_check_modules(PC_minizip-ng QUIET "minizip-ng>=${minizip-ng_FIND_VERSION}") + + # Find include directory + find_path(minizip-ng_INCLUDE_DIR + NAMES + mz.h + HINTS + ${minizip-ng_ROOT} + ${PC_minizip-ng_INCLUDE_DIRS} + PATH_SUFFIXES + include + include/minizip-ng + minizip-ng/include + ) - 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 () - list(APPEND _minizip-ng_REQUIRED_VARS minizip-ng_INCLUDE_DIR) - - # Search for minizip-ng.pc - find_package(PkgConfig QUIET) - pkg_check_modules(PC_minizip-ng QUIET "minizip-ng>=${minizip-ng_FIND_VERSION}") - - # Find include directory - find_path(minizip-ng_INCLUDE_DIR - NAMES - mz.h - HINTS - ${minizip-ng_ROOT} - ${PC_minizip-ng_INCLUDE_DIRS} - PATH_SUFFIXES - include - minizip-ng/include - ) + # Lib names to search for + set(_minizip-ng_LIB_NAMES minizip-ng) - # Lib names to search for - set(_minizip-ng_LIB_NAMES minizip-ng libminizip-ng) - if(BUILD_TYPE_DEBUG) - # Prefer Debug lib names (Windows only) - list(INSERT _minizip-ng_LIB_NAMES 0 minizip-ngd) - endif() + 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() + 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 - ) + # 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 + ) - # Get version from header or pkg-config - set(minizip-ng_VERSION "${minizip-ng_FIND_VERSION}") - endif() + # Get version from header or pkg-config + set(minizip-ng_VERSION "${minizip-ng_FIND_VERSION}") # Override REQUIRED if package can be installed if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) @@ -92,127 +90,141 @@ 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) +if(NOT minizip_FOUND AND NOT TARGET minizip::minizip) + ############################################################################### + ### Create target - set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") - set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + if(NOT TARGET minizip-ng::minizip-ng) + add_library(minizip-ng::minizip-ng UNKNOWN IMPORTED GLOBAL) + set(_minizip-ng_TARGET_CREATE TRUE) + endif() - # 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}") + ############################################################################### + + ### 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") + + # 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 creates 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} + ) - # Minizip-ng use a hardcoded lib prefix instead of CMAKE_STATIC_LIBRARY_PREFIX - set(_minizip-ng_LIB_PREFIX "lib") + if(CMAKE_TOOLCHAIN_FILE) + set(minizip-ng_CMAKE_ARGS + ${minizip-ng_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + endif() - 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(APPLE) + string(REPLACE ";" "$" ESCAPED_CMAKE_OSX_ARCHITECTURES "${CMAKE_OSX_ARCHITECTURES}") - 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} - ) + 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(CMAKE_TOOLCHAIN_FILE) - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) + 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() - 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() + # 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 + ) - if (ANDROID) - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} - -DANDROID_PLATFORM=${ANDROID_PLATFORM} - -DANDROID_ABI=${ANDROID_ABI} - -DANDROID_STL=${ANDROID_STL}) - endif() + add_dependencies(minizip-ng::minizip-ng minizip-ng_install) + message(STATUS "Installing minizip-ng: ${minizip-ng_LIBRARY} (version \"${minizip-ng_VERSION}\")") 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 - ) + ############################################################################### + ### Configure target ### - add_dependencies(minizip-ng::minizip-ng minizip-ng_install) - message(STATUS "Installing minizip-ng: ${minizip-ng_LIBRARY} (version \"${minizip-ng_VERSION}\")") -endif() - -############################################################################### -### Configure target ### - -if(_minizip-ng_TARGET_CREATE) - set_target_properties(minizip-ng::minizip-ng PROPERTIES - IMPORTED_LOCATION "${minizip-ng_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${minizip-ng_INCLUDE_DIR}" - ) + if(_minizip-ng_TARGET_CREATE) + set_target_properties(minizip-ng::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) + 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-ng::minizip-ng INTERFACE ZLIB::ZLIB) + endif() 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..cad9d0b23f --- /dev/null +++ b/share/cmake/modules/Findminizip.cmake @@ -0,0 +1,128 @@ +# 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: That options changes the name for the library file to "libminizip", but is it still +# 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-ng::minizip-ng - IMPORTED target, if found +# +############################################################################### +### Try to find package ### + +if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) + 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}") + + # 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) + add_library(minizip-ng::minizip-ng UNKNOWN IMPORTED GLOBAL) + set(_minizip_TARGET_CREATE TRUE) +endif() + +############################################################################### + +############################################################################### +### Configure target ### + +if(minizip_FOUND AND _minizip_TARGET_CREATE) + set_target_properties(minizip-ng::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-ng::minizip-ng INTERFACE ZLIB::ZLIB) +endif() \ No newline at end of file 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/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; From 6f6a4842f37dbc44d928cc5f30894a28b35eaeb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 8 Nov 2022 10:59:44 -0500 Subject: [PATCH 2/5] Update comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- share/cmake/modules/Findminizip-ng.cmake | 2 +- share/cmake/modules/Findminizip.cmake | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index eb2ea48223..973fff2a0d 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -140,7 +140,7 @@ if(NOT minizip_FOUND AND NOT TARGET minizip::minizip) -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR} -DCMAKE_INSTALL_DATADIR=${CMAKE_INSTALL_DATADIR} -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} - # Since the other modules creates a subfolder for the includes by default and since + # 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. diff --git a/share/cmake/modules/Findminizip.cmake b/share/cmake/modules/Findminizip.cmake index cad9d0b23f..1eb9c0de02 100644 --- a/share/cmake/modules/Findminizip.cmake +++ b/share/cmake/modules/Findminizip.cmake @@ -5,8 +5,8 @@ # # This module DOES NOT install minizip-ng with MZ_COMPAT=ON if it is not found. # -# Note: That options changes the name for the library file to "libminizip", but is it still -# minizip-ng. OCIO uses the API from minizip-ng. +# 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 From 265d5f2f8afa107b27743c4fd9b82e5b44bf535b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 15 Nov 2022 08:56:40 -0500 Subject: [PATCH 3/5] Improved find_package in Config mode (adding it back) Added missing scripts to install minizip-ng and zlib for the analysis workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- .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 | 167 ++++++++++++------- share/cmake/modules/Findminizip.cmake | 136 ++++++++++----- 5 files changed, 306 insertions(+), 103 deletions(-) create mode 100644 share/ci/scripts/multi/install_minizip-ng.sh create mode 100644 share/ci/scripts/multi/install_zlib.sh 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 100644 index 0000000000..d5dff07900 --- /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=/opt/aswf/zlib/build/ext/lib \ + -DZLIB_INCLUDE_DIR=/opt/aswf/zlib/build/ext/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 100644 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 973fff2a0d..2517f1831f 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -18,62 +18,116 @@ # Targets defined by this module: # minizip-ng::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 ### if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) - list(APPEND _minizip-ng_REQUIRED_VARS minizip-ng_INCLUDE_DIR) - - # Search for minizip-ng.pc - find_package(PkgConfig QUIET) - pkg_check_modules(PC_minizip-ng QUIET "minizip-ng>=${minizip-ng_FIND_VERSION}") - - # Find include directory - find_path(minizip-ng_INCLUDE_DIR - NAMES - mz.h - HINTS - ${minizip-ng_ROOT} - ${PC_minizip-ng_INCLUDE_DIRS} - PATH_SUFFIXES - include - include/minizip-ng - minizip-ng/include - ) + if(NOT DEFINED minizip-ng_ROOT) + # Search for minizip-ng-config.cmake + find_package(minizip-ng ${minizip-ng_FIND_VERSION} CONFIG QUIET) + endif() - # Lib names to search for - set(_minizip-ng_LIB_NAMES minizip-ng) + if (minizip-ng_FOUND) + get_target_property(minizip-ng_INCLUDE_DIR MINIZIP::minizip-ng INTERFACE_INCLUDE_DIRECTORIES) + get_target_property(minizip-ng_LIBRARY MINIZIP::minizip-ng LOCATION) - if(BUILD_TYPE_DEBUG) - # Prefer Debug lib names (Windows only) - list(INSERT _minizip-ng_LIB_NAMES 0 minizip-ngd) - endif() + 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}") + 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 + ) endif() - endif() + else() + list(APPEND _minizip-ng_REQUIRED_VARS minizip-ng_INCLUDE_DIR) - # 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 - ) + # Search for minizip-ng.pc + find_package(PkgConfig QUIET) + pkg_check_modules(PC_minizip-ng QUIET "minizip-ng>=${minizip-ng_FIND_VERSION}") + + # Find include directory + find_path(minizip-ng_INCLUDE_DIR + NAMES + mz.h + HINTS + ${minizip-ng_ROOT} + ${PC_minizip-ng_INCLUDE_DIRS} + PATH_SUFFIXES + include + include/minizip-ng + minizip-ng/include + ) - # Get version from header or pkg-config - set(minizip-ng_VERSION "${minizip-ng_FIND_VERSION}") + # 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 + ) + + # Get version from header or pkg-config + set(minizip-ng_VERSION "${minizip-ng_FIND_VERSION}") + endif() # Override REQUIRED if package can be installed if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) @@ -106,7 +160,6 @@ if(NOT minizip_FOUND AND NOT TARGET minizip::minizip) endif() ############################################################################### - ### Install package from source ### if(NOT minizip-ng_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) @@ -213,18 +266,18 @@ if(NOT minizip_FOUND AND NOT TARGET minizip::minizip) add_dependencies(minizip-ng::minizip-ng minizip-ng_install) message(STATUS "Installing minizip-ng: ${minizip-ng_LIBRARY} (version \"${minizip-ng_VERSION}\")") endif() +endif() - ############################################################################### - ### Configure target ### +############################################################################### +### Configure target ### - if(_minizip-ng_TARGET_CREATE) - set_target_properties(minizip-ng::minizip-ng PROPERTIES - IMPORTED_LOCATION "${minizip-ng_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${minizip-ng_INCLUDE_DIR}" - ) +if(_minizip-ng_TARGET_CREATE) + set_target_properties(minizip-ng::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) + mark_as_advanced(minizip-ng_INCLUDE_DIR minizip-ng_LIBRARY minizip-ng_VERSION) - target_link_libraries(minizip-ng::minizip-ng INTERFACE ZLIB::ZLIB) - endif() + target_link_libraries(minizip-ng::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 index 1eb9c0de02..42b8573a1e 100644 --- a/share/cmake/modules/Findminizip.cmake +++ b/share/cmake/modules/Findminizip.cmake @@ -29,58 +29,102 @@ ### Try to find package ### if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) - 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) + if(NOT DEFINED minizip_ROOT) + # Search for minizip-config.cmake + find_package(minizip ${minizip_FIND_VERSION} CONFIG QUIET) 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}") + 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() - 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 - ) + 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() - # Get version from header or pkg-config - set(minizip_VERSION "${minizip_FIND_VERSION}") + # 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) From 2d8fc0eb90bd1842f52cae1a0a75da6b1bf88b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 15 Nov 2022 10:02:47 -0500 Subject: [PATCH 4/5] Adding +x permissions for install_minizip_ng and zlib Fixing path to find zlib in install_minizip-ng.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- share/ci/scripts/multi/install_minizip-ng.sh | 4 ++-- share/ci/scripts/multi/install_zlib.sh | 0 2 files changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 share/ci/scripts/multi/install_minizip-ng.sh mode change 100644 => 100755 share/ci/scripts/multi/install_zlib.sh diff --git a/share/ci/scripts/multi/install_minizip-ng.sh b/share/ci/scripts/multi/install_minizip-ng.sh old mode 100644 new mode 100755 index d5dff07900..b8c5aab75a --- a/share/ci/scripts/multi/install_minizip-ng.sh +++ b/share/ci/scripts/multi/install_minizip-ng.sh @@ -45,8 +45,8 @@ cmake -DCMAKE_BUILD_TYPE=Release \ -DMZ_ICONV=OFF \ -DMZ_FETCH_LIBS=OFF \ -DMZ_FORCE_FETCH_LIBS=OFF \ - -DZLIB_LIBRARY=/opt/aswf/zlib/build/ext/lib \ - -DZLIB_INCLUDE_DIR=/opt/aswf/zlib/build/ext/include \ + -DZLIB_LIBRARY=${INSTALL_TARGET}/${CMAKE_INSTALL_LIBDIR} \ + -DZLIB_INCLUDE_DIR=${INSTALL_TARGET}/include \ ../. cmake --build . \ --target install \ diff --git a/share/ci/scripts/multi/install_zlib.sh b/share/ci/scripts/multi/install_zlib.sh old mode 100644 new mode 100755 From d0e7e7df1c33b9e2055a23bc2fa849124398a3f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Mon, 21 Nov 2022 15:14:51 -0500 Subject: [PATCH 5/5] 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) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- share/cmake/modules/Findminizip-ng.cmake | 26 +++++++++++++++++------- share/cmake/modules/Findminizip.cmake | 12 +++++------ src/OpenColorIO/CMakeLists.txt | 2 +- src/apps/ocioarchive/CMakeLists.txt | 2 +- tests/cpu/CMakeLists.txt | 2 +- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index 2517f1831f..b0136abc5f 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -16,7 +16,7 @@ # 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 @@ -41,6 +41,11 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) if (minizip-ng_FOUND) get_target_property(minizip-ng_INCLUDE_DIR MINIZIP::minizip-ng INTERFACE_INCLUDE_DIRECTORIES) 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 @@ -73,6 +78,13 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) 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) @@ -150,12 +162,12 @@ if(NOT minizip-ng_FOUND) find_package(minizip ${minizip-ng_FIND_VERSION} REQUIRED) endif() -if(NOT minizip_FOUND AND NOT TARGET minizip::minizip) +if(NOT minizip_FOUND AND NOT TARGET MINIZIP::minizip) ############################################################################### ### Create target - if(NOT TARGET minizip-ng::minizip-ng) - add_library(minizip-ng::minizip-ng UNKNOWN IMPORTED GLOBAL) + if(NOT TARGET MINIZIP::minizip-ng) + add_library(MINIZIP::minizip-ng UNKNOWN IMPORTED GLOBAL) set(_minizip-ng_TARGET_CREATE TRUE) endif() @@ -263,7 +275,7 @@ if(NOT minizip_FOUND AND NOT TARGET minizip::minizip) --parallel ) - add_dependencies(minizip-ng::minizip-ng minizip-ng_install) + add_dependencies(MINIZIP::minizip-ng minizip-ng_install) message(STATUS "Installing minizip-ng: ${minizip-ng_LIBRARY} (version \"${minizip-ng_VERSION}\")") endif() endif() @@ -272,12 +284,12 @@ 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 index 42b8573a1e..1a75747177 100644 --- a/share/cmake/modules/Findminizip.cmake +++ b/share/cmake/modules/Findminizip.cmake @@ -23,7 +23,7 @@ # 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 # ############################################################################### ### Try to find package ### @@ -39,7 +39,7 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) get_target_property(minizip_INCLUDE_DIR MINIZIP::minizip INTERFACE_INCLUDE_DIRECTORIES) get_target_property(minizip_LIBRARY MINIZIP::minizip LOCATION) - if (not minizip_LIBRARY) + if (NOT minizip_LIBRARY) # Lib names to search for set(_minizip_LIB_NAMES minizip) @@ -144,8 +144,8 @@ endif() ############################################################################### ### Create target -if(minizip_FOUND AND NOT TARGET minizip::minizip) - add_library(minizip-ng::minizip-ng UNKNOWN IMPORTED GLOBAL) +if(minizip_FOUND AND NOT TARGET MINIZIP::minizip-ng) + add_library(MINIZIP::minizip-ng UNKNOWN IMPORTED GLOBAL) set(_minizip_TARGET_CREATE TRUE) endif() @@ -155,7 +155,7 @@ endif() ### Configure target ### if(minizip_FOUND AND _minizip_TARGET_CREATE) - set_target_properties(minizip-ng::minizip-ng PROPERTIES + set_target_properties(MINIZIP::minizip-ng PROPERTIES IMPORTED_LOCATION "${minizip_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${minizip_INCLUDE_DIR}" ) @@ -168,5 +168,5 @@ if(minizip_FOUND AND _minizip_TARGET_CREATE) mark_as_advanced(minizip_INCLUDE_DIR minizip_LIBRARY minizip_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/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/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/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 )