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
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:
<package>Config.cmake file must exist (find_package(<pkg> CONFIG))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:
find_library to search for the library files (.lib) and use taget_link_libraries to link them, andfind_path to search for header files and include them with target_include_directories.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!
Most helpful comment
Hi @xarthurx,
Not all the libraries in vcpkg provide
find_packagesupport, this is because, providing said support is not automatic.In order for
find_packageto work, either:<package>Config.cmakefile must exist (find_package(<pkg> CONFIG))Find<Package>.cmakefile 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.cmakefile when building a library, but to do so, the appropriate CMake commands must be used in the library'sCMakeLists.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_packagesupport for libraries where the author has enabled it, and we also accept Pull Requests that patch libraries to providefind_packagesupport (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_packageis not available, you can use:find_libraryto search for the library files (.lib) and usetaget_link_librariesto link them, andfind_pathto search for header files and include them withtarget_include_directories.1) The best way is to check the library's documentation.
2) CMake ships with a bunch of
Find<package>.cmakemodules 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>.cmakemodule 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.