[CMake] Several questions/problems on FIND_* search behavior
Bill Hoffman
bill.hoffman at kitware.com
Wed Apr 11 21:33:04 EDT 2007
E. Wing wrote:
> Several questions/problems on FIND_* search behavior:
>
> 1) Somebody complained to me that FIND_FILE was not finding things in
> the paths that the documentation say they should be in. I confirmed on
> OS X. I don't know about other platforms.
>
I think it follows the docs....
> So if I do:
> FIND_FILE(FOO libm.dylib)
> I'm expecting it to find it in /usr/lib, but it doesn't turn up a hit.
> Among other paths, I'm expecting /usr/include and /usr/lib to be
> searched. I'm also kind of expecting /usr to be searched. But copying
> the file around didn't seem to produce any hits. So what's the real
> story here? (FYI: I can explicitly add the PATHS and it will be found,
> and FIND_LIBRARY does find it.)
>
FIND_FILE does not search in /usr/lib only FIND_LIBRARY search in
the library directories. FIND_FILE only looks in PATH.
>
> 2) I'm trying to use CMAKE_LIBRARY_PATH and CMAKE_INCLUDE_PATH. I set
> my environment like
> export CMAKE_LIBRARY_PATH=/path/to/lib1:/path/to/lib2
> export CMAKE_INCLUDE_PATH=/path/to/include
>
> So far, these haven't turned up any hits for me. I tried on both Mac
> and Linux, CMake versions 2.4.
>
That should work, please give a specific example, note that
CMAKE_LIBRARY_PATH
is only searched by FIND_LIBRARY and CMAKE_INCLUDE_PATH is only searched
by FIND_PATH, as per the docs.
> 3) Is it possible to list multiple potential paths for an $ENV{FOO}
> variable? So if I do:
> export FOO=../Dir1:../Dir2
> and my script has:
> FIND_LIBRARY(FOO foo PATHS $ENV{FOO}),
> will this work?
> (So far my tests say no, but I would like to know if this can work.)
>
That is not what the docs say for FIND_*:
FIND_FILE(
<VAR>
name | NAMES name1 [name2 ...]
PATHS path1 [path2 ... ENV var]
.....
)
....
if ENV var is found in the PATHS section the environment variable var
will be read and converted from a system environment variable to a cmake
style list of paths. For example ENV PATH would be a way to list the
system path variable.
.....
To use and env var in a FIND_* command you do it like this:
PATHS ENV FOO
This is because path separators are OS specific ; on windows and : on
unix, so $ENV{PATH} will only work on windows for cmake. But the ENV
PATH syntax of FIND_* will let cmake do the correct conversion of the
native path into cmake.
>
> 4) Finally, back to FIND_LIBRARY(FOO foo PATHS $ENV{FOO}),
> how do I make CMake search my system paths last. I want my $ENV{FOO}
> to be like an override, but my system installed stuff keeps getting
> found first, before my $ENV{FOO} is checked.
>
Again, back to the docs....
...
If NO_DEFAULT_PATH is specified, then no additional paths are added to
the search. If NO_DEFAULT_PATH is not specified, the search process is
as follows:
....
So, you can do this:
FIND_*(.... PATHS mystuff NO_DEFAULT_PATH) # first look with no extra paths
FIND_*(....) # now look in all the default paths.
-Bill
More information about the CMake
mailing list