[CMake] Find preferentially in /usr/local/lib not working

Timenkov Yuri ytimenkov at parallels.com
Fri Mar 28 06:50:04 EDT 2008


On Friday 28 March 2008 13:26:43 Stephen Collyer wrote:
> Timenkov Yuri wrote:
> > On Friday 28 March 2008 12:48:49 Stephen Collyer wrote:
> >> I'm trying to change some find* modules to prefer /usr/local/lib
> >>
> >> over /usr/lib and I can't get it to work. I have, for example:
> >>> FIND_PATH(CURL_INCLUDE_DIR
> >>>     NAMES
> >>>       curl/curl.h
> >>>     PATHS
> >>>       /usr/local/include
> >>>       /usr/include
> >>> )
> >>
> >> but this sets CURL_INCLUDE_DIR to /usr/include even though I have
> >> a curl/curl.h in /usr/local/include.
> >>
> >> Can someone tell me what I'm doing wrong here ?
> >
> > 1) Explicitly pass -DCURL_INCLUDE_DIR=/usr/local/include to cmake.
>
> Right, but that isn't a good solution for me.
Yes, It depends. If you know exactly that you want always search 
in /usr/local, you may modify cmake command invocation in .spec file (for 
example) when building packages.
If you want build multiple packages with same settings, it is better to set 
Environment variable.
If you have peculiar settings, it is better to modify .cmake files. This is 
most convenient way, if you have specific configuration in your project and 
it is not intended for wide distributive/OS list support.

>
> > 2) Point -DCMAKE_INCLUDE_PATH command line parameter or environment
> > variable to /usr/local/include. This forces cmake to search in
> > /usr/local/include
>
> I've tried setting CMAKE_INCLUDE_PATH explicitly prior to running the
> find script in a CMakeList.txt file, and it makes no difference. See
> my later posting.
Did you run this on clean build directory or CMakeCache.txt existed?
If so, you should manually delete CURL_INCLUDE_DIR value from cache (or whole 
cache).

The point is that once search variable is found in cache, cmake will never 
look again for headers nor validate its value.  Therefore you can put 
multiple find_path statements into single file.

>
> > 3) make 2-step find_path call (from cmake --help-command find_path)
> >
> >>        The reason the paths listed in the call to the command are
> >> searched last is that most users of CMake would expect things to be
> >> found first in the locations specified by their environment.  Projects
> >> may override this behavior by simply calling the command twice:
> >>
> >>           FIND_PATH(<VAR> NAMES name PATHS paths NO_DEFAULT_PATH)
> >>           FIND_PATH(<VAR> NAMES name)
> >>
> >>        Once one of these calls succeeds the result variable will be set
> >> and stored in the cache so that neither call will search again.
> >
> > Therefore, you first specify /usr/local/include in PATHS (as you done it)
> > and set NO_DEFAULT_PATH. And make second call to use usual search order.
>
> Right. So, if I understand correctly, I force FIND_PATH to look in
> /usr/local with, say:
>
> FIND_PATH(IDIR NAMES curl/curl.h PATHS /usr/local/include NO_DEFAULT_PATH)
>
> If that succeeds, the following FIND_PATH is a no-op, whereas if
> it fails then the default paths are searched ?
Yes.


More information about the CMake mailing list