find_package: Fix prefer-config mode to not fail on missing optional package

When `CMAKE_FIND_PACKAGE_PREFER_CONFIG` mode was set to `ON`, failure to
find a package was fatal even if it was not `REQUIRED`.  Fix this and
add a test case.

Fixes: #19557
2 files changed