[CMake] find_library search orders with CMAKE_PREFIX_PATH & CMAKE_FIND_ROOT_PATH

Eric Noulard eric.noulard at gmail.com
Wed May 23 04:01:09 EDT 2012


2012/5/23 Nicolas Tisserand <nt at manctl.com>:
> Hi all,
>
> I am currently building a collection of inter-dependent libraries and tools,
> mostly cmake-built, all installed to a common staging directory.
>
> I therefore need CMake find_library & find_package commands to search in the
> staging directory first, before inspecting the system.
>
> Here's my problem: I can't get any combination of CMAKE_PREFIX_PATH or
> CMAKE_FIND_ROOT_PATH_MODE_* (in BOTH/NEVER/ONLY modes) to do this correctly,
> when find_library is given multiple names for the library.

I'm not sure I understand, doesn't the
-DCMAKE_FIND_ROOT_PATH:PATH=/Users/nt/Hacks/cmake-find-png/stage
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY:STRING=ONLY
case gives you want you want:

==============================> Looking for: png;png14
==============================> Found:
/Users/nt/Hacks/cmake-find-png/stage/lib/libpng14.a
==============================> Looking for: png14;png
==============================> Found:
/Users/nt/Hacks/cmake-find-png/stage/lib/libpng14.a
-- Configuring done
-- Generating done
-- Build files have been written to:
/Users/nt/Hacks/cmake-find-png/build-ROOT_PATH_ONLY


> It only works using CMAKE_PREFIX_PATH, or CMAKE_FIND_ROOT_PATH &
> CMAKE_FIND_ROOT_PATH_MODE=BOTH, provided that the name of the library
> present in the stage directory is the *first* of the library names list
> given to find_library.
>
> It seems like the search order in such cases is as follows (in pseudo-code):
>
> for each name in names
>     for dir in stage, system
>         if library_found(dir, name)
>             return dir, name
>         end
>     end
> end

This is the case (at least for find_library)  if you look at
Source/cmFindLibraryCommand.cxx
std::string cmFindLibraryCommand::FindNormalLibrary()

> My use case would require the inner and outer loops to be swapped.

This looks like a reasonable request to me but I can't imagine a way
to support that without adding some option like "PATH_FIRST" to
find_library.

Again could you explain why the

-DCMAKE_FIND_ROOT_PATH:PATH=/Users/nt/Hacks/cmake-find-png/stage
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY:STRING=ONLY
does not work for you?

-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


More information about the CMake mailing list