Skip to content

[openimageio] Configure failed when using openimageio #38065

@JackBoosY

Description

@JackBoosY

Operating system

All platform

Compiler

Not related to compiler

Steps to reproduce the behavior

1. ./vcpkg install openimageio[libraw]
2. Use openimageio in custom project.

Failure logs

CMake Error at D:/installed/x64-windows-static/share/openimageio/OpenImageIOTargets.cmake:71 (set_target_properties):
  The link interface of target "OpenImageIO::OpenImageIO" contains:

    lcms2::lcms2

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.

Additional context

I found this bug in my another PR #38034.
The description is port lcms target lcms2::lcms2 was not found. And this issue can only be reproduced in static build.
After analyzing the dependency relationship, I found this is caused by openimageio's feature libraw, which depends on port libraw, which depends on port lcms.
After reading the generated OpenimageIOConfig.cmake / OpenimageIOTargets.cmake:

  1. there is no find_package(lcms2 CONFIG) in the config.cmake file.
  2. target lcms2::lcms2 was found in the Targets.cmake file:
set_target_properties(OpenImageIO::OpenImageIO PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "OIIO_STATIC_DEFINE=1"
  INTERFACE_COMPILE_FEATURES "cxx_std_14"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${VCPKG_IMPORT_PREFIX}/include"
  INTERFACE_LINK_LIBRARIES "OpenImageIO::OpenImageIO_Util;...\$<\$<NOT:\$<CONFIG:DEBUG>>:${VCPKG_IMPORT_PREFIX}/lib/libraw_r.a>;\$<\$<CONFIG:DEBUG>:${VCPKG_IMPORT_PREFIX}/debug/lib/libraw_r.a>;...;\$<LINK_ONLY:lcms2::lcms2>;..."
)

So I checked the libraw generated config / targets cmake files:
In librawConfig.cmake:

...
if(true)
    if(1)
        find_dependency(lcms2 CONFIG)
    elseif(false)
        find_dependency(LCMS)
    endif()
endif()
...

In librawTargets.cmake:

# Create imported target libraw::raw
add_library(libraw::raw STATIC IMPORTED)

set_target_properties(libraw::raw PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "LIBRAW_NODLL"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/libraw"
  INTERFACE_LINK_LIBRARIES "m;lcms2::lcms2;..."
)

# Create imported target libraw::raw_r
add_library(libraw::raw_r STATIC IMPORTED)

set_target_properties(libraw::raw_r PROPERTIES
  INTERFACE_COMPILE_DEFINITIONS "LIBRAW_NODLL"
  INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/libraw"
  INTERFACE_LINK_LIBRARIES "m;lcms2::lcms2;..."
)

That's weird. We expected libraw find lcms2 first, then pass the found targets lcms2::lcms2 to openimageio's targets.cmake, which not executed.
In static build, the dependency's dependency target / library shouldn't be included since it's binary has already included into the dependency library.

So I consider there have some issues in this.

Edit:
In src/raw.imageio/CMakeLists.txt:

    add_oiio_plugin (rawinput.cpp
                     INCLUDE_DIRS ${LibRaw_INCLUDE_DIR}
                     LINK_LIBRARIES ${LibRaw_r_LIBRARIES}
                     DEFINITIONS "-DUSE_LIBRAW=1" ${LibRaw_r_DEFINITIONS})

And in config-TRIPLET-out.log:

-- Found LibRaw 0.21.2 
--     LibRaw_INCLUDE_DIR = J:/vcpkg_commit/vcpkg/installed/x64-windows-static/include/libraw
--     LibRaw_LIBRARIES = optimized;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/lib/manual-link/raw.lib;debug;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/debug/lib/manual-link/rawd.lib;optimized;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/lib/jasper.lib;debug;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/debug/lib/jasperd.lib;optimized;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/lib/jpeg.lib;debug;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/debug/lib/jpeg.lib;lcms2::lcms2;optimized;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/lib/zlib.lib;debug;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/debug/lib/zlibd.lib
--     LibRaw_r_LIBRARIES = optimized;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/lib/raw_r.lib;debug;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/debug/lib/raw_rd.lib;optimized;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/lib/jasper.lib;debug;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/debug/lib/jasperd.lib;optimized;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/lib/jpeg.lib;debug;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/debug/lib/jpeg.lib;lcms2::lcms2;optimized;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/lib/zlib.lib;debug;J:/vcpkg_commit/vcpkg/installed/x64-windows-static/debug/lib/zlibd.lib

However, libraw's usage should be

    find_package(libraw CONFIG REQUIRED)
    # non-thread-safe
    target_link_libraries(main PRIVATE libraw::raw)
    # thread-safe
    target_link_libraries(main PRIVATE libraw::raw_r)

So I think this is why the issue happened.
Trying to use config mode instead.

Metadata

Metadata

Assignees

Labels

category:port-bugThe issue is with a library, which is something the port should already support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions