CMake/Tests/RunCMake/find_library/PrefixInPATH.cmake
Brad King ffc06c1239 Teach find_(library|file|path) to get prefixes from PATH (#15370)
The find_package command already knows how to compute installation
prefixes from PATH.  Use the same approach to establish prefixes for
find_library, find_file, and find_path to use to look in directories
like "<prefix>/lib[/<arch>]" and "<prefix>/include" for libraries and
headers.  This will reduce the amount of configuration end users need to
do to establish a work environment rooted under a specific prefix.
2015-02-19 10:03:17 -05:00

12 lines
422 B
CMake

list(APPEND CMAKE_FIND_LIBRARY_PREFIXES lib)
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .a)
set(ENV_PATH "$ENV{PATH}")
foreach(path "/does_not_exist" "" "/bin" "/sbin")
unset(PrefixInPATH_LIBRARY CACHE)
set(ENV{PATH} "${CMAKE_CURRENT_SOURCE_DIR}${path}")
find_library(PrefixInPATH_LIBRARY NAMES PrefixInPATH)
message(STATUS "PrefixInPATH_LIBRARY='${PrefixInPATH_LIBRARY}'")
endforeach()
set(ENV{PATH} "${ENV_PATH}")