[cmake-developers] find_package with NO_MODULE while cross-compiling

Julien Schueller schueller at phimeca.com
Wed Mar 16 04:20:24 EDT 2016


Oh, I did not see this one at all, thanks a lot Nils! 
Julien 

----- Mail original -----

> De: "Nils Gladitz" <nilsgladitz at gmail.com>
> À: "Julien Schueller" <schueller at phimeca.com>, "CMake Developers"
> <cmake-developers at cmake.org>
> Envoyé: Mardi 15 Mars 2016 23:24:05
> Objet: Re: [cmake-developers] find_package with NO_MODULE while
> cross-compiling

> On 15.03.2016 23:01, Julien Schueller wrote:

> > Hi,
> 

> > When using find_package (<name> NO_MODULE) while cross-compiling,
> 
> > 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.
> 

> > For example let's say that I have Qt5 project in my host Linux box, which
> > provides a /usr/lib/cmake/.../Qt5WidgetsConfig.cmake.
> 
> > In my cmake project I use: find_package (Qt5Widgets NO_MODULE), everything
> > goes as planned.
> 
> > 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
> 
> > I set CMAKE_FIND_ROOT_PATH to /usr/i686-w64-mingw32 and stuff via a
> > toolchain
> > file, and everything goes fine too.
> 
> > 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.
> 

> > I found a workaround, which is to not let cmake use host rules to find
> > <name>Config.cmake in the case of cross-compiling:
> 
> > if (CMAKE_CROSSCOMPILING)
> 
> > set (NO_MODULE_ARGS NO_MODULE NO_SYSTEM_ENVIRONMENT_PATH
> > NO_CMAKE_SYSTEM_PATH)
> 
> > endif ()
> 
> > find_package (Qt5Widgets ${NO_MODULE_ARGS})
> 
> > 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 ?
> 

> Setting
> https://cmake.org/cmake/help/v3.5/variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE.html
> to ONLY in your toolchain file should prevent cmake from picking up native
> packages.

> Nils

-- 
Julien Schueller 
Phimeca Engineering 
www.phimeca.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160316/696d4ecc/attachment.html>


More information about the cmake-developers mailing list