Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between find_package and pkg_search_module

Tags:

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
like image 461
Arne Avatar asked Sep 21 '14 14:09

Arne


1 Answers

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:

  • Always prefer package config scripts, if provided by the library.
  • Use find scripts as a fallback for libraries that are not aware of CMake.
  • Use 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.
like image 162
ComicSansMS Avatar answered Oct 22 '22 02:10

ComicSansMS