Skip to content

Commit

Permalink
deps: Add build recipe for PNG (AcademySoftwareFoundation#4423)
Browse files Browse the repository at this point in the history
As requested in AcademySoftwareFoundation#4387.

---------

Signed-off-by: Zach Lewis <[email protected]>
Signed-off-by: Larry Gritz <[email protected]>
Signed-off-by: zachlewis <[email protected]>
Co-authored-by: Larry Gritz <[email protected]>
  • Loading branch information
zachlewis and lgritz committed Nov 9, 2024
1 parent 3b29190 commit 79f442f
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/cmake/add_oiio_plugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
9 changes: 8 additions & 1 deletion src/cmake/build_Freetype.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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

Expand Down
67 changes: 67 additions & 0 deletions src/cmake/build_PNG.cmake
Original file line number Diff line number Diff line change
@@ -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 ()
5 changes: 5 additions & 0 deletions src/cmake/externalpackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/ico.imageio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/libOpenImageIO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/png.imageio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/png.imageio/png_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#pragma once

#include <png.h>
#include <libpng16/png.h>
#include <zlib.h>

#include <OpenImageIO/Imath.h>
Expand Down

0 comments on commit 79f442f

Please sign in to comment.