[CMake] on find_package and building dependencies

Alexander Neundorf a.neundorf-work at gmx.net
Tue Jan 3 13:15:01 EST 2012


On Thursday 29 December 2011, Eric Noulard wrote:
> 2011/12/29 Ryan Lewis <me at ryanlewis.net>:
> > Hi,
> > 
> > I really like CMake's find_package() utility for finding dependencies,
> > but for some projects I have a
> > separate local copy of the installed libraries, and I want to point
> > find_package at a particular directory to find the installed
> > libraries.
> > How can I do this?
> 
> Have a look at find_package documentation,
> in particular the usage of
> CMAKE_FIND_ROOT_PATH
> and other
> *CMAKE_FIND_ROOT_PATH_*
> variables
> 
> you basically want:
> set(CMAKE_FIND_ROOT_PATH "/you/local/install/dir")
> before calling find_package(...)

No, please don't.
CMAKE_FIND_ROOT_PATH is intended for cross-compiling, to tell cmake where the 
root of the target file system is located.

Use CMAKE_PREFIX_PATH instead. It can contain a list of directories, and 
find_program(), find_file(), find_path(), find_package() and find_library() 
append bin/, include/ and lib/ respectively to each of the directories listed 
there.
The directories resulting from CMAKE_PREFIX_PATH are checked before all PATHS 
and HINTS directories.

E.g. if you have stuff inside /your/local/install/dir and /some/other/dir, do
$ export CMAKE_PREFIX_PATH=/your/local/install/dir:/some/other/dir
$ cmake ...args

or set it directly as a cmake variable within your CMakeLists.txt.

Alex


More information about the CMake mailing list