cmake: Make host protoc lookup reliable in cross-compile
FindWrapProtoc's fallback find_program had three related defects in
cross-compile builds:
1. QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH was passed via PATHS
(searched last), so a system /usr/bin/protoc could shadow an explicit
host prefix supplied by the user.
2. CMAKE_PREFIX_PATH was consulted, but it conventionally holds target
prefixes in cross-compile builds; if a target's protobuf install
prefix contains a bin/protoc (e.g. a cross-compiled QNX or Android
binary that is not runnable on the host), find_program picks it up
without checking runnability, leading to a silent misconfiguration
and a cryptic build-time failure.
3. CMAKE_FIND_ROOT_PATH was not suppressed. That mechanism exists to
re-root searches into the target sysroot, the opposite of what is
needed here. protoc is a host build tool; the target sysroot is
irrelevant to finding it, and re-rooting only creates opportunities
to match non-runnable target binaries.
Fix all three: pass the hint via HINTS so user-supplied paths precede
the system PATH; add NO_CMAKE_PATH and NO_CMAKE_ENVIRONMENT_PATH to
exclude target CMAKE_PREFIX_PATH entries; add NO_CMAKE_FIND_ROOT_PATH to
disable root-path re-rooting entirely, so only the explicit HINTS and
the host system PATH are searched.
Native builds are unaffected.
Fixes: QTBUG-146828
Change-Id: I0274614c6a2ad5b2dc34937a03a1c037814754f5
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>