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_Freetype.cmake b/src/cmake/build_Freetype.cmake index ff70e7f18f..8804a7487b 100644 --- a/src/cmake/build_Freetype.cmake +++ b/src/cmake/build_Freetype.cmake @@ -17,6 +17,12 @@ set_cache (Freetype_BUILD_SHARED_LIBS OFF string (MAKE_C_IDENTIFIER ${Freetype_BUILD_VERSION} Freetype_VERSION_IDENT) +# 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" ) ) + set (_freetype_EXTRA_CMAKE_ARGS -DFT_DISABLE_PNG=ON ) +endif () + build_dependency_with_cmake(Freetype VERSION ${Freetype_BUILD_VERSION} GIT_REPOSITORY ${Freetype_GIT_REPOSITORY} @@ -25,7 +31,8 @@ build_dependency_with_cmake(Freetype -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 diff --git a/src/cmake/build_PNG.cmake b/src/cmake/build_PNG.cmake new file mode 100644 index 0000000000..3d89c39cb0 --- /dev/null +++ b/src/cmake/build_PNG.cmake @@ -0,0 +1,67 @@ +# 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) +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=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 + ) + + +set (PNG_REFIND FALSE) +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 + ) + +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) +endif () 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