Vcpkg: How do I use libraries that do not have a helper text after installation

Created on 13 Nov 2019  路  2Comments  路  Source: microsoft/vcpkg

This has confused me for a while and didn't find any better solution so I put it here:
For some packages, after installation, there's a helper text like:

 The package leveldb:x64-windows provides CMake targets:
 find_package(leveldb CONFIG REQUIRED)
 target_link_libraries(main PRIVATE leveldb::leveldb)

But for some, nanogui as an example, there isn't any...
Using find_package(nanogui REQUIRED) will result a cmake error of cannot finding the nanoguiConfig.cmake file.
Before reporting a bug (because I don't know if it is), what is the general way of finding how to use such libraries?

related question:
https://github.com/microsoft/vcpkg/issues/8933

question

Most helpful comment

Hi @xarthurx,

Not all the libraries in vcpkg provide find_package support, this is because, providing said support is not automatic.

In order for find_package to work, either:

  • a <package>Config.cmake file must exist (find_package(<pkg> CONFIG))
  • or a Find<Package>.cmake file must exist (find_package(<pkg> MODULE)).

These files are used by CMake to find and link the libraries properly. CMake is able to generate a <pkg>Config.cmake file when building a library, but to do so, the appropriate CMake commands must be used in the library's CMakeLists.txt. And in some cases, library authors do not enable this integration at all. There's also the case of libraries that are not built with CMake which will obviously lack the support.

In vcpkg we provide find_package support for libraries where the author has enabled it, and we also accept Pull Requests that patch libraries to provide find_package support (we are also considering eventually adding a feature to vcpkg that will generate these integration files automatically for every library).

Now, in regards to your problem, for cases where find_package is not available, you can use:

Before reporting a bug (because I don't know if it is), what is the general way of finding how to use such libraries?

1) The best way is to check the library's documentation.

2) CMake ships with a bunch of Find<package>.cmake modules for popular libraries like boost, opengl, png, python, zlib, etc. (e.g.: find_package(ZLIB MODULE REQUIRED) should find zlib). You can find the list in CMake's documentation: https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules.

3) Find an open source Find<package>.cmake module online (or write your own).

4) Modify the library's build-system to produce configuration files that you can use in your project (and then submit your patches upstream so everyone can enjoy CMake integration 馃槃).

I hope this information helps you, let us know if you have any more questions.

All 2 comments

Hi @xarthurx,

Not all the libraries in vcpkg provide find_package support, this is because, providing said support is not automatic.

In order for find_package to work, either:

  • a <package>Config.cmake file must exist (find_package(<pkg> CONFIG))
  • or a Find<Package>.cmake file must exist (find_package(<pkg> MODULE)).

These files are used by CMake to find and link the libraries properly. CMake is able to generate a <pkg>Config.cmake file when building a library, but to do so, the appropriate CMake commands must be used in the library's CMakeLists.txt. And in some cases, library authors do not enable this integration at all. There's also the case of libraries that are not built with CMake which will obviously lack the support.

In vcpkg we provide find_package support for libraries where the author has enabled it, and we also accept Pull Requests that patch libraries to provide find_package support (we are also considering eventually adding a feature to vcpkg that will generate these integration files automatically for every library).

Now, in regards to your problem, for cases where find_package is not available, you can use:

Before reporting a bug (because I don't know if it is), what is the general way of finding how to use such libraries?

1) The best way is to check the library's documentation.

2) CMake ships with a bunch of Find<package>.cmake modules for popular libraries like boost, opengl, png, python, zlib, etc. (e.g.: find_package(ZLIB MODULE REQUIRED) should find zlib). You can find the list in CMake's documentation: https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules.

3) Find an open source Find<package>.cmake module online (or write your own).

4) Modify the library's build-system to produce configuration files that you can use in your project (and then submit your patches upstream so everyone can enjoy CMake integration 馃槃).

I hope this information helps you, let us know if you have any more questions.

@vicroms Hi, thank you so much for the detailed answer!
This is reeeeeeeeeeeeeeeeeally what I need and didn't know!

vcpkg is really a great piece of work!

Was this page helpful?
0 / 5 - 0 ratings