cmakevcpkg

vcpkg: classic vs manifest mode


I am trying to understand how to use the classic mode of vcpkg (Visual Studio BuildTools 2022 + standalone installation).

I've used DCMTK as reference cmake project. Since it does not contains a vcpkg.json I added one:

> cat .\vcpkg.json
{
  "name": "dcmtk",
  "dependencies": [
    {
      "name": "libpng"
    }
  ]
}

Followed by:

  variables:
    VCPKG_DEFAULT_TRIPLET: x64-windows-static
  script:
    - cmake -S . -B build1
      -GNinja -DCMAKE_BUILD_TYPE=Release
      -DDCMTK_USE_FIND_PACKAGE_WIN_DEFAULT=TRUE
      -DVCPKG_MANIFEST_MODE=ON
      -DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake

I can see in my gitlab output:

-- Info: DCMTK PNG support will be enabled

Now I change into:

  variables:
    VCPKG_DEFAULT_TRIPLET: x64-windows-static
  script:
    - rm vcpkg.json
    - vcpkg install libpng
    - cmake -S . -B build2
      -GNinja -DCMAKE_BUILD_TYPE=Release
      -DDCMTK_USE_FIND_PACKAGE_WIN_DEFAULT=TRUE
      -DVCPKG_MANIFEST_MODE=OFF
      -DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake

I now see:

-- Warning: PNG support will be disabled because libpng was not found.

What did I misunderstood from the classic mode documentation ? What step am I missing so that it behave as the manifest mode.


Solution

  • The documentation is rather evasive:

    VCPKG_TARGET_TRIPLET This setting controls the triplet vcpkg will install and consume libraries from.

    If unset, vcpkg will automatically detect an appropriate default triplet given the current compiler settings. If you change this CMake variable, you must delete your cache and reconfigure.

    It does not describe case where it fails to detect an appropriate default...which seems to be my case here.

    Solution is simply:

      variables:
        VCPKG_DEFAULT_TRIPLET: x64-windows-static
      script:
        - rm vcpkg.json
        - vcpkg install libpng
        - cmake -S . -B build2
          -GNinja -DCMAKE_BUILD_TYPE=Release
          -DVCPKG_TARGET_TRIPLET=x64-windows-static ### Important ###
          -DDCMTK_USE_FIND_PACKAGE_WIN_DEFAULT=TRUE
          -DCMAKE_TOOLCHAIN_FILE=C:/dev/vcpkg/scripts/buildsystems/vcpkg.cmake
    

    For reference:


    I was able to diagnose the failure to find png using the debug mode of cmake cmake --debug-find:

    Excerpt:

    CMake Debug Log at C:/Program Files/CMake/share/cmake-3.27/Modules/FindZLIB.cmake:122 (find_path):
      find_path called with the following settings:
    
        VAR: ZLIB_INCLUDE_DIR
        NAMES: "zlib.h"
        Documentation: Path to a file.
        Framework
          Only Search Frameworks: 0
          Search Frameworks Last: 1
          Search Frameworks First: 0
        AppBundle
          Only Search AppBundle: 0
          Search AppBundle Last: 1
          Search AppBundle First: 0
        CMAKE_FIND_USE_CMAKE_PATH: 1
        CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
        CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
        CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
        CMAKE_FIND_USE_INSTALL_PREFIX: 1
    
      find_path considered the following locations:
    
        C:/dev/vcpkg/installed/x64-windows/include/include/zlib.h
        C:/dev/vcpkg/installed/x64-windows/include/zlib.h
        C:/dev/vcpkg/installed/x64-windows/include/zlib.h
        [...]