How to use host tools using find_package when cross-compiling (eg. Qt5LinguistTools)

The issue is that the Qt5LinguistTools package provides functions like qt_add_translation.

So the proposed solution would be to this ?

  • Add a package in the project for example in cmake/Qt5LinguistHostTools.cmake
  • In this file, use find_program to find host tools (lrelease and lupdate programs)
  • In this file, implement the qt_add_translation macro that uses host tools with the same behavior as the original /usr/lib/x86_64-linux-gnu/cmake/Qt5LinguistTools/Qt5LinguistToolsMacros.cmake

Currently, I’m doing this (join is a function that concat all glob results):
CMAKE_PREFIX_PATH="/usr/lib/cmake;$(join ';' /usr/{lib/$(gcc -print-multiarch),lib*,share}/cmake)"

to match the find_package documentation where it is said to search paths matching this:

<prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/
<prefix>/(lib/<arch>|lib*|share)/<name>*/
<prefix>/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/

To me this bash solution seems to be less maintenance as I don’t need to maintain a copy of Qt’s cmake macros like qt_add_translation (but requires bash …)