<html><body><div style="font-family: arial,helvetica,sans-serif; font-size: 12pt; color: #000000"><div>Oh, I did not see this one at all, thanks a lot Nils!<br></div><div>Julien<br></div><div><br></div><hr id="zwchr"><blockquote style="border-left:2px solid #1010FF;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;" data-mce-style="border-left: 2px solid #1010FF; margin-left: 5px; padding-left: 5px; color: #000; font-weight: normal; font-style: normal; text-decoration: none; font-family: Helvetica,Arial,sans-serif; font-size: 12pt;"><b>De: </b>"Nils Gladitz" <nilsgladitz@gmail.com><br><b>À: </b>"Julien Schueller" <schueller@phimeca.com>, "CMake Developers" <cmake-developers@cmake.org><br><b>Envoyé: </b>Mardi 15 Mars 2016 23:24:05<br><b>Objet: </b>Re: [cmake-developers] find_package with NO_MODULE while cross-compiling<br><div><br></div><div class="moz-cite-prefix">On 15.03.2016 23:01, Julien Schueller wrote:<br></div><blockquote cite="mid:1802445749.1660970.1458079317184.JavaMail.zimbra@phimeca.com"><div style="font-family: arial,helvetica,sans-serif; font-size:
        12pt; color: #000000" data-mce-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></blockquote><br> Setting <a class="moz-txt-link-freetext" href="https://cmake.org/cmake/help/v3.5/variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE.html" target="_blank" data-mce-href="https://cmake.org/cmake/help/v3.5/variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE.html">https://cmake.org/cmake/help/v3.5/variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE.html</a> to ONLY in your toolchain file should prevent cmake from picking up native packages.<br> <br> Nils<br></blockquote><div><br><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>