<html><body><div style="font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000"><div>Hi,<br></div><div><br></div><div>When using find_package (<name> NO_MODULE) while cross-compiling,<br></div><div>cmake may find an existing <name>Config.cmake in the host root path if <name>Config.cmake is not available in the target root path.<br></div><div><br></div><div>For example let's say that I have Qt5 project in my host Linux box, which provides a /usr/lib/cmake/.../Qt5WidgetsConfig.cmake.<br></div><div>In my cmake project I use: find_package (Qt5Widgets NO_MODULE), everything goes as planned.<br></div><div>Now I want to cross-compile using MinGW-w64, I install qt5 in my mingw target root, so I have a /usr/i686-w64-mingw32/lib/cmake/.../Qt5WidgetsConfig.cmake</div><div>I set CMAKE_FIND_ROOT_PATH to /usr/i686-w64-mingw32 and stuff via a toolchain file, and everything goes fine too.<br></div><div>No if I remove the qt5 target package for mingw, or it is unavailable in the first place, cmake prefers the host qt5 config file, and the compilation fails.<br></div><div><br></div><div>I found a workaround, which is to not let cmake use host rules to find <name>Config.cmake in the case of cross-compiling:<br></div><div>if (CMAKE_CROSSCOMPILING)<br>  set (NO_MODULE_ARGS     NO_MODULE     NO_SYSTEM_ENVIRONMENT_PATH     NO_CMAKE_SYSTEM_PATH)<br>endif ()<br>find_package (Qt5Widgets ${NO_MODULE_ARGS})<br>Would there be a smarter way to do this instead of invading each CMakeLists that uses a find_package relying on package-provided cmake configs ?<br></div><div><br></div><div><br></div><div>-- <br></div><div><span name="x"></span>Julien Schueller<br>Phimeca Engineering<br>www.phimeca.com<span name="x"></span><br></div></div></body></html>