Skip to content

Commit

Permalink
cmake: Add library dependencies in Config.cmake.in when building stat…
Browse files Browse the repository at this point in the history
…ic (AcademySoftwareFoundation#3552)

This fixes builds in projects that compile OpenImageIO as static
libraries and don't themselves depend on the image libraries used by
OpenImageIO such as PNG, JPEG or TIFF.

When OpenImageIO is built as a static library its targets have e.g.
PNG::PNG among INTERFACE_LINK_LIBRARIES. If the including project does
not itself depend on PNG, the following error would be observed:

Target "<...>" links to target "PNG::PNG" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
  • Loading branch information
p12tic authored and lgritz committed Sep 18, 2022
1 parent 8c40efd commit 9900536
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/cmake/Config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ if (NOT @OPENIMAGEIO_CONFIG_DO_NOT_FIND_IMATH@ AND NOT OPENIMAGEIO_CONFIG_DO_NOT
endif ()
endif ()

if (NOT @BUILD_SHARED_LIBS@)
# This is required in static library builds, as e.g. PNG::PNG appears among
# INTERFACE_LINK_LIBRARIES. If the project does not know about PNG target, it will cause
# configuration error about unknown targets being linked in.
find_dependency(TIFF)
if (@JPEG_FOUND@)
find_dependency(JPEG)
endif()
if (@PNG_FOUND@)
find_dependency(PNG)
endif()
endif ()

# Compute the installation prefix relative to this file. Note that cmake files are installed
# to ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} (see OIIO_CONFIG_INSTALL_DIR)
get_filename_component(_CURR_INSTALL_LIBDIR "${CMAKE_CURRENT_LIST_DIR}/../../" ABSOLUTE)
Expand Down

0 comments on commit 9900536

Please sign in to comment.