Package vs Library

assignment_operator picture assignment_operator · May 23, 2014 · Viewed 10k times · Source

I've just started working with CMake and I noticed that they have both a find_package and a find_library. And this confuses me. Can somebody explain the difference between a package and a library in the world of programming? Or, in the world of CMake?

Appreciate it, guys!

Answer

lrineau picture lrineau · May 23, 2014

Imagine you want to use zlib in your project, you need to find the header file zlib.h, and the library libz.so (on Linux). You can use the low-level cmake commands find_path and find_library to find them, or you can use find_package(ZLIB). The later command will try to find out all what is necessary to use zlib. It can be extra macro definitions, or dependencies.

Update, more detail about find_package: when the CMake command find_package(SomeThing) is called, as says the documentation, there are two possibility: the module mode (that searches for a file FindSomeThing.cmake), or the config mode (that searches for a file named SomeThingConfig.cmake). For ZLIB, there is a module named FindZLIB, shipped with CMake itself (on my Linux machine that is the file /usr/share/cmake/Modules/FindZLIB.cmake). That module is a CMake script that uses the CMake API to search for ZLIB files in default locations, or ask the user for the location if it cannot be found automatically.