[cmake-developers] Installing Toolchain files (Was: Building with Qt for the Raspberry Pi with CMake)

Stephen Kelly steveire at gmail.com
Mon Apr 15 13:48:26 EDT 2013


Alexander Neundorf wrote:

> I think that's a good idea.
> Qt, once built, knows where the compiler is and what the target operating
> system is, so it is a good source of information for that.
> It also knows at least some part of CMAKE_FIND_ROOT_PATH, that would be
> its own install locations, maybe it knows even more about where things are
> to be found for the target ?
> 

I've uploaded the change I've worked on for Qt:

 https://codereview.qt-project.org/#change,53858

The CMAKE_FIND_ROOT_PATH is indeed known, as is the CMAKE_PREFIX_PATH and 
all relevant compilers. That seems to be all the relevant information for a 
toolchain. I tried also defining CMAKE_AR and CMAKE_LINKER, but that fails 
and is not needed anyway. Setting CMAKE_LINKER fails because the variable 
contains 'g++' and the '+' cause regex compile failure in 
CMakeParseImplicitLinkInfo.cmake. 

So, after building Qt, a project can be built using 

 cmake .. -DCMAKE_TOOLCHAIN_FILE=/path/to/qt/cmake/Qt5Toolchain.cmake

The generated file is deliberately named generically so that that always 
works. The path to the Qt build will be specific enough anyway. The 
toolchain files contain absolute paths to the sysroot and the cross-
compilers.

When building Qt, a sysroot can be passed to the configure script, and a so-
called 'host-prefix' can be passed too. Cross compiled libraries get 
installed into the prefix, and host-compiled tools like moc and qmake get 
installed to the hostprefix. In my patch, I install the toolchain file to 

 $$hostprefix/cmake/Qt5Toolchain.cmake

I'm not sure about the exact location to install it to, because there is no 
precedent for installing toolchain files, nor is there likely to be another 
reason to in another project. 

Toolchain files are specific to a pair of compiler and sysroot, which are 
often distributed separately. Installing the toolchain file only makes sense 
for Qt because the Qt installation is already specific to that compiler and 
sysroot, and because Qt doesn't use cmake itself (otherwise the toolchain 
file would already be a prerequisite to building Qt). So, I don't really see 
this situation coming up again.

Any better ideas of where to install it to anyway?

Thanks,

Steve.





More information about the cmake-developers mailing list