[CMake] What is the recommended ways to find libraries

Oto Petřík oto.petrik at gmail.com
Wed Jun 17 13:18:34 EDT 2015


Hi,

> Let's say my project wants to depend on a library PKG1 (here PKG1 can
> be MPFR, MPC, PTHREAD, GMP, BZIP2, you name it). Let's say the library
> is installed in $PKG1/include, $PKG1/lib, alternatively, all my
> dependencies are installed in $HASHSTACK/include and $HASHSTACK/lib,
> or perhaps they are installed system wide.

> Perhaps I am missing the official recommendation regarding the above,
> so that's why I am asking here. But if there is none, then I think the
> current state is unsatisfactory.

you may be looking for CMAKE_PREFIX_PATH
(http://www.cmake.org/cmake/help/v3.2/variable/CMAKE_PREFIX_PATH.html)

cmake -DCMAKE_PREFIX_PATH=$HOME/built-libs/gmp;$HOME/built-libs/arb;$HOME/built-libs/otherdependencies
(or have a script that sets CMAKE_PREFIX_PATH environment variable)

works with find_module, find_file, find_library,... expects
directories to have standard structure (include,lib,...), see
documentation of find_* commands for details.
it is usually enough to set CMAKE_PREFIX_PATH to DESTDIRs used in
dependencies' "make install DESTDIR=/foo"

you may want to remove NO_DEFAULT_PATH as used in linked
LibFindMacros.cmake, it disables this functionality.

Regards,
Oto Petrik


More information about the CMake mailing list