From 06a838a1507e8ce1643e54a91a6e32c920b87410 Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Wed, 30 Oct 2024 16:00:46 -0400 Subject: [PATCH 1/5] deps(PNG): Add build recipe Signed-off-by: Zach Lewis --- src/cmake/build_PNG.cmake | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/cmake/build_PNG.cmake diff --git a/src/cmake/build_PNG.cmake b/src/cmake/build_PNG.cmake new file mode 100644 index 0000000000..ec6b293864 --- /dev/null +++ b/src/cmake/build_PNG.cmake @@ -0,0 +1,54 @@ +# Copyright Contributors to the OpenImageIO project. +# SPDX-License-Identifier: Apache-2.0 +# https://github.com/AcademySoftwareFoundation/OpenImageIO + +###################################################################### +# PNG by hand! +###################################################################### + +set_cache (PNG_BUILD_VERSION 1.6.44 "PNG version for local builds") +set (PNG_GIT_REPOSITORY "https://github.com/glennrp/libpng") +set (PNG_GIT_TAG "v${PNG_BUILD_VERSION}") + +set_cache (PNG_BUILD_SHARED_LIBS ${LOCAL_BUILD_SHARED_LIBS_DEFAULT} + DOC "Should execute a local PNG build, if necessary, build shared libraries" ADVANCED) + +string (MAKE_C_IDENTIFIER ${PNG_BUILD_VERSION} PNG_VERSION_IDENT) + +unset (PNG_FOUND) +unset (PNG_LIBRARIES) +unset (PNG_INCLUDE_DIRS) +unset (PNG_INCLUDE_DIR) + +build_dependency_with_cmake (PNG + VERSION ${PNG_BUILD_VERSION} + GIT_REPOSITORY ${PNG_GIT_REPOSITORY} + GIT_TAG ${PNG_GIT_TAG} + CMAKE_ARGS + -D PNG_SHARED=${PNG_BUILD_SHARED_LIBS} + -D PNG_STATIC=ON + -D PNG_EXECUTABLES=OFF + -D PNG_TESTS=OFF + -D PNG_FRAMEWORK=OFF + -D CMAKE_POSITION_INDEPENDENT_CODE=ON + -D CMAKE_INSTALL_LIBDIR=lib + ) + + +set (PNG_REFIND FALSE) +set (PNG_REFIND_VERSION ${PNG_BUILD_VERSION}) + + +set (PNG_REFIND_ARGS EXACT REQUIRED) + + +if (PNG_BUILD_VERSION VERSION_GREATER 1.6.43) + list (APPEND PNG_REFIND_ARGS CONFIG) +endif () + + +find_package(PNG ${PNG_REFIND_VERSION} ${PNG_REFIND_ARGS}) + +if (PNG_BUILD_SHARED_LIBS) + install_local_dependency_libs (PNG png) +endif () From 144f201ed97026998a53fce4b2da37a8445cbf73 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Sun, 3 Nov 2024 20:14:20 -0800 Subject: [PATCH 2/5] build: Improve finding locally built PNG * Adjustments to lock down a better ordering of include directories. * Always prefer a static library png when available, and when building local PNG, for sure only build the static version. * Give the symbols an "oiio" prefix so they can't link against symbols in the wrong library. * Give a bunch of extra hints about the directory locations and config location of the local build to make extra sure it's the one found and chosen. This is still not perfect. It's plagued by one remaining nasty problem: If there is a too-old version of libpng installed in a system area, although we will diligently build newer local copy, it's extremely hard to ensure that it doesn't accidentally get the headers corresponding to the old version, because OTHER dependencies may be correctly found in the system area and therefore put it in the include path where it will be found rather than the one we intend. I don't know how to fix this robustly. For now, it remains the case that the dependency self-build works very well if the dependency is missing, but can be hit-or-miss if there are headers for a too-old version installed in the same area as other dependency headers we use, since it's very hard to control which end up earlier in the include path. But at least for now, this setup works fine for all of our CI cases. Signed-off-by: Larry Gritz --- src/cmake/add_oiio_plugin.cmake | 2 +- src/cmake/build_PNG.cmake | 19 ++++++++++++++++--- src/cmake/externalpackages.cmake | 5 +++++ src/ico.imageio/CMakeLists.txt | 6 ++++-- src/libOpenImageIO/CMakeLists.txt | 2 +- src/png.imageio/CMakeLists.txt | 6 ++++-- src/png.imageio/png_pvt.h | 2 +- 7 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/cmake/add_oiio_plugin.cmake b/src/cmake/add_oiio_plugin.cmake index d65ac62c43..a1d87addfe 100644 --- a/src/cmake/add_oiio_plugin.cmake +++ b/src/cmake/add_oiio_plugin.cmake @@ -70,7 +70,7 @@ macro (add_oiio_plugin) target_compile_definitions (${_plugin_NAME} PRIVATE ${_plugin_DEFINITIONS} OpenImageIO_EXPORTS) - target_include_directories (${_plugin_NAME} PRIVATE ${_plugin_INCLUDE_DIRS}) + target_include_directories (${_plugin_NAME} BEFORE PRIVATE ${_plugin_INCLUDE_DIRS}) target_link_libraries (${_plugin_NAME} PUBLIC OpenImageIO PRIVATE ${_plugin_LINK_LIBRARIES}) set_target_properties (${_plugin_NAME} PROPERTIES PREFIX "" FOLDER "Plugins") diff --git a/src/cmake/build_PNG.cmake b/src/cmake/build_PNG.cmake index ec6b293864..3d89c39cb0 100644 --- a/src/cmake/build_PNG.cmake +++ b/src/cmake/build_PNG.cmake @@ -19,19 +19,24 @@ unset (PNG_FOUND) unset (PNG_LIBRARIES) unset (PNG_INCLUDE_DIRS) unset (PNG_INCLUDE_DIR) +unset (PNG_VERSION_STRING) +unset (PNG_DEFINITIONS) +unset (PNG_VERSION) build_dependency_with_cmake (PNG VERSION ${PNG_BUILD_VERSION} GIT_REPOSITORY ${PNG_GIT_REPOSITORY} GIT_TAG ${PNG_GIT_TAG} CMAKE_ARGS - -D PNG_SHARED=${PNG_BUILD_SHARED_LIBS} + -D PNG_SHARED=OFF -D PNG_STATIC=ON -D PNG_EXECUTABLES=OFF -D PNG_TESTS=OFF + -D PNG_TOOLS=OFF -D PNG_FRAMEWORK=OFF -D CMAKE_POSITION_INDEPENDENT_CODE=ON -D CMAKE_INSTALL_LIBDIR=lib + -D PNG_PREFIX=oiio ) @@ -40,14 +45,22 @@ set (PNG_REFIND_VERSION ${PNG_BUILD_VERSION}) set (PNG_REFIND_ARGS EXACT REQUIRED) - +set (PNG_DIR ${PNG_LOCAL_INSTALL_DIR}/lib/cmake/PNG) +set (PNG_FIND_VERSION_EXACT ON) if (PNG_BUILD_VERSION VERSION_GREATER 1.6.43) list (APPEND PNG_REFIND_ARGS CONFIG) endif () +find_package(PNG ${PNG_REFIND_VERSION} ${PNG_REFIND_ARGS} + HINTS + ${PNG_LOCAL_INSTALL_DIR}/lib/cmake/PNG + ${PNG_LOCAL_INSTALL_DIR} + NO_DEFAULT_PATH + ) -find_package(PNG ${PNG_REFIND_VERSION} ${PNG_REFIND_ARGS}) +set (PNG_INCLUDE_DIRS ${PNG_LOCAL_INSTALL_DIR}/include) +include_directories(BEFORE ${PNG_INCLUDE_DIRS}) if (PNG_BUILD_SHARED_LIBS) install_local_dependency_libs (PNG png) diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index f8670a83f9..984d22d05f 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -120,6 +120,11 @@ endif () # we will continue building, but the related functionality will be disabled. checked_find_package (PNG VERSION_MIN 1.6.0) +if (TARGET PNG::png_static) + set (PNG_TARGET PNG::png_static) +elseif (TARGET PNG::PNG) + set (PNG_TARGET PNG::PNG) +endif () checked_find_package (Freetype VERSION_MIN 2.10.0 diff --git a/src/ico.imageio/CMakeLists.txt b/src/ico.imageio/CMakeLists.txt index 7423522689..31d205d536 100644 --- a/src/ico.imageio/CMakeLists.txt +++ b/src/ico.imageio/CMakeLists.txt @@ -2,9 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 # https://github.com/AcademySoftwareFoundation/OpenImageIO -if (TARGET PNG::PNG) +if (PNG_TARGET) add_oiio_plugin (icoinput.cpp icooutput.cpp - LINK_LIBRARIES PNG::PNG ZLIB::ZLIB) + INCLUDE_DIRS ${PNG_INCLUDE_DIRS} + DEFINITIONS ${PNG_DEFINITIONS} + LINK_LIBRARIES ${PNG_LIBRARIES} ${PNG_TARGET} ZLIB::ZLIB) else () message (WARNING "libpng not found, so ICO support will not work") set (format_plugin_definitions ${format_plugin_definitions} DISABLE_ICO=1 PARENT_SCOPE) diff --git a/src/libOpenImageIO/CMakeLists.txt b/src/libOpenImageIO/CMakeLists.txt index 1dd60922c7..e08e34a8bf 100644 --- a/src/libOpenImageIO/CMakeLists.txt +++ b/src/libOpenImageIO/CMakeLists.txt @@ -88,7 +88,7 @@ if (EMBEDPLUGINS) PRIVATE EMBED_PLUGINS=1 ${format_plugin_definitions}) - target_include_directories (OpenImageIO + target_include_directories (OpenImageIO BEFORE PRIVATE ${format_plugin_include_dirs}) # Organize the embedded plugins into source folders diff --git a/src/png.imageio/CMakeLists.txt b/src/png.imageio/CMakeLists.txt index 232bcbaea3..0cdeb41939 100644 --- a/src/png.imageio/CMakeLists.txt +++ b/src/png.imageio/CMakeLists.txt @@ -2,9 +2,11 @@ # SPDX-License-Identifier: Apache-2.0 # https://github.com/AcademySoftwareFoundation/OpenImageIO -if (TARGET PNG::PNG) +if (PNG_TARGET OR PNG_LIBRARIES) add_oiio_plugin (pnginput.cpp pngoutput.cpp - LINK_LIBRARIES PNG::PNG ZLIB::ZLIB) + INCLUDE_DIRS ${PNG_INCLUDE_DIRS} + DEFINITIONS ${PNG_DEFINITIONS} + LINK_LIBRARIES ${PNG_LIBRARIES} ${PNG_TARGET} ZLIB::ZLIB) else () message (WARNING "libpng not found, so PNG support will not work") set (format_plugin_definitions ${format_plugin_definitions} DISABLE_PNG=1 PARENT_SCOPE) diff --git a/src/png.imageio/png_pvt.h b/src/png.imageio/png_pvt.h index a4a96269a1..49dbd25e96 100644 --- a/src/png.imageio/png_pvt.h +++ b/src/png.imageio/png_pvt.h @@ -4,7 +4,7 @@ #pragma once -#include +#include #include #include From acf0d7ad5eb532690bd705301b6502aad95e455e Mon Sep 17 00:00:00 2001 From: Zach Lewis Date: Mon, 4 Nov 2024 12:24:17 -0500 Subject: [PATCH 3/5] build: disable PNG support in Freetype for MacOS / Arm64 Freetype seems to be having trouble linking PNG on MacOS when CMAKE_OSX_ARCHITECTURES = arm64. Signed-off-by: Zach Lewis --- src/cmake/build_Freetype.cmake | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/cmake/build_Freetype.cmake b/src/cmake/build_Freetype.cmake index ff70e7f18f..79bd61060d 100644 --- a/src/cmake/build_Freetype.cmake +++ b/src/cmake/build_Freetype.cmake @@ -17,15 +17,24 @@ set_cache (Freetype_BUILD_SHARED_LIBS OFF string (MAKE_C_IDENTIFIER ${Freetype_BUILD_VERSION} Freetype_VERSION_IDENT) +set( _freetype_CMAKE_ARGS + -D BUILD_SHARED_LIBS=${Freetype_BUILD_SHARED_LIBS} + -D CMAKE_POSITION_INDEPENDENT_CODE=ON + -D CMAKE_INSTALL_LIBDIR=lib +) + +# Conditionally disable support for PNG-compressed OpenType embedded bitmaps on Apple Silicon +# https://github.com/AcademySoftwareFoundation/OpenImageIO/pull/4423#issuecomment-2455034286 +if ( APPLE AND ( CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" ) ) + list( APPEND _freetype_CMAKE_ARGS -D FT_DISABLE_PNG=ON ) +endif () + build_dependency_with_cmake(Freetype VERSION ${Freetype_BUILD_VERSION} GIT_REPOSITORY ${Freetype_GIT_REPOSITORY} GIT_TAG ${Freetype_GIT_TAG} - CMAKE_ARGS - -D BUILD_SHARED_LIBS=${Freetype_BUILD_SHARED_LIBS} - -D CMAKE_POSITION_INDEPENDENT_CODE=ON - -D CMAKE_INSTALL_LIBDIR=lib - ) + CMAKE_ARGS ${_freetype_CMAKE_ARGS} +) # Set some things up that we'll need for a subsequent find_package to work From 9558aa23dc4e9fe1fc399ca709d0f8b1a797869e Mon Sep 17 00:00:00 2001 From: zachlewis Date: Tue, 5 Nov 2024 10:30:24 -0500 Subject: [PATCH 4/5] Update src/cmake/build_Freetype.cmake Co-authored-by: Larry Gritz Signed-off-by: zachlewis --- src/cmake/build_Freetype.cmake | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cmake/build_Freetype.cmake b/src/cmake/build_Freetype.cmake index 79bd61060d..3a67ec2249 100644 --- a/src/cmake/build_Freetype.cmake +++ b/src/cmake/build_Freetype.cmake @@ -33,7 +33,11 @@ build_dependency_with_cmake(Freetype VERSION ${Freetype_BUILD_VERSION} GIT_REPOSITORY ${Freetype_GIT_REPOSITORY} GIT_TAG ${Freetype_GIT_TAG} - CMAKE_ARGS ${_freetype_CMAKE_ARGS} + CMAKE_ARGS + -D BUILD_SHARED_LIBS=${Freetype_BUILD_SHARED_LIBS} + -D CMAKE_POSITION_INDEPENDENT_CODE=ON + -D CMAKE_INSTALL_LIBDIR=lib + ${_freetype_EXTRA_CMAKE_ARGS} ) # Set some things up that we'll need for a subsequent find_package to work From 97c070cd0a73ab21dc700ee67e87b1d64c3ee64d Mon Sep 17 00:00:00 2001 From: zachlewis Date: Tue, 5 Nov 2024 10:30:32 -0500 Subject: [PATCH 5/5] Update src/cmake/build_Freetype.cmake Co-authored-by: Larry Gritz Signed-off-by: zachlewis --- src/cmake/build_Freetype.cmake | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/cmake/build_Freetype.cmake b/src/cmake/build_Freetype.cmake index 3a67ec2249..8804a7487b 100644 --- a/src/cmake/build_Freetype.cmake +++ b/src/cmake/build_Freetype.cmake @@ -17,16 +17,10 @@ set_cache (Freetype_BUILD_SHARED_LIBS OFF string (MAKE_C_IDENTIFIER ${Freetype_BUILD_VERSION} Freetype_VERSION_IDENT) -set( _freetype_CMAKE_ARGS - -D BUILD_SHARED_LIBS=${Freetype_BUILD_SHARED_LIBS} - -D CMAKE_POSITION_INDEPENDENT_CODE=ON - -D CMAKE_INSTALL_LIBDIR=lib -) - # Conditionally disable support for PNG-compressed OpenType embedded bitmaps on Apple Silicon # https://github.com/AcademySoftwareFoundation/OpenImageIO/pull/4423#issuecomment-2455034286 if ( APPLE AND ( CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64" ) ) - list( APPEND _freetype_CMAKE_ARGS -D FT_DISABLE_PNG=ON ) + set (_freetype_EXTRA_CMAKE_ARGS -DFT_DISABLE_PNG=ON ) endif () build_dependency_with_cmake(Freetype