From b7ced079ae59ccd62c12783b2453b521b57b18be Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Tue, 13 Sep 2022 23:22:16 +0300 Subject: [PATCH] cmake: Add library dependencies in Config.cmake.in when building static 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? --- src/cmake/Config.cmake.in | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cmake/Config.cmake.in b/src/cmake/Config.cmake.in index 9fff123a35..4d87192d24 100644 --- a/src/cmake/Config.cmake.in +++ b/src/cmake/Config.cmake.in @@ -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)