microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.26k stars 6.41k forks source link

[lcms] find_package with version failed #34675

Closed miyanyan closed 1 year ago

miyanyan commented 1 year ago

Describe the bug I got an version error when use:

find_package(lcms2 2.14 CONFIG REQUIRED)

or

find_package(lcms 2.14 CONFIG REQUIRED) 

Environment

To Reproduce Steps to reproduce the behavior:

  1. ./vcpkg install lcms
  2. See error Repro code when
    [CMake] CMake Error at D:/github/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (_find_package):
    [CMake]   Could not find a configuration file for package "lcms2" that is compatible
    [CMake]   with requested version "2.14".
    [CMake] 
    [CMake]   The following configuration files were considered but not accepted:
    [CMake] 
    [CMake]     D:/github/vcpkg/installed/x64-windows/share/lcms2/lcms2Config.cmake, version: unknown
    [CMake] 
    [CMake] Call Stack (most recent call first):
    [CMake]   testOCIO/CMakeLists.txt:2 (find_package)
    [CMake] -- Configuring incomplete, errors occurred!

    Expected behavior find exact version of lcms

Additional context I find that in port/lcms/CMakeLists.txt:

# Generate pkg-config file
SET(PACKAGE "lcms2")
# Read VERSION from file configure
file(READ "${CMAKE_CURRENT_LIST_DIR}/configure" lcms2_configure)
string(REGEX MATCH "PACKAGE_VERSION='(([0-9]+)\\.([0-9]+))'" _ ${lcms2_configure})
set(VERSION "${CMAKE_MATCH_1}")  # <-- set version here
SET(prefix "${CMAKE_INSTALL_PREFIX}")
SET(exec_prefix "\${prefix}")
SET(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
SET(includedir "\${prefix}/include")
CONFIGURE_FILE(lcms2.pc.in "${PROJECT_BINARY_DIR}/lcms2.pc" @ONLY)

I don't how cmake version works, maybe should set some vars like PACKAGE_FIND_VERSION

jimwang118 commented 1 year ago

You can control the port version that needs to be called through the manifest mode.

miyanyan commented 1 year ago

You can control the port version that needs to be called through the manifest mode.

I got this error when I wanted to update opencolorio to v2.3.0, the CMakeLists.txt of opencolorio v2.3.0 changed find package function, so if version: unknown is allowed in vcpkg, I can modify share/cmake/modules/FindExtPackages.cmake like this: from

# ocio_handle_dependency will call find_package
if(OCIO_BUILD_APPS)
    # NOTE: Depending of the compiler version lcms2 2.2 does not compile with 
    # C++17 so, if you change the lcms2 version update the code to compile 
    # lcms2 and dependencies with C++17 or higher i.e. remove the cap of C++ 
    # version in Findlcms2.cmake and src/apps/ociobakelut/CMakeLists.txt.

    # lcms2
    # https://github.com/mm2/Little-CMS
    ocio_handle_dependency(  lcms2 REQUIRED ALLOW_INSTALL
                             MIN_VERSION 2.2
                             RECOMMENDED_VERSION 2.2
                             RECOMMENDED_VERSION_REASON "Latest version tested with OCIO")
endif()

to

if(OCIO_BUILD_APPS)
    # NOTE: Depending of the compiler version lcms2 2.2 does not compile with 
    # C++17 so, if you change the lcms2 version update the code to compile 
    # lcms2 and dependencies with C++17 or higher i.e. remove the cap of C++ 
    # version in Findlcms2.cmake and src/apps/ociobakelut/CMakeLists.txt.

    # lcms2
    # https://github.com/mm2/Little-CMS
    ocio_handle_dependency(  lcms2 REQUIRED ALLOW_INSTALL )
endif()
dg0yt commented 1 year ago

Who provides an lcms2 cmake package with version information?

The CMake config provided by vcpkg is unofficial, even if not decorated this way, and doesn't offer version information. The port comes with its own CMakeLists.txt...

There is a new release 2.15 which features a meson build system. vcpkg should switch, and maybe there is an official cmake config generated now.

Last not least most providers chose the port name lcms2 (and lcms for versions < 2), and I always stumble over vcpkg not using the common name. Maybe time to switch? https://repology.org/project/lcms/versions

miyanyan commented 1 year ago

yeah, the port name also makes me confused...

jimwang118 commented 1 year ago

If you use the classic find_package() to find a library, only the latest version of the library will be found in vcpkg. If you want to use a fixed version, you can use it in manifest mode. If the port name is inconsistent with the upstream port name, we will modify it as much as possible to make the name consistent.

jimwang118 commented 1 year ago

Thanks for posting this issue. Please reopen this issue if this is still a problem for you.