[CMake] Several questions/problems on FIND_* search behavior

Bill Hoffman bill.hoffman at kitware.com
Thu Apr 12 10:58:22 EDT 2007


E. Wing wrote:
>
>
> But I was thinking about a corner case where the include and lib don't
> share a common root. So that's what got me wondering about setting
> multiple paths in my environemental variable:
> export OPENTHREADS_DIR=/optional_libs:/optional_headers
>
> I didn't expect this to work, but I was hoping I would be corrected.
>
You could expand that before the call to FIND_LIBRARY  in your own cmake 
code.
>
>> > 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.
>>
>
> So here's the thing. I do want to search the default system paths, but
> I want them searched last. My motivation is for automated/one-touch
That is exactly what the above code does.   It will first search the 
paths you gave
it in the version of FIND_* that has NO_DEFAULT_PATH.  If it is not 
found there
it will then search again in the FIND_* that does not have NO_DEFAULT_PATH.

>
> The problem with the two step FIND_ using NO_DEFAULT_PATH is that I
> need to modify all the official Find*.cmake packages that I use, and
> not just the ones I control.
>
Then you should most likely use the CMAKE_* environment variables, they
are always searched first.   So, just tell people to set CMAKE_LIBRARY_PATH,
CMAKE_INCLUDE_PATH to the extra places that you want searched first.

-Bill



More information about the CMake mailing list