CMake NO_DEFAULT_PATH also disables hints and path suffixes
CMake “find_{file,library,package,path,program}” have a NO_DEFAULT_PATH
parameter that disables ALL search paths, even the <NAME>_ROOT
priority.
The need for this and the workaround is best shown by example with a non-system compiler such as Intel oneAPI.
The reason that we use NO_DEFAULT_PATH
for non-system compilers is because CMake will still try to use the system libraries that may not be ABI compatible with the other compiler.
NO_DEFAULT_PATH
disables the CMake default PATH_SUFFIXES
, so those need to be specified as well.
To make the command line and environment variable hints work again, do like:
find_library(ZLIB_LIBRARY
NAMES z zlib
NO_DEFAULT_PATH
HINTS ${ZLIB_ROOT} ENV ZLIB_ROOT
PATH_SUFFIXES lib)
find_path(ZLIB_INCLUDE_DIR
NAMES zlib.h
NO_DEFAULT_PATH
HINTS ${ZLIB_ROOT} ENV ZLIB_ROOT
PATH_SUFFIXES include)