[CMake] find_library search orders with CMAKE_PREFIX_PATH & CMAKE_FIND_ROOT_PATH

Nicolas Tisserand nicolas.tisserand at gmail.com
Wed May 23 14:22:26 EDT 2012


On Wed, May 23, 2012 at 1:01 AM, Eric Noulard <eric.noulard at gmail.com> wrote:
> 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:

Yes, I forgot to clarify that point. It does not work for me either,
because it completely discards all system libraries (like libm.dylib
or CoreFoundation.framework on the mac, for instance), which makes it
difficult to build anything useful without copying or symbolic-linking
all the system libraries in the stage/lib directory.

What I would need is simply to have the custom-built libraries take
precedence over their potential system-wide versions.

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

Thanks for the tip :-)

>> 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.

This would be nice but would require to edit the find_library calls in
the build system of all the custom-built libraries, which is not very
desirable, because I do not maintain them.

Could something like
-DCMAKE_FIND_ROOT_PATH_MODE_{PROGRAM,INCLUDE,LIBRARY}:STRING=FIRST be
envisioned instead? That way, I could trigger the correct build
through command line switches, without intrusive editions.

> 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?

Yeah, sure. As stated above, it restricts the set of libraries
available through find_library to the exact contents of the stage
directory, thus completely discarding some required standard
libraries.

--
Nicolas


More information about the CMake mailing list