find_package( HDF5 ) doesn't respect CMAKE_FIND_ROOT_PATH_MODE_PACKAGE
While trying to cross-compile flann-1.8.4 for Android, I've encountered the following quagmire:
- Flann uses find_package( HDF5 ), but it's not required & I don't have it on the target system.
- This finds the package installed on the host, unless CMAKE_FIND_ROOT_PATH_MODE_PROGRAM is set to ONLY (no matter what CMAKE_FIND_ROOT_PATH_MODE_PACKAGE says).
- However, when I set CMAKE_FIND_ROOT_PATH_MODE_PROGRAM to ONLY, CMake no longer finds the NDK's ar program (static linker).
- Even if I explicitly set CMAKE_AR, its value isn't respected, and the static linking command ends up as "".
It seems to me like there's one or two bugs, here. First, find_package() should respect CMAKE_FIND_ROOT_PATH_MODE_PACKAGE and be unaffected by CMAKE_FIND_ROOT_PATH_MODE_PROGRAM. That much seems clear.
Secondly, I don't understand why CMAKE_FIND_ROOT_PATH_MODE_PROGRAM is breaking CMake's ability to find ar, not least because ar is installed in one of the directories listed in my CMAKE_FIND_ROOT_PATH. I double & triple-checked all my path strings, to make sure it's not just a typo somewhere. I'll reproduce & file this as a separate bug.
Attached is the output of CMake finding HDF5 on the host system, then trying to use it during cross-compilation. Toolchain file also included. Though I think the issue is probably a bug in
share/cmake-3.7/Modules/FindHDF5.cmake, rather than anything specific to flann, it can be obtained from http://www.cs.ubc.ca/research/flann/