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 01/23] - 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 02/23] 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 03/23] 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 04/23] 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 05/23] 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 ) From d7ec9ca7c97c9d85a2a69e98b15d31cd9d9d2030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Mon, 28 Nov 2022 16:01:39 -0500 Subject: [PATCH 06/23] First pass for the OpenColorIOConfig.cmake file with the required dependencies only. A few extra fixes for OpenEXR, ZLIB and Minizip-ng. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- CMakeLists.txt | 13 ++++++ share/cmake/modules/FindExtPackages.cmake | 2 +- share/cmake/modules/FindOpenEXR.cmake | 4 ++ share/cmake/modules/Findminizip-ng.cmake | 18 +++++++- share/cmake/modules/Findminizip.cmake | 18 +++++++- share/cmake/modules/Findzlib.cmake | 52 +++++++++++++++++------ src/cmake/Config.cmake.in | 47 ++++++++++++++++++++ 7 files changed, 139 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f5089e735a..6e3983ae7f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,6 +299,7 @@ set(OCIO_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets.cmake") set(OCIO_VERSION_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") set(OCIO_PROJECT_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake") set(OCIO_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") +set(OCIO_CUSTOM_FIND_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/cmake") # Version fetched from the top level project() write_basic_package_version_file( @@ -321,6 +322,18 @@ install( FILE ${OCIO_TARGETS_EXPORT_NAME} ) +# Install custom Find modules. +install(FILES + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findexpat.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/FindImath.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findpystring.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip-ng.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findzlib.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findyaml-cpp.cmake + DESTINATION ${OCIO_CUSTOM_FIND_MODULE_DIR} +) + install( FILES "${OCIO_PROJECT_CONFIG}" "${OCIO_VERSION_CONFIG}" DESTINATION "${OCIO_CONFIG_INSTALL_DIR}" diff --git a/share/cmake/modules/FindExtPackages.cmake b/share/cmake/modules/FindExtPackages.cmake index b777e5bb8f..7f34accd4c 100644 --- a/share/cmake/modules/FindExtPackages.cmake +++ b/share/cmake/modules/FindExtPackages.cmake @@ -44,7 +44,7 @@ find_package(Imath 3.0 REQUIRED) # ZLIB # https://github.com/madler/zlib set(_zlib_ExternalProject_VERSION "1.2.12") -find_package(zlib REQUIRED) +find_package(zlib 1.2.11 REQUIRED) # minizip-ng # https://github.com/zlib-ng/minizip-ng diff --git a/share/cmake/modules/FindOpenEXR.cmake b/share/cmake/modules/FindOpenEXR.cmake index 8c14635413..e32e50afde 100644 --- a/share/cmake/modules/FindOpenEXR.cmake +++ b/share/cmake/modules/FindOpenEXR.cmake @@ -45,6 +45,10 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) if(OpenEXR_FOUND) get_target_property(OpenEXR_LIBRARY OpenEXR::OpenEXR LOCATION) get_target_property(OpenEXR_INCLUDE_DIR OpenEXR::OpenEXR INTERFACE_INCLUDE_DIRECTORIES) + + # IMPORTED_GLOBAL property must be set to TRUE since alisasing a non-global imported target + # is not possible until CMake 3.18+. + set_target_properties(OpenEXR::OpenEXR PROPERTIES IMPORTED_GLOBAL TRUE) endif() # Override REQUIRED if package can be installed diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index b0136abc5f..6f8f0e1424 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -138,7 +138,23 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) ) # Get version from header or pkg-config - set(minizip-ng_VERSION "${minizip-ng_FIND_VERSION}") + if(minizip-ng_INCLUDE_DIR) + list(GET minizip-ng_INCLUDE_DIR 0 _minizip-ng_INCLUDE_DIR) + if(EXISTS "${_minizip-ng_INCLUDE_DIR}/mz.h") + set(_minizip-ng_CONFIG "${_minizip-ng_INCLUDE_DIR}/mz.h") + endif() + endif() + + if(_minizip-ng_CONFIG) + file(STRINGS "${_minizip-ng_CONFIG}" _minizip-ng_VER_SEARCH + REGEX "^[ \t]*#define[ \t]+MZ_VERSION[ \t]+\\(\"[.0-9]+\"\\).*$") + if(_minizip-ng_VER_SEARCH) + string(REGEX REPLACE ".*#define[ \t]+MZ_VERSION[ \t]+\\(\"([.0-9]+)\"\\).*" + "\\1" minizip-ng_VERSION "${_minizip-ng_VER_SEARCH}") + endif() + elseif(PC_minizip-ng_FOUND) + set(minizip-ng_VERSION "${PC_minizip-ng_VERSION}") + endif() endif() # Override REQUIRED if package can be installed diff --git a/share/cmake/modules/Findminizip.cmake b/share/cmake/modules/Findminizip.cmake index 1a75747177..4142f3c359 100644 --- a/share/cmake/modules/Findminizip.cmake +++ b/share/cmake/modules/Findminizip.cmake @@ -123,7 +123,23 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) ) # Get version from header or pkg-config - set(minizip_VERSION "${minizip_FIND_VERSION}") + if(minizip_INCLUDE_DIR) + list(GET minizip_INCLUDE_DIR 0 _minizip_INCLUDE_DIR) + if(EXISTS "${_minizip_INCLUDE_DIR}/mz.h") + set(_minizip_CONFIG "${_minizip_INCLUDE_DIR}/mz.h") + endif() + endif() + + if(_minizip_CONFIG) + file(STRINGS "${_minizip_CONFIG}" _minizip_VER_SEARCH + REGEX "^[ \t]*#define[ \t]+MZ_VERSION[ \t]+\\(\"[.0-9]+\"\\).*$") + if(_minizip_VER_SEARCH) + string(REGEX REPLACE ".*#define[ \t]+MZ_VERSION[ \t]+\\(\"([.0-9]+)\"\\).*" + "\\1" minizip_VERSION "${_minizip_VER_SEARCH}") + endif() + elseif(PC_minizip_FOUND) + set(minizip_VERSION "${PC_minizip_VERSION}") + endif() endif() # Override REQUIRED if package can be installed diff --git a/share/cmake/modules/Findzlib.cmake b/share/cmake/modules/Findzlib.cmake index 546cea341a..3346ae543c 100644 --- a/share/cmake/modules/Findzlib.cmake +++ b/share/cmake/modules/Findzlib.cmake @@ -1,7 +1,13 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install minizip-ng +# Locate or install zlib +# +# ********************************************************************** +# Note that this is a wrapper around the CMake ZLIB find module. +# This find module DOES NOT output any variables with lowercase "zlib". +# Treat this module as if it was FindZLIB.cmake. +# ********************************************************************** # # Variables defined by this module: # ZLIB_FOUND - If FALSE, do not try to link to minizip-ng @@ -12,16 +18,9 @@ # Targets defined by this module: # ZLIB::ZLIB - IMPORTED target, if found # -# This module is named GetZLIB because it is not used with find_package(). -# It must be included using include(). -# -# The reason is that CMake provide a FindZLIB already and the current file is -# using it. -# ############################################################################### ### Try to find package ### -# Assign the rigtt name for ZLIB depending on the OS. if(WIN32) set(_ZLIB_LIB_NAME "zlib") set(_ZLIB_STATIC_LIB_NAME "zlibstatic") @@ -31,7 +30,7 @@ else() endif() if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) - set(_ZLIB_REQUIRED_VARS ZLIB_LIBRARIES) + set(_ZLIB_REQUIRED_VARS ZLIB_LIBRARIES ZLIB_INCLUDE_DIRS) if(NOT DEFINED ZLIB_ROOT) # Save old value of CMAKE_MODULE_PATH @@ -40,11 +39,40 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules") # Use CMake FindZLIB module - find_package(ZLIB ${zlib_FIND_VERSION}) + find_package(ZLIB ${zlib_FIND_VERSION} QUIET) # Restore CMAKE_MODULE_PATH set(CMAKE_MODULE_PATH ${_ZLIB__CMAKE_MODULE_PATH_OLD_}) endif() + + if (ZLIB_FOUND) + # CMake find modules sets ZLIB_LIBRARIES and ZLIB_INCLUDE_DIRS. + + if(ZLIB_LIBRARIES) + # Set ZLIB_LIBRARY to match the other custom find modules that OCIO has. + set(ZLIB_LIBRARY ${ZLIB_LIBRARIES}) + endif() + + if(ZLIB_INCLUDE_DIRS) + # Set ZLIB_INCLUDE_DIR to match the other custom find modules that OCIO has. + set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIRS}) + endif() + + set(ZLIB_VERSION ${zlib_FIND_VERSION}) + endif() + + # Override REQUIRED if package can be installed + if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) + set(ZLIB_FIND_REQUIRED FALSE) + endif() + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(zlib + REQUIRED_VARS + ${_ZLIB_REQUIRED_VARS} + VERSION_VAR + ZLIB_VERSION + ) endif() ############################################################################### @@ -65,8 +93,8 @@ if(NOT ZLIB_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) # Set find_package standard args set(ZLIB_FOUND TRUE) - if(_zlib_ExternalProject_VERSION) - set(ZLIB_VERSION ${_zlib_ExternalProject_VERSION}) + if(_ZLIB_ExternalProject_VERSION) + set(ZLIB_VERSION ${_ZLIB_ExternalProject_VERSION}) else() set(ZLIB_VERSION ${zlib_FIND_VERSION}) endif() diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index feabdeb2e3..18586333d6 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -2,6 +2,53 @@ include(CMakeFindDependencyMacro) +# Get the install directory. +set(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}") +# Get the install directory. Since the current file is under +# /lib/cmake/OpenColorIO going back three directory. +foreach(i RANGE 1 3) + get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) + if(_IMPORT_PREFIX STREQUAL "/") + set(_IMPORT_PREFIX "") + break() + endif() +endforeach() + +# Append OCIO custom find module path. +list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/cmake") + +######################## +# Required dependencies +######################## + +if (NOT expat::expat) + find_dependency(expat @expat_VERSION@) +endif() + +if (NOT Imath::Imath) + find_dependency(Imath @Imath_VERSION@) +endif() + +if (NOT pystring::pystring) + find_dependency(pystring @pystring_VERSION@) +endif() + +if (NOT yaml-cpp) + find_dependency(yaml-cpp @yaml-cpp_VERSION@) +endif() + +# CMake has a zlib find module, but OCIO is using its own find module for zlib. (Findzlib.cmake) +if (NOT ZLIB::ZLIB) + find_dependency(zlib @ZLIB_VERSION@) +endif() + +if (NOT MINIZIP::minizip-ng) + find_dependency(minizip-ng @minizip-ng_VERSION@) +endif() + +# Remove OCIO custom find module path. +list(REMOVE_AT CMAKE_MODULE_PATH -1) + include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake) include(FindPackageHandleStandardArgs) From 21560feb2d650e5362042ea3f5a05603cca25036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 29 Nov 2022 13:12:25 -0500 Subject: [PATCH 07/23] Adding a informative message when building static ocio instead of per module. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- CMakeLists.txt | 9 +++++++++ share/cmake/modules/Findpystring.cmake | 8 -------- share/cmake/modules/Findyaml-cpp.cmake | 8 -------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e3983ae7f..1187576392 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,6 +251,15 @@ if(OCIO_BUILD_STATIC) endif() endif() +if (BUILD_SHARED_LIBS AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + message(STATUS "Note that building the static version of OpenColorIO does not embed the dependencies\ + into the library file. The needed dependencies must be linked to the consumer + application or shared library that uses static OpenColorIO. + + The following mandatory dependencies MUST be linked to the consumer application or shared library: + Expat, yaml-cpp, Imath, pystring, minizip-ng and ZLIB") +endif() + ############################################################################### # Find or install external dependencies diff --git a/share/cmake/modules/Findpystring.cmake b/share/cmake/modules/Findpystring.cmake index 702ac1e812..ca9ce832f6 100644 --- a/share/cmake/modules/Findpystring.cmake +++ b/share/cmake/modules/Findpystring.cmake @@ -127,14 +127,6 @@ if(NOT pystring_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) -DANDROID_STL=${ANDROID_STL}) endif() - if(NOT BUILD_SHARED_LIBS) - #TODO: Find a way to merge in the static libs when built with internal pystring - message(WARNING - "Building STATIC libOpenColorIO using the in-built pystring. " - "pystring symbols are NOT included in the output binary!" - ) - endif() - # Hack to let imported target be built from ExternalProject_Add file(MAKE_DIRECTORY ${pystring_INCLUDE_DIR}) diff --git a/share/cmake/modules/Findyaml-cpp.cmake b/share/cmake/modules/Findyaml-cpp.cmake index 023e14fc07..cc53df4f93 100644 --- a/share/cmake/modules/Findyaml-cpp.cmake +++ b/share/cmake/modules/Findyaml-cpp.cmake @@ -213,14 +213,6 @@ if(NOT yaml-cpp_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) -DANDROID_STL=${ANDROID_STL}) endif() - if(NOT BUILD_SHARED_LIBS) - #TODO: Find a way to merge in the static libs when built with internal yamlcpp - message(WARNING - "Building STATIC libOpenColorIO using the in-built yaml-cpp. " - "yaml-cpp symbols are NOT included in the output binary!" - ) - endif() - set(yaml-cpp_GIT_TAG "yaml-cpp-${yaml-cpp_VERSION}") # Hack to let imported target be built from ExternalProject_Add From 0d5692397c48460c3a65a40d3edb2add3b1512fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 29 Nov 2022 14:34:02 -0500 Subject: [PATCH 08/23] Adding an extra step to test the consumer app with static OpenColorIO for Windows, Linux and MacOS. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- .github/workflows/ci_workflow.yml | 36 ++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 890021741b..76f159cebd 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -291,7 +291,7 @@ jobs: - name: Test run: ctest -V -C ${{ matrix.build-type }} working-directory: _build - - name: Test CMake Consumer + - name: Test CMake Consumer with dynamic version of OpenColorIO if: matrix.build-shared == 'ON' run: | cmake . \ @@ -301,6 +301,16 @@ jobs: --config ${{ matrix.build-type }} ./consumer working-directory: _build/tests/cmake-consumer-dist + - name: Test CMake Consumer with static version of OpenColorIO + if: matrix.build-shared == 'OFF' + run: | + cmake . \ + -DCMAKE_PREFIX_PATH=../../../_install \ + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + cmake --build . \ + --config ${{ matrix.build-type }} + ./consumer + working-directory: _build/tests/cmake-consumer-dist # --------------------------------------------------------------------------- # macOS @@ -428,7 +438,7 @@ jobs: - name: Test run: ctest -V -C ${{ matrix.build-type }} working-directory: _build - - name: Test CMake Consumer + - name: Test CMake Consumer with dynamic version of OpenColorIO if: matrix.build-shared == 'ON' run: | cmake . \ @@ -438,6 +448,16 @@ jobs: --config ${{ matrix.build-type }} ./consumer working-directory: _build/tests/cmake-consumer-dist + - name: Test CMake Consumer with static version of OpenColorIO + if: matrix.build-shared == 'OFF' + run: | + cmake . \ + -DCMAKE_PREFIX_PATH=../../../_install \ + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + cmake --build . \ + --config ${{ matrix.build-type }} + ./consumer + working-directory: _build/tests/cmake-consumer-dist # --------------------------------------------------------------------------- # Windows @@ -573,7 +593,7 @@ jobs: run: ctest -V -C ${{ matrix.build-type }} shell: bash working-directory: _build - - name: Test CMake Consumer + - name: Test CMake Consumer with dynamic version of OpenColorIO if: matrix.build-shared == 'ON' run: | cmake . \ @@ -585,3 +605,13 @@ jobs: ./${{ matrix.build-type }}/consumer shell: bash working-directory: _build/tests/cmake-consumer-dist + - name: Test CMake Consumer with static version of OpenColorIO + if: matrix.build-shared == 'OFF' + run: | + cmake . \ + -DCMAKE_PREFIX_PATH=../../../_install \ + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + cmake --build . \ + --config ${{ matrix.build-type }} + ./consumer + working-directory: _build/tests/cmake-consumer-dist From 0a0044320dc39acc434548a63baec84c0557d1c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 1 Dec 2022 08:19:16 -0500 Subject: [PATCH 09/23] Re-using the same test instead of creating a new one by removing the condition on build-shared. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- .github/workflows/ci_workflow.yml | 42 +++++-------------------------- 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 76f159cebd..0683c57e35 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -291,18 +291,8 @@ jobs: - name: Test run: ctest -V -C ${{ matrix.build-type }} working-directory: _build - - name: Test CMake Consumer with dynamic version of OpenColorIO - if: matrix.build-shared == 'ON' - run: | - cmake . \ - -DCMAKE_PREFIX_PATH=../../../_install \ - -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - cmake --build . \ - --config ${{ matrix.build-type }} - ./consumer - working-directory: _build/tests/cmake-consumer-dist - - name: Test CMake Consumer with static version of OpenColorIO - if: matrix.build-shared == 'OFF' + # The test is valid for both build-shared=ON and build-shared=OFF. + - name: Test CMake Consumer run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ @@ -438,18 +428,8 @@ jobs: - name: Test run: ctest -V -C ${{ matrix.build-type }} working-directory: _build - - name: Test CMake Consumer with dynamic version of OpenColorIO - if: matrix.build-shared == 'ON' - run: | - cmake . \ - -DCMAKE_PREFIX_PATH=../../../_install \ - -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - cmake --build . \ - --config ${{ matrix.build-type }} - ./consumer - working-directory: _build/tests/cmake-consumer-dist - - name: Test CMake Consumer with static version of OpenColorIO - if: matrix.build-shared == 'OFF' + # The test is valid for both build-shared=ON and build-shared=OFF. + - name: Test CMake Consumer run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ @@ -593,8 +573,8 @@ jobs: run: ctest -V -C ${{ matrix.build-type }} shell: bash working-directory: _build - - name: Test CMake Consumer with dynamic version of OpenColorIO - if: matrix.build-shared == 'ON' + # The test is valid for both build-shared=ON and build-shared=OFF. + - name: Test CMake Consumer run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ @@ -605,13 +585,3 @@ jobs: ./${{ matrix.build-type }}/consumer shell: bash working-directory: _build/tests/cmake-consumer-dist - - name: Test CMake Consumer with static version of OpenColorIO - if: matrix.build-shared == 'OFF' - run: | - cmake . \ - -DCMAKE_PREFIX_PATH=../../../_install \ - -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - cmake --build . \ - --config ${{ matrix.build-type }} - ./consumer - working-directory: _build/tests/cmake-consumer-dist From cf7eaff30b7e0e1684e4a241600a1411f8bbfe30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 1 Dec 2022 15:07:17 -0500 Subject: [PATCH 10/23] Fixing spacing, typo and adding back the NOT in the condition. (it was removed for debugging purpose) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1187576392..b288f9e7e6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -251,13 +251,13 @@ if(OCIO_BUILD_STATIC) endif() endif() -if (BUILD_SHARED_LIBS AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) - message(STATUS "Note that building the static version of OpenColorIO does not embed the dependencies\ +if (NOT BUILD_SHARED_LIBS AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + message(STATUS "Note that building the static version of OpenColorIO does not embed the dependencies\ into the library file. The needed dependencies must be linked to the consumer application or shared library that uses static OpenColorIO. The following mandatory dependencies MUST be linked to the consumer application or shared library: - Expat, yaml-cpp, Imath, pystring, minizip-ng and ZLIB") + expat, yaml-cpp, Imath, pystring, minizip-ng and ZLIB") endif() From f9cb1d0d3813829120abd7ad4b52f368ae003114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 6 Dec 2022 15:29:15 -0500 Subject: [PATCH 11/23] Changing directory where we share OCIO custom find modules (now in /share/cmake/modules). Adding a cmake macro when installing OCIO since it is needed by some custom find modules. The find modules are only installed when building OCIO as a static library. The config.cmake.in files now only looks for the dependency when OCIO was built as a static library. Tentative (ci-workflow): Adding cmake-consumer test for static builds. Overhaul of the Findzlib module to be more inline with the FindZLIB from cmake and to be more robust. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- .github/workflows/ci_workflow.yml | 84 ++++++++++++++++++++++++-- CMakeLists.txt | 33 ++++++---- share/cmake/modules/Findzlib.cmake | 96 +++++++++++++++++++----------- src/cmake/Config.cmake.in | 79 ++++++++++++------------ 4 files changed, 200 insertions(+), 92 deletions(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 0683c57e35..9c17d368b4 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -291,8 +291,11 @@ jobs: - name: Test run: ctest -V -C ${{ matrix.build-type }} working-directory: _build - # The test is valid for both build-shared=ON and build-shared=OFF. - - name: Test CMake Consumer + - name: Store absolute build path + run: | + echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV + - name: Test CMake Consumer with shared OCIO + if: matrix.build-shared == 'ON' run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ @@ -301,6 +304,26 @@ jobs: --config ${{ matrix.build-type }} ./consumer working-directory: _build/tests/cmake-consumer-dist + - name: Test CMake Consumer with static OCIO + if: matrix.build-shared == 'OFF' + # yaml-cpp_VERSION need to be provided since there is no way to find the version in the + # header files. + # Pystring is different because Findpystring does not require pystring_VERSION to be present. + run: | + cmake . \ + -DCMAKE_PREFIX_PATH=../../../_install \ + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist + -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dyaml-cpp_VERSION=0.7.0 + -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist + cmake --build . \ + --config ${{ matrix.build-type }} + ./consumer + working-directory: _build/tests/cmake-consumer-dist # --------------------------------------------------------------------------- # macOS @@ -428,12 +451,35 @@ jobs: - name: Test run: ctest -V -C ${{ matrix.build-type }} working-directory: _build - # The test is valid for both build-shared=ON and build-shared=OFF. - - name: Test CMake Consumer + - name: Store absolute build path + run: | + echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV + - name: Test CMake Consumer with shared OCIO + if: matrix.build-shared == 'ON' + run: | + cmake . \ + -DCMAKE_PREFIX_PATH=../../../_install \ + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + cmake --build . \ + --config ${{ matrix.build-type }} + ./consumer + working-directory: _build/tests/cmake-consumer-dist + - name: Test CMake Consumer with static OCIO + if: matrix.build-shared == 'OFF' + # yaml-cpp_VERSION need to be provided since there is no way to find the version in the + # header files. + # Pystring is different because Findpystring does not require pystring_VERSION to be present. run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist + -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dyaml-cpp_VERSION=0.7.0 + -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist cmake --build . \ --config ${{ matrix.build-type }} ./consumer @@ -573,12 +619,38 @@ jobs: run: ctest -V -C ${{ matrix.build-type }} shell: bash working-directory: _build - # The test is valid for both build-shared=ON and build-shared=OFF. - - name: Test CMake Consumer + - name: Store absolute build path + run: | + echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV + shell: bash + - name: Test CMake Consumer with shared OCIO + if: matrix.build-shared == 'ON' + run: | + cmake . \ + -DCMAKE_PREFIX_PATH=../../../_install \ + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + cmake --build . \ + --config ${{ matrix.build-type }} + export PATH=../../../_install/bin:$PATH + ./${{ matrix.build-type }}/consumer + shell: bash + working-directory: _build/tests/cmake-consumer-dist + - name: Test CMake Consumer with static OCIO + if: matrix.build-shared == 'OFF' + # yaml-cpp_VERSION need to be provided since there is no way to find the version in the + # header files. + # Pystring is different because Findpystring does not require pystring_VERSION to be present. run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} + -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist + -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dyaml-cpp_VERSION=0.7.0 + -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist + -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist cmake --build . \ --config ${{ matrix.build-type }} export PATH=../../../_install/bin:$PATH diff --git a/CMakeLists.txt b/CMakeLists.txt index f63b84916c..f735112f03 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,7 +308,8 @@ set(OCIO_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets.cmake") set(OCIO_VERSION_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") set(OCIO_PROJECT_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake") set(OCIO_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") -set(OCIO_CUSTOM_FIND_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/cmake") +set(OCIO_CUSTOM_FIND_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/share/cmake/modules") +set(OCIO_CUSTOM_MACROS_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/share/cmake/macros") # Version fetched from the top level project() write_basic_package_version_file( @@ -331,17 +332,25 @@ install( FILE ${OCIO_TARGETS_EXPORT_NAME} ) -# Install custom Find modules. -install(FILES - ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findexpat.cmake - ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/FindImath.cmake - ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findpystring.cmake - ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip.cmake - ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip-ng.cmake - ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findzlib.cmake - ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findyaml-cpp.cmake - DESTINATION ${OCIO_CUSTOM_FIND_MODULE_DIR} -) +if (NOT BUILD_SHARED_LIBS) + # Install custom macros used in the find modules. + install(FILES + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/macros/VersionUtils.cmake + DESTINATION ${OCIO_CUSTOM_MACROS_MODULE_DIR} + ) + + # Install custom Find modules. + install(FILES + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findexpat.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/FindImath.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findpystring.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip-ng.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findzlib.cmake + ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findyaml-cpp.cmake + DESTINATION ${OCIO_CUSTOM_FIND_MODULE_DIR} + ) +endif() install( FILES "${OCIO_PROJECT_CONFIG}" "${OCIO_VERSION_CONFIG}" diff --git a/share/cmake/modules/Findzlib.cmake b/share/cmake/modules/Findzlib.cmake index 3346ae543c..83524bfb35 100644 --- a/share/cmake/modules/Findzlib.cmake +++ b/share/cmake/modules/Findzlib.cmake @@ -6,11 +6,12 @@ # ********************************************************************** # Note that this is a wrapper around the CMake ZLIB find module. # This find module DOES NOT output any variables with lowercase "zlib". -# Treat this module as if it was FindZLIB.cmake. +# +# Treat this module as if it was FindZLIB.cmake. # ********************************************************************** # # Variables defined by this module: -# ZLIB_FOUND - If FALSE, do not try to link to minizip-ng +# ZLIB_FOUND - If FALSE, do not try to link to zlib # ZLIB_LIBRARIES - ZLIB library to link to # ZLIB_INCLUDE_DIRS - Where to find zlib.h and other headers # ZLIB_VERSION - The version of the library @@ -21,55 +22,73 @@ ############################################################################### ### Try to find package ### -if(WIN32) - set(_ZLIB_LIB_NAME "zlib") - set(_ZLIB_STATIC_LIB_NAME "zlibstatic") -else() - set(_ZLIB_LIB_NAME "z") - set(_ZLIB_STATIC_LIB_NAME "z") -endif() - if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) - set(_ZLIB_REQUIRED_VARS ZLIB_LIBRARIES ZLIB_INCLUDE_DIRS) + # Update ZLIB_ROOT if zlib_ROOT was set. + if (zlib_ROOT) + set(ZLIB_ROOT "${zlib_ROOT}") + endif() - if(NOT DEFINED ZLIB_ROOT) - # Save old value of CMAKE_MODULE_PATH - set(_ZLIB__CMAKE_MODULE_PATH_OLD_ ${CMAKE_MODULE_PATH}) - # Force find_package to use CMAKE module and not custom modules. - set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules") + # Update ZLIB_LIBRARY if zlib_LIBRARY was set. + if (zlib_LIBRARY) + set(ZLIB_LIBRARY "${zlib_LIBRARY}") + endif() - # Use CMake FindZLIB module - find_package(ZLIB ${zlib_FIND_VERSION} QUIET) + # Update ZLIB_INCLUDE_DIR if zlib_INCLUDE_DIR was set. + if (zlib_INCLUDE_DIR) + set(ZLIB_INCLUDE_DIR "${zlib_INCLUDE_DIR}") + endif() - # Restore CMAKE_MODULE_PATH - set(CMAKE_MODULE_PATH ${_ZLIB__CMAKE_MODULE_PATH_OLD_}) + # ZLIB_USE_STATIC_LIBS is supported only from CMake 3.24+. + if (ZLIB_STATIC_LIBRARY) + set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}") + elseif(zlib_STATIC_LIBRARY) + set(ZLIB_USE_STATIC_LIBS "${zlib_STATIC_LIBRARY}") endif() + # Forcing CMake to use its own find module called FindZLIB.cmake. + # Save old value of CMAKE_MODULE_PATH + set(_ZLIB__CMAKE_MODULE_PATH_OLD_ ${CMAKE_MODULE_PATH}) + # Force find_package to use CMAKE module and not custom modules. + set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules") + + # Use CMake FindZLIB module. (ZLIB in capital letters is important) + # FindZLIB supports ZLIB_ROOT, ZLIB_LIBRARIES and ZLIB_INCLUDE_DIRS. + find_package(ZLIB ${zlib_FIND_VERSION} QUIET) + + # Restore CMAKE_MODULE_PATH + set(CMAKE_MODULE_PATH ${_ZLIB__CMAKE_MODULE_PATH_OLD_}) + if (ZLIB_FOUND) # CMake find modules sets ZLIB_LIBRARIES and ZLIB_INCLUDE_DIRS. - - if(ZLIB_LIBRARIES) - # Set ZLIB_LIBRARY to match the other custom find modules that OCIO has. - set(ZLIB_LIBRARY ${ZLIB_LIBRARIES}) + + if(ZLIB_LIBRARIES AND NOT ZLIB_LIBRARY) + # Set ZLIB_LIBRARY to match the others OCIO's custom find modules. + set(ZLIB_LIBRARY "${ZLIB_LIBRARIES}") endif() - if(ZLIB_INCLUDE_DIRS) - # Set ZLIB_INCLUDE_DIR to match the other custom find modules that OCIO has. - set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIRS}) + if(ZLIB_INCLUDE_DIRS AND NOT ZLIB_INCLUDE_DIR) + # Set ZLIB_LIBRARY to match the others OCIO's custom find modules. + set(ZLIB_INCLUDE_DIR "${ZLIB_INCLUDE_DIRS}") + endif() + + # CMake FindZLIB uses ZLIB_VERSION_STRING for CMake < 3.26. + # CMake 3.26 will update that variable to ZLIB_VERSION. + if (ZLIB_VERSION_STRING) + set(ZLIB_VERSION "${ZLIB_VERSION_STRING}") endif() - - set(ZLIB_VERSION ${zlib_FIND_VERSION}) endif() # Override REQUIRED if package can be installed if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) + set(zlib_FIND_REQUIRED FALSE) set(ZLIB_FIND_REQUIRED FALSE) endif() include(FindPackageHandleStandardArgs) find_package_handle_standard_args(zlib REQUIRED_VARS - ${_ZLIB_REQUIRED_VARS} + ZLIB_LIBRARY + ZLIB_INCLUDE_DIR VERSION_VAR ZLIB_VERSION ) @@ -79,6 +98,7 @@ endif() ### Create target if(NOT TARGET ZLIB::ZLIB) + add_library(ZLIB::ZLIB UNKNOWN IMPORTED GLOBAL) set(_ZLIB_TARGET_CREATE TRUE) endif() @@ -91,6 +111,14 @@ if(NOT ZLIB_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") + if(WIN32) + set(_ZLIB_LIB_NAME "zlib") + set(_ZLIB_STATIC_LIB_NAME "zlibstatic") + else() + set(_ZLIB_LIB_NAME "z") + set(_ZLIB_STATIC_LIB_NAME "z") + endif() + # Set find_package standard args set(ZLIB_FOUND TRUE) if(_ZLIB_ExternalProject_VERSION) @@ -177,13 +205,9 @@ if(NOT ZLIB_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) COMMAND ${CMAKE_COMMAND} -E remove -f ${_EXT_DIST_ROOT}/${_ZLIB_INSTALL_LIBDIR}/zlib.lib ${_EXT_DIST_ROOT}/bin/zlib.dll ) - add_library(ZLIB::ZLIB STATIC IMPORTED GLOBAL) add_dependencies(ZLIB::ZLIB ZLIB_install) - set_property(TARGET ZLIB::ZLIB PROPERTY - IMPORTED_LOCATION "${ZLIB_LIBRARIES}" - ) - target_include_directories(ZLIB::ZLIB INTERFACE "${CMAKE_INSTALL_BINDIR}/include") - + + # Setting those variables to follow the same naming as the other OCIO custom find modules. set(ZLIB_LIBRARY ${ZLIB_LIBRARIES}) set(ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIRS}) diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index 18586333d6..0e82aa12d7 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -2,53 +2,56 @@ include(CMakeFindDependencyMacro) -# Get the install directory. -set(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}") -# Get the install directory. Since the current file is under -# /lib/cmake/OpenColorIO going back three directory. -foreach(i RANGE 1 3) - get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) - if(_IMPORT_PREFIX STREQUAL "/") - set(_IMPORT_PREFIX "") - break() +if (NOT @BUILD_SHARED_LIBS@) + # Get the install directory. + set(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}") + # Get the install directory. Since the current file is under + # /lib/cmake/OpenColorIO going back three directory. + foreach(i RANGE 1 3) + get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) + if(_IMPORT_PREFIX STREQUAL "/") + set(_IMPORT_PREFIX "") + break() + endif() + endforeach() + + # Append OCIO custom find module path. + list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/cmake/modules") + list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/cmake/macros") + + ######################## + # Required dependencies + ######################## + + if (NOT expat::expat) + find_dependency(expat @expat_VERSION@) endif() -endforeach() -# Append OCIO custom find module path. -list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/cmake") - -######################## -# Required dependencies -######################## - -if (NOT expat::expat) - find_dependency(expat @expat_VERSION@) -endif() + if (NOT Imath::Imath) + find_dependency(Imath @Imath_VERSION@) + endif() -if (NOT Imath::Imath) - find_dependency(Imath @Imath_VERSION@) -endif() + if (NOT pystring::pystring) + find_dependency(pystring @pystring_VERSION@) + endif() -if (NOT pystring::pystring) - find_dependency(pystring @pystring_VERSION@) -endif() + if (NOT yaml-cpp) + find_dependency(yaml-cpp @yaml-cpp_VERSION@) + endif() -if (NOT yaml-cpp) - find_dependency(yaml-cpp @yaml-cpp_VERSION@) -endif() + # CMake has a zlib find module, but OCIO is using its own find module for zlib. (Findzlib.cmake) + if (NOT ZLIB::ZLIB) + find_dependency(zlib @ZLIB_VERSION@) + endif() -# CMake has a zlib find module, but OCIO is using its own find module for zlib. (Findzlib.cmake) -if (NOT ZLIB::ZLIB) - find_dependency(zlib @ZLIB_VERSION@) -endif() + if (NOT MINIZIP::minizip-ng) + find_dependency(minizip-ng @minizip-ng_VERSION@) + endif() -if (NOT MINIZIP::minizip-ng) - find_dependency(minizip-ng @minizip-ng_VERSION@) + # Remove OCIO custom find module path. + list(REMOVE_AT CMAKE_MODULE_PATH -1) endif() -# Remove OCIO custom find module path. -list(REMOVE_AT CMAKE_MODULE_PATH -1) - include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake) include(FindPackageHandleStandardArgs) From df34c3b53d770fd9deb769428526ba40db4ab9a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Wed, 7 Dec 2022 09:20:27 -0500 Subject: [PATCH 12/23] Adding missing backward slashes and saving the build path in an existing step instead of creating a new step. Adding a check for CMake version for a section in Findzlib.cmake. Re-phrasing some comments. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- .github/workflows/ci_workflow.yml | 69 +++++++++++++----------------- share/cmake/modules/Findzlib.cmake | 23 +++++----- 2 files changed, 43 insertions(+), 49 deletions(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 9c17d368b4..cc6f53f093 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -287,13 +287,11 @@ jobs: --target install \ --config ${{ matrix.build-type }} \ -- -j$(nproc) + echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV working-directory: _build - name: Test run: ctest -V -C ${{ matrix.build-type }} working-directory: _build - - name: Store absolute build path - run: | - echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV - name: Test CMake Consumer with shared OCIO if: matrix.build-shared == 'ON' run: | @@ -306,19 +304,18 @@ jobs: working-directory: _build/tests/cmake-consumer-dist - name: Test CMake Consumer with static OCIO if: matrix.build-shared == 'OFF' - # yaml-cpp_VERSION need to be provided since there is no way to find the version in the - # header files. - # Pystring is different because Findpystring does not require pystring_VERSION to be present. + # The yaml-cpp_VERSION is set below because Findyaml-cpp.cmake needs it but is unable to + # extract it from the headers, like the other modules. run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ - -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist - -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist - -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist - -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist - -Dyaml-cpp_VERSION=0.7.0 - -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ + -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dyaml-cpp_VERSION=0.7.0 \ + -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \ -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist cmake --build . \ --config ${{ matrix.build-type }} @@ -447,13 +444,11 @@ jobs: --target install \ --config ${{ matrix.build-type }} \ -- -j$(sysctl -n hw.ncpu) + echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV working-directory: _build - name: Test run: ctest -V -C ${{ matrix.build-type }} working-directory: _build - - name: Store absolute build path - run: | - echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV - name: Test CMake Consumer with shared OCIO if: matrix.build-shared == 'ON' run: | @@ -466,19 +461,18 @@ jobs: working-directory: _build/tests/cmake-consumer-dist - name: Test CMake Consumer with static OCIO if: matrix.build-shared == 'OFF' - # yaml-cpp_VERSION need to be provided since there is no way to find the version in the - # header files. - # Pystring is different because Findpystring does not require pystring_VERSION to be present. + # The yaml-cpp_VERSION is set below because Findyaml-cpp.cmake needs it but is unable to + # extract it from the headers, like the other modules. run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ - -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist - -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist - -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist - -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist - -Dyaml-cpp_VERSION=0.7.0 - -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ + -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dyaml-cpp_VERSION=0.7.0 \ + -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \ -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist cmake --build . \ --config ${{ matrix.build-type }} @@ -613,15 +607,13 @@ jobs: cmake --build . \ --target install \ --config ${{ matrix.build-type }} + echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV shell: bash working-directory: _build - name: Test run: ctest -V -C ${{ matrix.build-type }} shell: bash working-directory: _build - - name: Store absolute build path - run: | - echo "ocio_build_path=$(pwd)" >> $GITHUB_ENV shell: bash - name: Test CMake Consumer with shared OCIO if: matrix.build-shared == 'ON' @@ -637,19 +629,18 @@ jobs: working-directory: _build/tests/cmake-consumer-dist - name: Test CMake Consumer with static OCIO if: matrix.build-shared == 'OFF' - # yaml-cpp_VERSION need to be provided since there is no way to find the version in the - # header files. - # Pystring is different because Findpystring does not require pystring_VERSION to be present. + # The yaml-cpp_VERSION is set below because Findyaml-cpp.cmake needs it but is unable to + # extract it from the headers, like the other modules. run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ - -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} - -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist - -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist - -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist - -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist - -Dyaml-cpp_VERSION=0.7.0 - -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist + -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ + -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dyaml-cpp_VERSION=0.7.0 \ + -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \ -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist cmake --build . \ --config ${{ matrix.build-type }} diff --git a/share/cmake/modules/Findzlib.cmake b/share/cmake/modules/Findzlib.cmake index 83524bfb35..17919d5b69 100644 --- a/share/cmake/modules/Findzlib.cmake +++ b/share/cmake/modules/Findzlib.cmake @@ -1,7 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install zlib +# Locate or install ZLIB # # ********************************************************************** # Note that this is a wrapper around the CMake ZLIB find module. @@ -39,10 +39,12 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) endif() # ZLIB_USE_STATIC_LIBS is supported only from CMake 3.24+. - if (ZLIB_STATIC_LIBRARY) - set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}") - elseif(zlib_STATIC_LIBRARY) - set(ZLIB_USE_STATIC_LIBS "${zlib_STATIC_LIBRARY}") + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0") + if (ZLIB_STATIC_LIBRARY) + set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}") + elseif(zlib_STATIC_LIBRARY) + set(ZLIB_USE_STATIC_LIBS "${zlib_STATIC_LIBRARY}") + endif() endif() # Forcing CMake to use its own find module called FindZLIB.cmake. @@ -59,20 +61,21 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) set(CMAKE_MODULE_PATH ${_ZLIB__CMAKE_MODULE_PATH_OLD_}) if (ZLIB_FOUND) - # CMake find modules sets ZLIB_LIBRARIES and ZLIB_INCLUDE_DIRS. - + # Right now, OCIO custom find modules uses the following standard: + # _LIBRARY and _INCLUDE_DIR + # But CMake's FindZLIB sets ZLIB_LIBRARIES and ZLIB_INCLUDE_DIRS. + + # Set ZLIB_LIBRARY if it is not set already. if(ZLIB_LIBRARIES AND NOT ZLIB_LIBRARY) - # Set ZLIB_LIBRARY to match the others OCIO's custom find modules. set(ZLIB_LIBRARY "${ZLIB_LIBRARIES}") endif() + # Set ZLIB_INCLUDE_DIR if it is not set already. if(ZLIB_INCLUDE_DIRS AND NOT ZLIB_INCLUDE_DIR) - # Set ZLIB_LIBRARY to match the others OCIO's custom find modules. set(ZLIB_INCLUDE_DIR "${ZLIB_INCLUDE_DIRS}") endif() # CMake FindZLIB uses ZLIB_VERSION_STRING for CMake < 3.26. - # CMake 3.26 will update that variable to ZLIB_VERSION. if (ZLIB_VERSION_STRING) set(ZLIB_VERSION "${ZLIB_VERSION_STRING}") endif() From 009c8f241eabcf14690cec35c4819ab2979b4c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Wed, 7 Dec 2022 13:06:46 -0500 Subject: [PATCH 13/23] Prevent the download of the dependencies in the scenario where static OCIO is linked to a consumer project. Since OCIO_INSTALL_EXT_PACKAGES is not defined, our find module tries to download the dependencies, but we don't want that mecanism for consumer project. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- share/cmake/modules/FindImath.cmake | 2 +- share/cmake/modules/FindOpenEXR.cmake | 2 +- share/cmake/modules/Findexpat.cmake | 2 +- share/cmake/modules/Findlcms2.cmake | 2 +- share/cmake/modules/Findminizip-ng.cmake | 2 +- share/cmake/modules/Findopenfx.cmake | 2 +- share/cmake/modules/Findpybind11.cmake | 2 +- share/cmake/modules/Findpystring.cmake | 2 +- share/cmake/modules/Findyaml-cpp.cmake | 2 +- share/cmake/modules/Findzlib.cmake | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/share/cmake/modules/FindImath.cmake b/share/cmake/modules/FindImath.cmake index 1510bbdf70..d3641b1487 100644 --- a/share/cmake/modules/FindImath.cmake +++ b/share/cmake/modules/FindImath.cmake @@ -131,7 +131,7 @@ endif() ############################################################################### ### Install package from source ### -if(NOT Imath_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) +if(NOT Imath_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) include(GNUInstallDirs) diff --git a/share/cmake/modules/FindOpenEXR.cmake b/share/cmake/modules/FindOpenEXR.cmake index e32e50afde..476d82f23d 100644 --- a/share/cmake/modules/FindOpenEXR.cmake +++ b/share/cmake/modules/FindOpenEXR.cmake @@ -81,7 +81,7 @@ macro(set_target_location target_name) endif() endmacro() -if(NOT OpenEXR_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) +if(NOT OpenEXR_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) include(GNUInstallDirs) diff --git a/share/cmake/modules/Findexpat.cmake b/share/cmake/modules/Findexpat.cmake index 59e5c2e102..57757dba38 100644 --- a/share/cmake/modules/Findexpat.cmake +++ b/share/cmake/modules/Findexpat.cmake @@ -162,7 +162,7 @@ endif() ############################################################################### ### Install package from source ### -if(NOT expat_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) +if(NOT expat_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) include(GNUInstallDirs) diff --git a/share/cmake/modules/Findlcms2.cmake b/share/cmake/modules/Findlcms2.cmake index b7049ce4f4..f35fcf14f4 100644 --- a/share/cmake/modules/Findlcms2.cmake +++ b/share/cmake/modules/Findlcms2.cmake @@ -97,7 +97,7 @@ endif() ############################################################################### ### Install package from source ### -if(NOT lcms2_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) +if(NOT lcms2_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index 6f8f0e1424..ec4d4b0d78 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -189,7 +189,7 @@ if(NOT minizip_FOUND AND NOT TARGET MINIZIP::minizip) ############################################################################### ### Install package from source ### - if(NOT minizip-ng_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + if(NOT minizip-ng_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) include(GNUInstallDirs) diff --git a/share/cmake/modules/Findopenfx.cmake b/share/cmake/modules/Findopenfx.cmake index f989e0f7ae..8b0eefb344 100644 --- a/share/cmake/modules/Findopenfx.cmake +++ b/share/cmake/modules/Findopenfx.cmake @@ -58,7 +58,7 @@ endif() ############################################################################### ### Install package from source ### -if(NOT openfx_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) +if(NOT openfx_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) include(GNUInstallDirs) diff --git a/share/cmake/modules/Findpybind11.cmake b/share/cmake/modules/Findpybind11.cmake index 316496096c..e6c2f35a86 100644 --- a/share/cmake/modules/Findpybind11.cmake +++ b/share/cmake/modules/Findpybind11.cmake @@ -134,7 +134,7 @@ endif() ############################################################################### ### Install package from source ### -if(NOT pybind11_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) +if(NOT pybind11_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) include(GNUInstallDirs) diff --git a/share/cmake/modules/Findpystring.cmake b/share/cmake/modules/Findpystring.cmake index ca9ce832f6..bbd5e1fd27 100644 --- a/share/cmake/modules/Findpystring.cmake +++ b/share/cmake/modules/Findpystring.cmake @@ -66,7 +66,7 @@ endif() ############################################################################### ### Install package from source ### -if(NOT pystring_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) +if(NOT pystring_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) set(_EXT_DIST_ROOT "${CMAKE_BINARY_DIR}/ext/dist") diff --git a/share/cmake/modules/Findyaml-cpp.cmake b/share/cmake/modules/Findyaml-cpp.cmake index cc53df4f93..37239900ee 100644 --- a/share/cmake/modules/Findyaml-cpp.cmake +++ b/share/cmake/modules/Findyaml-cpp.cmake @@ -130,7 +130,7 @@ endif() ############################################################################### ### Install package from source ### -if(NOT yaml-cpp_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) +if(NOT yaml-cpp_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) include(GNUInstallDirs) diff --git a/share/cmake/modules/Findzlib.cmake b/share/cmake/modules/Findzlib.cmake index 17919d5b69..6a12a4610f 100644 --- a/share/cmake/modules/Findzlib.cmake +++ b/share/cmake/modules/Findzlib.cmake @@ -107,7 +107,7 @@ endif() ############################################################################### ### Install package from source ### -if(NOT ZLIB_FOUND AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) +if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) include(GNUInstallDirs) From 76fd877ef9b06596d209ecca712f2424868725ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 8 Dec 2022 13:51:21 -0500 Subject: [PATCH 14/23] Changing path where OCIO install its own custom find module. Removing custom Findzlib and making modifications to use CMake FindZLIB. Created a InstallZLIB module which does the download and install part if OCIO_INSTALL_EXT_PACAKGES is ALL or MISSING. Tweaked config.cmake.in to use CMake FindZLIB. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- CMakeLists.txt | 5 +- share/cmake/modules/FindExtPackages.cmake | 31 +++++- share/cmake/modules/FindOpenEXR.cmake | 11 +- .../{Findzlib.cmake => InstallZLIB.cmake} | 100 ++---------------- src/cmake/Config.cmake.in | 14 ++- 5 files changed, 56 insertions(+), 105 deletions(-) rename share/cmake/modules/{Findzlib.cmake => InstallZLIB.cmake} (62%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f735112f03..f6e15bba61 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -308,8 +308,8 @@ set(OCIO_TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets.cmake") set(OCIO_VERSION_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake") set(OCIO_PROJECT_CONFIG "${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake") set(OCIO_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") -set(OCIO_CUSTOM_FIND_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/share/cmake/modules") -set(OCIO_CUSTOM_MACROS_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/share/cmake/macros") +set(OCIO_CUSTOM_FIND_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/share/OpenColorIO/cmake/modules") +set(OCIO_CUSTOM_MACROS_MODULE_DIR "${CMAKE_INSTALL_PREFIX}/share/OpenColorIO/cmake/macros") # Version fetched from the top level project() write_basic_package_version_file( @@ -346,7 +346,6 @@ if (NOT BUILD_SHARED_LIBS) ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findpystring.cmake ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip.cmake ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip-ng.cmake - ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findzlib.cmake ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findyaml-cpp.cmake DESTINATION ${OCIO_CUSTOM_FIND_MODULE_DIR} ) diff --git a/share/cmake/modules/FindExtPackages.cmake b/share/cmake/modules/FindExtPackages.cmake index 7f34accd4c..f54dee394d 100644 --- a/share/cmake/modules/FindExtPackages.cmake +++ b/share/cmake/modules/FindExtPackages.cmake @@ -41,10 +41,33 @@ find_package(pystring 1.1.3 REQUIRED) set(_Imath_ExternalProject_VERSION "3.1.5") find_package(Imath 3.0 REQUIRED) -# ZLIB -# https://github.com/madler/zlib -set(_zlib_ExternalProject_VERSION "1.2.12") -find_package(zlib 1.2.11 REQUIRED) +############################################################################### +### ZLIB (https://github.com/madler/zlib) +############################################################################### +set(_ZLIB_FIND_VERSION "1.2.11") +set(_ZLIB_ExternalProject_VERSION ${_ZLIB_FIND_VERSION}) + +if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) + # ZLIB_USE_STATIC_LIBS is supported only from CMake 3.24+. + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0") + if (ZLIB_STATIC_LIBRARY) + set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}") + endif() + endif() + + set(_ZLIB_REQUIRED REQUIRED) + # Override REQUIRED if package can be installed + if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) + set(_ZLIB_REQUIRED "") + endif() + + find_package(ZLIB ${_ZLIB_FIND_VERSION} ${_ZLIB_REQUIRED}) +endif() + +if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) + include(InstallZLIB) +endif() +############################################################################### # minizip-ng # https://github.com/zlib-ng/minizip-ng diff --git a/share/cmake/modules/FindOpenEXR.cmake b/share/cmake/modules/FindOpenEXR.cmake index 476d82f23d..a8b8448fd6 100644 --- a/share/cmake/modules/FindOpenEXR.cmake +++ b/share/cmake/modules/FindOpenEXR.cmake @@ -89,13 +89,14 @@ if(NOT OpenEXR_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACK set(_EXT_BUILD_ROOT "${CMAKE_BINARY_DIR}/ext/build") # Required dependency - # OCIO custom module to find ZLIB. (Findzlib) - find_package(zlib) if(NOT ZLIB_FOUND) - message(STATUS "ZLib is required to build OpenEXR.") - return() + find_package(ZLIB) + if(NOT ZLIB_FOUND) + message(STATUS "ZLib is required to build OpenEXR.") + return() + endif() endif() - + find_package(Threads) if(NOT Threads_FOUND) message(STATUS "Threads is required to build OpenEXR.") diff --git a/share/cmake/modules/Findzlib.cmake b/share/cmake/modules/InstallZLIB.cmake similarity index 62% rename from share/cmake/modules/Findzlib.cmake rename to share/cmake/modules/InstallZLIB.cmake index 6a12a4610f..a6eb8101af 100644 --- a/share/cmake/modules/Findzlib.cmake +++ b/share/cmake/modules/InstallZLIB.cmake @@ -1,14 +1,7 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright Contributors to the OpenColorIO Project. # -# Locate or install ZLIB -# -# ********************************************************************** -# Note that this is a wrapper around the CMake ZLIB find module. -# This find module DOES NOT output any variables with lowercase "zlib". -# -# Treat this module as if it was FindZLIB.cmake. -# ********************************************************************** +# Install ZLIB # # Variables defined by this module: # ZLIB_FOUND - If FALSE, do not try to link to zlib @@ -17,96 +10,23 @@ # ZLIB_VERSION - The version of the library # # Targets defined by this module: -# ZLIB::ZLIB - IMPORTED target, if found +# ZLIB::ZLIB - Properties: +# IMPORTED_LOCATION ${ZLIB_LIBRARIES} +# INTERFACE_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRS} # ############################################################################### -### Try to find package ### - -if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) - # Update ZLIB_ROOT if zlib_ROOT was set. - if (zlib_ROOT) - set(ZLIB_ROOT "${zlib_ROOT}") - endif() - - # Update ZLIB_LIBRARY if zlib_LIBRARY was set. - if (zlib_LIBRARY) - set(ZLIB_LIBRARY "${zlib_LIBRARY}") - endif() - - # Update ZLIB_INCLUDE_DIR if zlib_INCLUDE_DIR was set. - if (zlib_INCLUDE_DIR) - set(ZLIB_INCLUDE_DIR "${zlib_INCLUDE_DIR}") - endif() - - # ZLIB_USE_STATIC_LIBS is supported only from CMake 3.24+. - if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0") - if (ZLIB_STATIC_LIBRARY) - set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}") - elseif(zlib_STATIC_LIBRARY) - set(ZLIB_USE_STATIC_LIBS "${zlib_STATIC_LIBRARY}") - endif() - endif() - - # Forcing CMake to use its own find module called FindZLIB.cmake. - # Save old value of CMAKE_MODULE_PATH - set(_ZLIB__CMAKE_MODULE_PATH_OLD_ ${CMAKE_MODULE_PATH}) - # Force find_package to use CMAKE module and not custom modules. - set(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules") - - # Use CMake FindZLIB module. (ZLIB in capital letters is important) - # FindZLIB supports ZLIB_ROOT, ZLIB_LIBRARIES and ZLIB_INCLUDE_DIRS. - find_package(ZLIB ${zlib_FIND_VERSION} QUIET) - - # Restore CMAKE_MODULE_PATH - set(CMAKE_MODULE_PATH ${_ZLIB__CMAKE_MODULE_PATH_OLD_}) - - if (ZLIB_FOUND) - # Right now, OCIO custom find modules uses the following standard: - # _LIBRARY and _INCLUDE_DIR - # But CMake's FindZLIB sets ZLIB_LIBRARIES and ZLIB_INCLUDE_DIRS. - - # Set ZLIB_LIBRARY if it is not set already. - if(ZLIB_LIBRARIES AND NOT ZLIB_LIBRARY) - set(ZLIB_LIBRARY "${ZLIB_LIBRARIES}") - endif() - - # Set ZLIB_INCLUDE_DIR if it is not set already. - if(ZLIB_INCLUDE_DIRS AND NOT ZLIB_INCLUDE_DIR) - set(ZLIB_INCLUDE_DIR "${ZLIB_INCLUDE_DIRS}") - endif() - - # CMake FindZLIB uses ZLIB_VERSION_STRING for CMake < 3.26. - if (ZLIB_VERSION_STRING) - set(ZLIB_VERSION "${ZLIB_VERSION_STRING}") - endif() - endif() - - # Override REQUIRED if package can be installed - if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) - set(zlib_FIND_REQUIRED FALSE) - set(ZLIB_FIND_REQUIRED FALSE) - endif() - - include(FindPackageHandleStandardArgs) - find_package_handle_standard_args(zlib - REQUIRED_VARS - ZLIB_LIBRARY - ZLIB_INCLUDE_DIR - VERSION_VAR - ZLIB_VERSION - ) -endif() ############################################################################### ### Create target - +############################################################################### if(NOT TARGET ZLIB::ZLIB) add_library(ZLIB::ZLIB UNKNOWN IMPORTED GLOBAL) set(_ZLIB_TARGET_CREATE TRUE) endif() ############################################################################### -### Install package from source ### +### Install package from source +############################################################################### if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) include(ExternalProject) include(GNUInstallDirs) @@ -127,8 +47,9 @@ if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGE if(_ZLIB_ExternalProject_VERSION) set(ZLIB_VERSION ${_ZLIB_ExternalProject_VERSION}) else() - set(ZLIB_VERSION ${zlib_FIND_VERSION}) + set(ZLIB_VERSION ${ZLIB_FIND_VERSION}) endif() + set(ZLIB_INCLUDE_DIRS "${_EXT_DIST_ROOT}/${CMAKE_INSTALL_INCLUDEDIR}") # Windows need the "d" suffix at the end. @@ -217,9 +138,10 @@ if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGE message(STATUS "Installing ZLIB: ${ZLIB_LIBRARIES} (version \"${ZLIB_VERSION}\")") endif() + ############################################################################### ### Configure target ### - +############################################################################### if(_ZLIB_TARGET_CREATE) set_target_properties(ZLIB::ZLIB PROPERTIES IMPORTED_LOCATION ${ZLIB_LIBRARIES} diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index 0e82aa12d7..fabbdc5ce9 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -16,8 +16,8 @@ if (NOT @BUILD_SHARED_LIBS@) endforeach() # Append OCIO custom find module path. - list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/cmake/modules") - list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/cmake/macros") + list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/OpenColorIO/cmake/modules") + list(APPEND CMAKE_MODULE_PATH "${_IMPORT_PREFIX}/share/OpenColorIO/cmake/macros") ######################## # Required dependencies @@ -39,9 +39,15 @@ if (NOT @BUILD_SHARED_LIBS@) find_dependency(yaml-cpp @yaml-cpp_VERSION@) endif() - # CMake has a zlib find module, but OCIO is using its own find module for zlib. (Findzlib.cmake) if (NOT ZLIB::ZLIB) - find_dependency(zlib @ZLIB_VERSION@) + # ZLIB_VERSION is available starting CMake 3.26+. + # ZLIB_VERSION_STRING is still available for backward compatibility. + # See https://cmake.org/cmake/help/git-stage/module/FindZLIB.html + if (@ZLIB_VERSION@) + find_dependency(ZLIB @ZLIB_VERSION@) + else() + find_dependency(ZLIB @ZLIB_VERSION_STRING@) + endif() endif() if (NOT MINIZIP::minizip-ng) From acc80b7c52b1394a553919b7464b402a0d5e81a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Fri, 9 Dec 2022 14:19:53 -0500 Subject: [PATCH 15/23] Adding more details in 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/FindExtPackages.cmake | 5 +++++ share/cmake/modules/InstallZLIB.cmake | 3 +++ 2 files changed, 8 insertions(+) diff --git a/share/cmake/modules/FindExtPackages.cmake b/share/cmake/modules/FindExtPackages.cmake index f54dee394d..59225a6714 100644 --- a/share/cmake/modules/FindExtPackages.cmake +++ b/share/cmake/modules/FindExtPackages.cmake @@ -43,6 +43,11 @@ find_package(Imath 3.0 REQUIRED) ############################################################################### ### ZLIB (https://github.com/madler/zlib) +### +### Since OCIO is using CMake's FindZLIB, it supports the same output variables +### and the same variables that can be overridden. +### +### See https://cmake.org/cmake/help/latest/module/FindZLIB.html ############################################################################### set(_ZLIB_FIND_VERSION "1.2.11") set(_ZLIB_ExternalProject_VERSION ${_ZLIB_FIND_VERSION}) diff --git a/share/cmake/modules/InstallZLIB.cmake b/share/cmake/modules/InstallZLIB.cmake index a6eb8101af..954563ec4e 100644 --- a/share/cmake/modules/InstallZLIB.cmake +++ b/share/cmake/modules/InstallZLIB.cmake @@ -3,6 +3,9 @@ # # Install ZLIB # +# Except for the variable ZLIB_VERSION_STRING, OCIO sets the same variables as the +# CMake's FindZLIB when installing ZLIB manually. +# # Variables defined by this module: # ZLIB_FOUND - If FALSE, do not try to link to zlib # ZLIB_LIBRARIES - ZLIB library to link to From 857b956ec9c2153c5add807d731c3f1e6f83ab34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Fri, 9 Dec 2022 14:34:16 -0500 Subject: [PATCH 16/23] Removing an extra "shell" property in CI workflow. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- .github/workflows/ci_workflow.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index cc6f53f093..1ed3c56380 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -614,7 +614,6 @@ jobs: run: ctest -V -C ${{ matrix.build-type }} shell: bash working-directory: _build - shell: bash - name: Test CMake Consumer with shared OCIO if: matrix.build-shared == 'ON' run: | From 42fe5a42fb09d3006db72cc4eef4e08ae17e23bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Mon, 12 Dec 2022 14:22:52 -0500 Subject: [PATCH 17/23] Fix issues discovered with the failing CI workflow: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cmake-consumer test now prefer the static version of the dependencies. Fix an issue where yaml-cpp is not found by a consumer app (variable spelled incorectly in Findyaml-cpp). Fix an issue expat library is not found by a consumer app on Windows. Adding support for OCIO's _STATIC_LIBRARY for ZLIB while supporting ZLIB_USE_STATIC_LIBS (CMake 3.24+) from CMake's FindZLIB. Signed-off-by: Cédrik Fuoco --- .github/workflows/ci_workflow.yml | 38 ++++++++++++++-- share/cmake/modules/FindExtPackages.cmake | 42 ++++++++++++++++++ share/cmake/modules/Findexpat.cmake | 11 ++++- share/cmake/modules/Findyaml-cpp.cmake | 2 +- src/cmake/Config.cmake.in | 54 ++++++++++++++++++++++- 5 files changed, 139 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 1ed3c56380..6c1e74a32d 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -306,17 +306,27 @@ jobs: if: matrix.build-shared == 'OFF' # The yaml-cpp_VERSION is set below because Findyaml-cpp.cmake needs it but is unable to # extract it from the headers, like the other modules. + # + # Prefer the static version of each dependencies by using _STATIC_LIBRARY. + # Alternatively, this can be done by setting _LIBRARY and _INCLUDE_DIR to + # the static version of the package. run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dexpat_STATIC_LIBRARY=ON \ -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -DImath_STATIC_LIBRARY=ON \ -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dpystring_STATIC_LIBRARY=ON \ -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dyaml-cpp_STATIC_LIBRARY=ON \ -Dyaml-cpp_VERSION=0.7.0 \ -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \ - -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist + -DZLIB_STATIC_LIBRARY=ON \ + -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dminizip-ng_STATIC_LIBRARY=ON cmake --build . \ --config ${{ matrix.build-type }} ./consumer @@ -462,18 +472,28 @@ jobs: - name: Test CMake Consumer with static OCIO if: matrix.build-shared == 'OFF' # The yaml-cpp_VERSION is set below because Findyaml-cpp.cmake needs it but is unable to - # extract it from the headers, like the other modules. + # extract it from the headers, like the other modules. + # + # Prefer the static version of each dependencies by using _STATIC_LIBRARY. + # Alternatively, this can be done by setting _LIBRARY and _INCLUDE_DIR to + # the static version of the package. run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dexpat_STATIC_LIBRARY=ON \ -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -DImath_STATIC_LIBRARY=ON \ -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dpystring_STATIC_LIBRARY=ON \ -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dyaml-cpp_STATIC_LIBRARY=ON \ -Dyaml-cpp_VERSION=0.7.0 \ -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \ - -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist + -DZLIB_STATIC_LIBRARY=ON \ + -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dminizip-ng_STATIC_LIBRARY=ON cmake --build . \ --config ${{ matrix.build-type }} ./consumer @@ -630,17 +650,27 @@ jobs: if: matrix.build-shared == 'OFF' # The yaml-cpp_VERSION is set below because Findyaml-cpp.cmake needs it but is unable to # extract it from the headers, like the other modules. + # + # Prefer the static version of each dependencies by using _STATIC_LIBRARY. + # Alternatively, this can be done by setting _LIBRARY and _INCLUDE_DIR to + # the static version of the package. run: | cmake . \ -DCMAKE_PREFIX_PATH=../../../_install \ -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} \ -Dexpat_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dexpat_STATIC_LIBRARY=ON \ -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -DImath_STATIC_LIBRARY=ON \ -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dpystring_STATIC_LIBRARY=ON \ -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dyaml-cpp_STATIC_LIBRARY=ON \ -Dyaml-cpp_VERSION=0.7.0 \ -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \ - -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist + -DZLIB_STATIC_LIBRARY=ON \ + -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist \ + -Dminizip-ng_STATIC_LIBRARY=ON cmake --build . \ --config ${{ matrix.build-type }} export PATH=../../../_install/bin:$PATH diff --git a/share/cmake/modules/FindExtPackages.cmake b/share/cmake/modules/FindExtPackages.cmake index 59225a6714..147e7be275 100644 --- a/share/cmake/modules/FindExtPackages.cmake +++ b/share/cmake/modules/FindExtPackages.cmake @@ -58,6 +58,35 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) if (ZLIB_STATIC_LIBRARY) set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}") endif() + else() # For CMake < 3.24 since ZLIB_USE_STATIC_LIBS is not available. + if(NOT ZLIB_LIBRARY) + if(DEFINED CMAKE_FIND_LIBRARY_PREFIXES) + set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") + else() + set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES) + endif() + + if(DEFINED CMAKE_FIND_LIBRARY_SUFFIXES) + set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}") + else() + set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) + endif() + + # Prefix/suffix for windows. + if(WIN32) + list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib") + list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a") + endif() + + # Check if static lib is preferred. + if(ZLIB_STATIC_LIBRARY OR ZLIB_USE_STATIC_LIBS) + if(WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) + endif() + endif() + endif() endif() set(_ZLIB_REQUIRED REQUIRED) @@ -67,6 +96,19 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) endif() find_package(ZLIB ${_ZLIB_FIND_VERSION} ${_ZLIB_REQUIRED}) + + # Restore the original find library ordering + if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) + set(CMAKE_FIND_LIBRARY_SUFFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}") + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES) + endif() + + if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES) + set(CMAKE_FIND_LIBRARY_PREFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES}") + else() + set(CMAKE_FIND_LIBRARY_PREFIXES) + endif() endif() if(NOT ZLIB_FOUND AND OCIO_INSTALL_EXT_PACKAGES AND NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL NONE) diff --git a/share/cmake/modules/Findexpat.cmake b/share/cmake/modules/Findexpat.cmake index 57757dba38..026ee34791 100644 --- a/share/cmake/modules/Findexpat.cmake +++ b/share/cmake/modules/Findexpat.cmake @@ -96,11 +96,20 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) if(expat_STATIC_LIBRARY) # Prefer static lib names - set(_expat_STATIC_LIB_NAMES + set(_expat_STATIC_LIB_NAMES "${CMAKE_STATIC_LIBRARY_PREFIX}expat${CMAKE_STATIC_LIBRARY_SUFFIX}") + + # See https://github.com/libexpat/libexpat/blob/R_2_2_8/expat/win32/README.txt + if (WIN32) + list(INSERT _expat_STATIC_LIB_NAMES 0 + "${CMAKE_STATIC_LIBRARY_PREFIX}expatMD${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}expatMT${CMAKE_STATIC_LIBRARY_SUFFIX}") + endif() if(WIN32 AND BUILD_TYPE_DEBUG) # Prefer static Debug lib names (Windows only) list(INSERT _expat_STATIC_LIB_NAMES 0 + "${CMAKE_STATIC_LIBRARY_PREFIX}expatdMD${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}expatdMT${CMAKE_STATIC_LIBRARY_SUFFIX}" "${CMAKE_STATIC_LIBRARY_PREFIX}expatd${CMAKE_STATIC_LIBRARY_SUFFIX}") endif() endif() diff --git a/share/cmake/modules/Findyaml-cpp.cmake b/share/cmake/modules/Findyaml-cpp.cmake index 37239900ee..4b3d2ba0f9 100644 --- a/share/cmake/modules/Findyaml-cpp.cmake +++ b/share/cmake/modules/Findyaml-cpp.cmake @@ -91,7 +91,7 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) ${_yaml-cpp_STATIC_LIB_NAMES} ${_yaml-cpp_LIB_NAMES} HINTS - ${_yaml-cpp_ROOT} + ${yaml-cpp_ROOT} ${PC_yaml-cpp_LIBRARY_DIRS} PATH_SUFFIXES lib64 diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index fabbdc5ce9..9c3cfec006 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -2,7 +2,7 @@ include(CMakeFindDependencyMacro) -if (NOT @BUILD_SHARED_LIBS@) +if (NOT @BUILD_SHARED_LIBS@) # NOT @BUILD_SHARED_LIBS@ # Get the install directory. set(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}") # Get the install directory. Since the current file is under @@ -43,11 +43,61 @@ if (NOT @BUILD_SHARED_LIBS@) # ZLIB_VERSION is available starting CMake 3.26+. # ZLIB_VERSION_STRING is still available for backward compatibility. # See https://cmake.org/cmake/help/git-stage/module/FindZLIB.html - if (@ZLIB_VERSION@) + + # ZLIB_USE_STATIC_LIBS is supported only from CMake 3.24+. + if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24.0") + if (ZLIB_STATIC_LIBRARY) + set(ZLIB_USE_STATIC_LIBS "${ZLIB_STATIC_LIBRARY}") + endif() + else() # For CMake < 3.24 since ZLIB_USE_STATIC_LIBS is not available. + if(NOT ZLIB_LIBRARY) + if(DEFINED CMAKE_FIND_LIBRARY_PREFIXES) + set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}") + else() + set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES) + endif() + + if(DEFINED CMAKE_FIND_LIBRARY_SUFFIXES) + set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES "${CMAKE_FIND_LIBRARY_SUFFIXES}") + else() + set(_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) + endif() + + # Prefix/suffix for windows. + if(WIN32) + list(APPEND CMAKE_FIND_LIBRARY_PREFIXES "" "lib") + list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".dll.a") + endif() + + # Check if static lib is preferred. + if(ZLIB_STATIC_LIBRARY OR ZLIB_USE_STATIC_LIBS) + if(WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES}) + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES .a) + endif() + endif() + endif() + endif() + + if (@ZLIB_VERSION@) # @ZLIB_VERSION@ find_dependency(ZLIB @ZLIB_VERSION@) else() find_dependency(ZLIB @ZLIB_VERSION_STRING@) endif() + + # Restore the original find library ordering + if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES) + set(CMAKE_FIND_LIBRARY_SUFFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}") + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES) + endif() + + if(DEFINED _ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES) + set(CMAKE_FIND_LIBRARY_PREFIXES "${_ZLIB_ORIG_CMAKE_FIND_LIBRARY_PREFIXES}") + else() + set(CMAKE_FIND_LIBRARY_PREFIXES) + endif() endif() if (NOT MINIZIP::minizip-ng) From 6a5a7a04ecb325e859646eb827b670d571ab45a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 13 Dec 2022 10:03:35 -0500 Subject: [PATCH 18/23] Removing pystring_STATIC_LIBRARY does not exists in CI workflow. Detecting if the build is Debug in the find module that OCIO installs since they can't rely on variables set by OCIO CMakefiles. Fix issue with yaml-cpp library naming in debug. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- .github/workflows/ci_workflow.yml | 3 --- share/cmake/modules/FindImath.cmake | 9 ++++++++ share/cmake/modules/Findexpat.cmake | 9 ++++++++ share/cmake/modules/Findminizip-ng.cmake | 9 ++++++++ share/cmake/modules/Findminizip.cmake | 9 ++++++++ share/cmake/modules/Findyaml-cpp.cmake | 26 ++++++++++++++++-------- 6 files changed, 53 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 6c1e74a32d..77527cd723 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -319,7 +319,6 @@ jobs: -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \ -DImath_STATIC_LIBRARY=ON \ -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \ - -Dpystring_STATIC_LIBRARY=ON \ -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \ -Dyaml-cpp_STATIC_LIBRARY=ON \ -Dyaml-cpp_VERSION=0.7.0 \ @@ -486,7 +485,6 @@ jobs: -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \ -DImath_STATIC_LIBRARY=ON \ -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \ - -Dpystring_STATIC_LIBRARY=ON \ -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \ -Dyaml-cpp_STATIC_LIBRARY=ON \ -Dyaml-cpp_VERSION=0.7.0 \ @@ -663,7 +661,6 @@ jobs: -DImath_ROOT=${{ env.ocio_build_path }}/ext/dist \ -DImath_STATIC_LIBRARY=ON \ -Dpystring_ROOT=${{ env.ocio_build_path }}/ext/dist \ - -Dpystring_STATIC_LIBRARY=ON \ -Dyaml-cpp_ROOT=${{ env.ocio_build_path }}/ext/dist \ -Dyaml-cpp_STATIC_LIBRARY=ON \ -Dyaml-cpp_VERSION=0.7.0 \ diff --git a/share/cmake/modules/FindImath.cmake b/share/cmake/modules/FindImath.cmake index d3641b1487..30f5b4e465 100644 --- a/share/cmake/modules/FindImath.cmake +++ b/share/cmake/modules/FindImath.cmake @@ -25,6 +25,15 @@ ############################################################################### ### Try to find package ### +# BUILD_TYPE_DEBUG variable is currently set in one of the OCIO's CMake files. +# Now that some OCIO's find module are installed with the library itself (with static build), +# a consumer app don't have access to the variables set by an OCIO's CMake files. Therefore, some +# OCIO's find modules must detect the build type by itselves. +set(BUILD_TYPE_DEBUG OFF) +if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") + set(BUILD_TYPE_DEBUG ON) +endif() + if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) set(_Imath_REQUIRED_VARS Imath_LIBRARY) set(_Imath_LIB_VER "${Imath_FIND_VERSION_MAJOR}_${Imath_FIND_VERSION_MINOR}") diff --git a/share/cmake/modules/Findexpat.cmake b/share/cmake/modules/Findexpat.cmake index 026ee34791..938f055ff4 100644 --- a/share/cmake/modules/Findexpat.cmake +++ b/share/cmake/modules/Findexpat.cmake @@ -25,6 +25,15 @@ ############################################################################### ### Try to find package ### +# BUILD_TYPE_DEBUG variable is currently set in one of the OCIO's CMake files. +# Now that some OCIO's find module are installed with the library itself (with static build), +# a consumer app don't have access to the variables set by an OCIO's CMake files. Therefore, some +# OCIO's find modules must detect the build type by itselves. +set(BUILD_TYPE_DEBUG OFF) +if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") + set(BUILD_TYPE_DEBUG ON) +endif() + if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) set(_expat_REQUIRED_VARS expat_LIBRARY) diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index ec4d4b0d78..70d68146db 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -32,6 +32,15 @@ ############################################################################### ### Try to find package ### +# BUILD_TYPE_DEBUG variable is currently set in one of the OCIO's CMake files. +# Now that some OCIO's find module are installed with the library itself (with static build), +# a consumer app don't have access to the variables set by an OCIO's CMake files. Therefore, some +# OCIO's find modules must detect the build type by itselves. +set(BUILD_TYPE_DEBUG OFF) +if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") + set(BUILD_TYPE_DEBUG ON) +endif() + if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) if(NOT DEFINED minizip-ng_ROOT) # Search for minizip-ng-config.cmake diff --git a/share/cmake/modules/Findminizip.cmake b/share/cmake/modules/Findminizip.cmake index 4142f3c359..62ffb1613e 100644 --- a/share/cmake/modules/Findminizip.cmake +++ b/share/cmake/modules/Findminizip.cmake @@ -28,6 +28,15 @@ ############################################################################### ### Try to find package ### +# BUILD_TYPE_DEBUG variable is currently set in one of the OCIO's CMake files. +# Now that some OCIO's find module are installed with the library itself (with static build), +# a consumer app don't have access to the variables set by an OCIO's CMake files. Therefore, some +# OCIO's find modules must detect the build type by itselves. +set(BUILD_TYPE_DEBUG OFF) +if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") + set(BUILD_TYPE_DEBUG ON) +endif() + if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) if(NOT DEFINED minizip_ROOT) diff --git a/share/cmake/modules/Findyaml-cpp.cmake b/share/cmake/modules/Findyaml-cpp.cmake index 4b3d2ba0f9..59558ce6a9 100644 --- a/share/cmake/modules/Findyaml-cpp.cmake +++ b/share/cmake/modules/Findyaml-cpp.cmake @@ -25,6 +25,15 @@ ############################################################################### ### Try to find package ### +# BUILD_TYPE_DEBUG variable is currently set in one of the OCIO's CMake files. +# Now that some OCIO's find module are installed with the library itself (with static build), +# a consumer app don't have access to the variables set by an OCIO's CMake files. Therefore, some +# OCIO's find modules must detect the build type by itselves. +set(BUILD_TYPE_DEBUG OFF) +if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") + set(BUILD_TYPE_DEBUG ON) +endif() + if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) set(_yaml-cpp_REQUIRED_VARS yaml-cpp_LIBRARY) @@ -66,22 +75,21 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) # Lib names to search for set(_yaml-cpp_LIB_NAMES yaml-cpp) - if(WIN32 AND BUILD_TYPE_DEBUG AND NOT MINGW) - # Prefer Debug lib names (Windows only) + if(BUILD_TYPE_DEBUG) + # Prefer Debug lib names. list(INSERT _yaml-cpp_LIB_NAMES 0 yaml-cppd) endif() if(yaml-cpp_STATIC_LIBRARY) # Prefer static lib names - if(WIN32 AND NOT MINGW) - set(_yaml-cpp_LIB_SUFFIX "md") - endif() set(_yaml-cpp_STATIC_LIB_NAMES - "libyaml-cpp${_yaml-cpp_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") - if(WIN32 AND BUILD_TYPE_DEBUG AND NOT MINGW) - # Prefer static Debug lib names (Windows only) + "${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cpp${CMAKE_STATIC_LIBRARY_SUFFIX}") + + # Starting from 0.7.0, all platforms uses the suffix "d" for debug. + # See https://github.com/jbeder/yaml-cpp/blob/master/CMakeLists.txt#L141 + if(BUILD_TYPE_DEBUG) list(INSERT _yaml-cpp_STATIC_LIB_NAMES 0 - "libyaml-cpp${_yaml-cpp_LIB_SUFFIX}d${CMAKE_STATIC_LIBRARY_SUFFIX}") + "${CMAKE_STATIC_LIBRARY_PREFIX}yaml-cppd${CMAKE_STATIC_LIBRARY_SUFFIX}") endif() endif() From 705f41980e4e3da520d3d1b96c0584e77d48f979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 13 Dec 2022 13:38:14 -0500 Subject: [PATCH 19/23] Fix issues on Windows with expat and minizip-ng library naming when building static OCIO. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- share/cmake/modules/Findexpat.cmake | 50 ++++++++++++++++++------ share/cmake/modules/Findminizip-ng.cmake | 19 ++++----- share/cmake/modules/Findminizip.cmake | 21 ++++------ 3 files changed, 54 insertions(+), 36 deletions(-) diff --git a/share/cmake/modules/Findexpat.cmake b/share/cmake/modules/Findexpat.cmake index 938f055ff4..8e23cbba0b 100644 --- a/share/cmake/modules/Findexpat.cmake +++ b/share/cmake/modules/Findexpat.cmake @@ -96,30 +96,58 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) expat/include ) + + # Expat uses prefix "lib" on all platform by default. + # Library name doesn't change in debug. + + # For Windows, see https://github.com/libexpat/libexpat/blob/R_2_2_8/expat/win32/README.txt. + # libexpat.lib + # The "w" indicates the UTF-16 version of the library. + # Lib names to search for - set(_expat_LIB_NAMES expat libexpat) + set(_expat_LIB_NAMES libexpat expat) + if(WIN32 AND BUILD_TYPE_DEBUG) - # Prefer Debug lib names (Windows only) - list(INSERT _expat_LIB_NAMES 0 expatd) + # Prefer Debug lib names. The library name changes only on Windows. + list(INSERT _expat_LIB_NAMES 0 libexpatd libexpatwd expatd expatwd) + elseif(WIN32) + # libexpat(w).dll/.lib + list(APPEND _expat_LIB_NAMES libexpatw expatw) endif() if(expat_STATIC_LIBRARY) + # Looking for both "lib" prefix and CMAKE_STATIC_LIBRARY_PREFIX. # Prefer static lib names set(_expat_STATIC_LIB_NAMES + "libexpat${CMAKE_STATIC_LIBRARY_SUFFIX}" "${CMAKE_STATIC_LIBRARY_PREFIX}expat${CMAKE_STATIC_LIBRARY_SUFFIX}") - # See https://github.com/libexpat/libexpat/blob/R_2_2_8/expat/win32/README.txt - if (WIN32) - list(INSERT _expat_STATIC_LIB_NAMES 0 - "${CMAKE_STATIC_LIBRARY_PREFIX}expatMD${CMAKE_STATIC_LIBRARY_SUFFIX}" - "${CMAKE_STATIC_LIBRARY_PREFIX}expatMT${CMAKE_STATIC_LIBRARY_SUFFIX}") - endif() if(WIN32 AND BUILD_TYPE_DEBUG) - # Prefer static Debug lib names (Windows only) + # Prefer static Debug lib names. The library name changes only on Windows. list(INSERT _expat_STATIC_LIB_NAMES 0 + "libexpatdMD${CMAKE_STATIC_LIBRARY_SUFFIX}" + "libexpatdMT${CMAKE_STATIC_LIBRARY_SUFFIX}" + "libexpatd${CMAKE_STATIC_LIBRARY_SUFFIX}" + "libexpatwdMD${CMAKE_STATIC_LIBRARY_SUFFIX}" + "libexpatwdMT${CMAKE_STATIC_LIBRARY_SUFFIX}" + "libexpatwd${CMAKE_STATIC_LIBRARY_SUFFIX}" "${CMAKE_STATIC_LIBRARY_PREFIX}expatdMD${CMAKE_STATIC_LIBRARY_SUFFIX}" "${CMAKE_STATIC_LIBRARY_PREFIX}expatdMT${CMAKE_STATIC_LIBRARY_SUFFIX}" - "${CMAKE_STATIC_LIBRARY_PREFIX}expatd${CMAKE_STATIC_LIBRARY_SUFFIX}") + "${CMAKE_STATIC_LIBRARY_PREFIX}expatd${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}expatwdMD${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}expatwdMT${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}expatwd${CMAKE_STATIC_LIBRARY_SUFFIX}") + elseif (WIN32) + list(INSERT _expat_STATIC_LIB_NAMES 0 + "libexpatMD${CMAKE_STATIC_LIBRARY_SUFFIX}" + "libexpatMT${CMAKE_STATIC_LIBRARY_SUFFIX}" + "libexpatwMD${CMAKE_STATIC_LIBRARY_SUFFIX}" + "libexpatwMT${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}expatMD${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}expatMT${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}expatwMD${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}expatwMT${CMAKE_STATIC_LIBRARY_SUFFIX}" + ) endif() endif() diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index 70d68146db..c5486e5024 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -115,23 +115,18 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) minizip-ng/include ) - # Lib names to search for - set(_minizip-ng_LIB_NAMES minizip-ng) + # Minizip-ng uses prefix "lib" on all platform by default. + # Library name doesn't change in debug. - if(BUILD_TYPE_DEBUG) - # Prefer Debug lib names (Windows only) - list(INSERT _minizip-ng_LIB_NAMES 0 minizip-ngd) - endif() + # Lib names to search for. + set(_minizip-ng_LIB_NAMES libminizip-ng minizip-ng) if(minizip-ng_STATIC_LIBRARY) - # Prefer static lib names + # Looking for both "lib" prefix and CMAKE_STATIC_LIBRARY_PREFIX. + # Prefer static lib names. set(_minizip-ng_STATIC_LIB_NAMES + "libminizip-ng${CMAKE_STATIC_LIBRARY_SUFFIX}" "${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 diff --git a/share/cmake/modules/Findminizip.cmake b/share/cmake/modules/Findminizip.cmake index 62ffb1613e..eeada367f8 100644 --- a/share/cmake/modules/Findminizip.cmake +++ b/share/cmake/modules/Findminizip.cmake @@ -99,23 +99,18 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) 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() + # Minizip uses prefix "lib" on all platform by default. + # Library name doesn't change in debug. + + # Lib names to search for. + set(_minizip_LIB_NAMES libminizip minizip) if(minizip_STATIC_LIBRARY) - # Prefer static lib names + # Looking for both "lib" prefix and CMAKE_STATIC_LIBRARY_PREFIX. + # Prefer static lib names. set(_minizip_STATIC_LIB_NAMES + "libminizip${CMAKE_STATIC_LIBRARY_SUFFIX}" "${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 From f84aef21ebde2a9d1ad391eb273e752967c5c78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Tue, 13 Dec 2022 22:31:29 -0500 Subject: [PATCH 20/23] Added option for macOS CI job in order to get more info on a failed job. Will be reverted once the issue is found. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- .github/workflows/ci_workflow.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index 77527cd723..a9b1b75150 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -491,7 +491,8 @@ jobs: -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \ -DZLIB_STATIC_LIBRARY=ON \ -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist \ - -Dminizip-ng_STATIC_LIBRARY=ON + -Dminizip-ng_STATIC_LIBRARY=ON \ + --trace-source=Findexpat.cmake --trace-expand cmake --build . \ --config ${{ matrix.build-type }} ./consumer From 253121045cb7a71eb60e10af396f9dc20ac2d30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Wed, 14 Dec 2022 10:50:26 -0500 Subject: [PATCH 21/23] Fixing a issue on macOS. Improving ZLIB usage comments. Bumping minizip-ng to the latest version - 3.0.7. Bumping ZLIB to the latest version 2.1.13 to fix a vulnerability (CVE-2022-37434) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- .github/workflows/ci_workflow.yml | 3 +- share/cmake/modules/FindExtPackages.cmake | 36 +++++++++++++++++++---- src/cmake/Config.cmake.in | 17 +++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci_workflow.yml b/.github/workflows/ci_workflow.yml index a9b1b75150..77527cd723 100644 --- a/.github/workflows/ci_workflow.yml +++ b/.github/workflows/ci_workflow.yml @@ -491,8 +491,7 @@ jobs: -DZLIB_ROOT=${{ env.ocio_build_path }}/ext/dist \ -DZLIB_STATIC_LIBRARY=ON \ -Dminizip-ng_ROOT=${{ env.ocio_build_path }}/ext/dist \ - -Dminizip-ng_STATIC_LIBRARY=ON \ - --trace-source=Findexpat.cmake --trace-expand + -Dminizip-ng_STATIC_LIBRARY=ON cmake --build . \ --config ${{ matrix.build-type }} ./consumer diff --git a/share/cmake/modules/FindExtPackages.cmake b/share/cmake/modules/FindExtPackages.cmake index 147e7be275..5455a08ce6 100644 --- a/share/cmake/modules/FindExtPackages.cmake +++ b/share/cmake/modules/FindExtPackages.cmake @@ -21,6 +21,17 @@ set(CMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY ON CACHE BOOL set(CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY ON CACHE BOOL "Disable CMake System Package Registry when finding packages") +if (APPLE) + # Store the previous value of CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE. + set(_PREVIOUS_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK}) + set(_PREVIOUS_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE}) + + # Prioritize other paths before Frameworks and Appbundle for find_path, find_library and + # find_package. + set(CMAKE_FIND_FRAMEWORK LAST) + set(CMAKE_FIND_APPBUNDLE LAST) +endif() + ############################################################################### ### Packages and versions ### @@ -44,12 +55,21 @@ find_package(Imath 3.0 REQUIRED) ############################################################################### ### ZLIB (https://github.com/madler/zlib) ### -### Since OCIO is using CMake's FindZLIB, it supports the same output variables -### and the same variables that can be overridden. +### The following variables can be set: +### ZLIB_ROOT Location of ZLIB library file and includes folder. +### Alternatively, ZLIB_LIBRARY and ZLIB_INCLUDE_DIR can be used. +### +### ZLIB_LIBRARY Location of ZLIB library file. +### ZLIB_INCLUDE_DIR Location of ZLIB includes folder. +### +### ZLIB_VERSION ZLIB Version (CMake 3.26+) +### ZLIB_VERSION_STRING ZLIB Version (CMake < 3.26) ### -### See https://cmake.org/cmake/help/latest/module/FindZLIB.html ############################################################################### -set(_ZLIB_FIND_VERSION "1.2.11") +# ZLIB 1.2.13 is used since it fixes a critical vulnerability. +# See https://nvd.nist.gov/vuln/detail/CVE-2022-37434 +# See https://github.com/madler/zlib/releases/tag/v1.2.13 +set(_ZLIB_FIND_VERSION "1.2.13") set(_ZLIB_ExternalProject_VERSION ${_ZLIB_FIND_VERSION}) if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) @@ -118,7 +138,7 @@ endif() # minizip-ng # https://github.com/zlib-ng/minizip-ng -find_package(minizip-ng 3.0.6 REQUIRED) +find_package(minizip-ng 3.0.7 REQUIRED) if(OCIO_BUILD_APPS) @@ -227,3 +247,9 @@ if(OCIO_BUILD_TESTS) message(WARNING "Could NOT find OpenImageIO. Skipping build of the OSL unit tests.") endif() endif() + +if (APPLE) + # Restore CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE values. + set(CMAKE_FIND_FRAMEWORK ${_PREVIOUS_CMAKE_FIND_FRAMEWORK}) + set(CMAKE_FIND_APPBUNDLE ${_PREVIOUS_CMAKE_FIND_APPBUNDLE}) +endif() diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index 9c3cfec006..6a4932a836 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -3,6 +3,17 @@ include(CMakeFindDependencyMacro) if (NOT @BUILD_SHARED_LIBS@) # NOT @BUILD_SHARED_LIBS@ + if (APPLE) + # Store the previous value of CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE. + set(_PREVIOUS_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK}) + set(_PREVIOUS_CMAKE_FIND_APPBUNDLE ${CMAKE_FIND_APPBUNDLE}) + + # Prioritize other paths before Frameworks and Appbundle for find_path, find_library and + # find_package. + set(CMAKE_FIND_FRAMEWORK LAST) + set(CMAKE_FIND_APPBUNDLE LAST) + endif() + # Get the install directory. set(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}") # Get the install directory. Since the current file is under @@ -106,6 +117,12 @@ if (NOT @BUILD_SHARED_LIBS@) # NOT @BUILD_SHARED_LIBS@ # Remove OCIO custom find module path. list(REMOVE_AT CMAKE_MODULE_PATH -1) + + if (APPLE) + # Restore CMAKE_FIND_FRAMEWORK and CMAKE_FIND_APPBUNDLE values. + set(CMAKE_FIND_FRAMEWORK ${_PREVIOUS_CMAKE_FIND_FRAMEWORK}) + set(CMAKE_FIND_APPBUNDLE ${_PREVIOUS_CMAKE_FIND_APPBUNDLE}) + endif() endif() include(${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake) From 19f8a71b2331be9726aa018d28cd89681cc635af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 15 Dec 2022 09:36:33 -0500 Subject: [PATCH 22/23] Proposing to remove Findminizip module since external minizip-ng build need to be done with the same option as the internal build. Otherwise, linking and symbols issues are going to happend if the other libraries are not linked in correctly. It is going to simplify the maintainability of OCIO. 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 | 232 +++++++++++------------ share/cmake/modules/Findminizip.cmake | 192 ------------------- 2 files changed, 111 insertions(+), 313 deletions(-) delete mode 100644 share/cmake/modules/Findminizip.cmake diff --git a/share/cmake/modules/Findminizip-ng.cmake b/share/cmake/modules/Findminizip-ng.cmake index c5486e5024..51513a9ee7 100644 --- a/share/cmake/modules/Findminizip-ng.cmake +++ b/share/cmake/modules/Findminizip-ng.cmake @@ -3,12 +3,6 @@ # # 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 @@ -119,14 +113,18 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) # Library name doesn't change in debug. # Lib names to search for. - set(_minizip-ng_LIB_NAMES libminizip-ng minizip-ng) + # Search for "minizip" since the library could be named "minizip" if it was built + # with MZ_COMPAT=ON. + set(_minizip-ng_LIB_NAMES libminizip-ng minizip-ng libminizip minizip) if(minizip-ng_STATIC_LIBRARY) # Looking for both "lib" prefix and CMAKE_STATIC_LIBRARY_PREFIX. # Prefer static lib names. set(_minizip-ng_STATIC_LIB_NAMES "libminizip-ng${CMAKE_STATIC_LIBRARY_SUFFIX}" - "${CMAKE_STATIC_LIBRARY_PREFIX}minizip-ng${CMAKE_STATIC_LIBRARY_SUFFIX}") + "${CMAKE_STATIC_LIBRARY_PREFIX}minizip-ng${CMAKE_STATIC_LIBRARY_SUFFIX}" + "libminizip${CMAKE_STATIC_LIBRARY_SUFFIX}" + "${CMAKE_STATIC_LIBRARY_PREFIX}minizip${CMAKE_STATIC_LIBRARY_SUFFIX}") endif() # Find library @@ -176,128 +174,120 @@ if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) ) endif() -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) +############################################################################### +### Create target +if(NOT TARGET MINIZIP::minizip-ng) + add_library(MINIZIP::minizip-ng UNKNOWN IMPORTED GLOBAL) + set(_minizip-ng_TARGET_CREATE TRUE) endif() -if(NOT minizip_FOUND AND NOT TARGET MINIZIP::minizip) - ############################################################################### - ### Create target - - 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 OCIO_INSTALL_EXT_PACKAGES 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 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} - ) +############################################################################### +### Install package from source ### + +if(NOT minizip-ng_FOUND AND OCIO_INSTALL_EXT_PACKAGES 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 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} + ) - if(CMAKE_TOOLCHAIN_FILE) - set(minizip-ng_CMAKE_ARGS - ${minizip-ng_CMAKE_ARGS} -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}) - endif() + 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}") + 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() + 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() + 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() - # 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}) + + 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() + add_dependencies(MINIZIP::minizip-ng minizip-ng_install) + message(STATUS "Installing minizip-ng: ${minizip-ng_LIBRARY} (version \"${minizip-ng_VERSION}\")") endif() ############################################################################### diff --git a/share/cmake/modules/Findminizip.cmake b/share/cmake/modules/Findminizip.cmake deleted file mode 100644 index eeada367f8..0000000000 --- a/share/cmake/modules/Findminizip.cmake +++ /dev/null @@ -1,192 +0,0 @@ -# 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 ### - -# BUILD_TYPE_DEBUG variable is currently set in one of the OCIO's CMake files. -# Now that some OCIO's find module are installed with the library itself (with static build), -# a consumer app don't have access to the variables set by an OCIO's CMake files. Therefore, some -# OCIO's find modules must detect the build type by itselves. -set(BUILD_TYPE_DEBUG OFF) -if(CMAKE_BUILD_TYPE MATCHES "[Dd][Ee][Bb][Uu][Gg]") - set(BUILD_TYPE_DEBUG ON) -endif() - -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 - ) - - # Minizip uses prefix "lib" on all platform by default. - # Library name doesn't change in debug. - - # Lib names to search for. - set(_minizip_LIB_NAMES libminizip minizip) - - if(minizip_STATIC_LIBRARY) - # Looking for both "lib" prefix and CMAKE_STATIC_LIBRARY_PREFIX. - # Prefer static lib names. - set(_minizip_STATIC_LIB_NAMES - "libminizip${CMAKE_STATIC_LIBRARY_SUFFIX}" - "${CMAKE_STATIC_LIBRARY_PREFIX}minizip${CMAKE_STATIC_LIBRARY_SUFFIX}") - 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 - if(minizip_INCLUDE_DIR) - list(GET minizip_INCLUDE_DIR 0 _minizip_INCLUDE_DIR) - if(EXISTS "${_minizip_INCLUDE_DIR}/mz.h") - set(_minizip_CONFIG "${_minizip_INCLUDE_DIR}/mz.h") - endif() - endif() - - if(_minizip_CONFIG) - file(STRINGS "${_minizip_CONFIG}" _minizip_VER_SEARCH - REGEX "^[ \t]*#define[ \t]+MZ_VERSION[ \t]+\\(\"[.0-9]+\"\\).*$") - if(_minizip_VER_SEARCH) - string(REGEX REPLACE ".*#define[ \t]+MZ_VERSION[ \t]+\\(\"([.0-9]+)\"\\).*" - "\\1" minizip_VERSION "${_minizip_VER_SEARCH}") - endif() - elseif(PC_minizip_FOUND) - set(minizip_VERSION "${PC_minizip_VERSION}") - endif() - 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 From a96046727c52c8930a626b9212de09da2f398489 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drik=20Fuoco?= Date: Thu, 15 Dec 2022 10:02:33 -0500 Subject: [PATCH 23/23] Removing findminizip.cmake from the install since it does not exist anymore. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Cédrik Fuoco --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6e15bba61..3911a154ce 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -344,7 +344,6 @@ if (NOT BUILD_SHARED_LIBS) ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findexpat.cmake ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/FindImath.cmake ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findpystring.cmake - ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip.cmake ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findminizip-ng.cmake ${CMAKE_CURRENT_LIST_DIR}/share/cmake/modules/Findyaml-cpp.cmake DESTINATION ${OCIO_CUSTOM_FIND_MODULE_DIR}