find_library: search LIBRARY_PATH env var
When using a compiler like GCC to drive linking, the LIBRARY_PATH
environment variable is used to get a :
-separated list of paths to search for libraries. gcc
passes -L
flags for these paths to its internal linker invocation.
LIBRARY_PATH
essentially extends the compiler's list of implicit link directories.
find_library
intentionally does not search the compiler's builtin implicit link directories. This is because one exception to CMake's preference for linking libraries by absolute path is for toolchain-provided libraries to be found by name, e.g. -lfoo
. That list of libraries is typically known for a given compiler, and so it is up to projects to just name the library instead of trying to find it with find_library
.
Link directories specified by LIBRARY_PATH
can contain libraries besides those that come in the compiler's builtin implicit link directories. Therefore it may make sense for find_library
to search entries of LIBRARY_PATH
too.