find_* commands: Use a configuration variable to set search behaviour to NAMES_PER_DIR
In Continuous integration pipelines where there are a lot of packages installed, particularly Windows, where each package may ship with their own version of libraries like libiconv, zlib etc, we want CMake to use our libraries instead of the ones installed along with some other software. So we set CMAKE_PREFIX_PATH for finding our libraries. The issue is that, according to certain implementations in find_*.cmake the find_library/program commands don't use NAMES_PER_DIR, so even though we CMAKE_PREFIX_PATH or mylib_ROOT CMake chooses other libraries instead of our respective ones. I know we can fix this by using NAMES_PER_DIR in the find_library call in the respective cmake file, but this becomes infeasible when the number of library dependencies is high, while we rely on the default find cmake scripts.
My proposal to address this issue is to define a global variable say SEARCH_PREFER_NAMES_PER_DIR to set the search behaviour of find_* commands if desired.
Side Note: I am working on a patch to build git using CMake (this patch has been integrated into pu), this was an issue recently encountered in the build pipelines.