[CMake] FIND_PATH() search custom path first

Chuck Atkins chuck.atkins at kitware.com
Tue Nov 4 13:07:06 EST 2014


Hi George, Jakub,


>   NO_DEFAULT_PATH
>
>   NO_CMAKE_ENVIRONMENT_PATH
>
>   NO_CMAKE_PATH
>
>   NO_SYSTEM_ENVIRONMENT_PATH
>
>   NO_CMAKE_SYSTEM_PATH
>

The options specified are redundant.  NO_DEFAULT_PATH implies the later 4.
If you just specify NO_DEFAULT_PATH then only HINTS and user guess paths
(those specified by the PATH argument) will be checked.



>    NO_CMAKE_FIND_ROOT_PATH
>

This is specific to cross compiling, and usually isn't needed unless that's
your situation.

A particularly effective and commonly used pattern is to build up the
options to the find call in a variable.  The FindBoost module does this
very thing to restrict it's component search to all the same directory.
The idea is that if you have a specific location that you know your file
should be found in when set, then something like this could work:

set(FOO_FIND_OPTS)
if(FOO_DIR)
  set(FOO_FIND_OPTS HINTS "${FOO_DIR}" NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH)
endif()
find_library(FOO_LIBRARY MyFooLib ${FOO_FIND_OPTS})

This way, if FOO_DIR is set, then it will only look there.  However, if
it's not, then FOO_FIND_OPTS is empty and the standard search will happen.

- Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141104/9af0382a/attachment.html>


More information about the CMake mailing list