All I can say about those commands right now is pkg_search_module has some odd usage, where I have to write the dependency that I would like to have two times. instead of just once like in find_package
pkg_search_module(ZLIB REQUIRED zlib)
#seriously two times zlib and once in only capital case‽
find_package(ZLIB)
#much cleaner but for some odd reason find_package does not work all the time
pkg_search_module
uses the pkg-config
tool to determine the location of the requested library. This is mostly useful on systems where pkg-config
is already in use, so you do not need to replicate all the information for CMake. Note that this approach has potential portability issues, since it requires pkg-config
to be setup correctly on the build machine.
find_package
on the other hand is CMake's very own mechanism for solving the same problem. For this to work you either need a CMake find script for the requested library (CMake already ships with a couple of those, but you can easily write your own) or alternatively a package config script provided by the requested library itself. In either case you might have to adjust your CMAKE_MODULE_PATH
for CMake to be able to find the respective script.
The choice which one to use is quite simple:
pkg_search_module
if you want to exploit synergies with pkg-config
. In particular, note that it is possible to implement a find script using pkg_search_module
as one method of obtaining the required information.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With