Nekomiya Kasane
Nekomiya Kasane

Reputation: 113

How to use pkg-config with vcpkg and cmake?

I'm working on a cmake project with vcpkg. After running vcpkg install mesa[*], I got an output:

mesa provides pkg-config modules:

    # Mesa EGL Library
    egl

    # Mesa OpenGL ES 1.1 CM library
    glesv1_cm

    # Mesa OpenGL ES 2.0 library
    glesv2

    # Mesa Off-screen Rendering Library
    osmesa

I know I need to ask cmake to find pkg-config first, then let pkg-config to find osmesa.pc, but how can I achieve this while avoiding absolute paths?

I tried

find_package(PkgConfig REQUIRED)

pkg_search_module(MESA_OSMESA REQUIRED osmesa)

but get an error

CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Preview/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/FindPkgConfig.cmake:906 (message):
1> [CMake]   None of the required 'osmesa' found

Upvotes: 2

Views: 813

Answers (1)

Bowie Owens
Bowie Owens

Reputation: 2976

There is now a package in vcpkg that installs a pkg-config compatible program. You can add pkgconf to your list of vcpkg dependencies as you would any other dependency.

https://vcpkg.io/en/package/pkgconf

I'm using manifest mode so my vcpkg.json file looks like:

{
  "name": "c",
  "builtin-baseline":"9a6da16845eca8d6ed70be416c1acbd206894c7f",
  "version": "1.0.0",
  "dependencies": [
    "boost-container",
    "boost-flyweight",
    { "name":"boost-locale", "features":["icu"]},
    "catch2",
    "fmt",
    "icu",
    "ms-gsl",
    "nanodbc",
    "pkgconf",
    "pybind11",
    "rapidcsv",
    "spdlog",
    "sqlite3"
  ]
}

Upvotes: 0

Related Questions