[cmake-developers] Using multiple toolchains
Stephen Kelly
steveire at gmail.com
Mon Jul 1 13:26:57 EDT 2013
Hi there,
I've pushed a proof-of-concept multiple-toolchains branch to my clone which
enables the use of multiple toolchains with cmake.
The idea is to use a separate cache and set of definition overrides for each
toolchain. The current proof-of-concept implementation is very simple and
makefile definitions are currently mostly read-only/frozen after the
project() invokation.
One of the goals I have is to make it possible to use N different
toolchains, not just two. That way, you can build your app for all different
Android platforms you support at the same time etc. For GammaRay, we'd want
to build the gammaray_probe for all available embedded linux versions we can
find at the same time etc.
There's obviously a clash of output binary names, cmake target names and
make target names if the same library is going to be build for multiple
toolchains. That's something I have not yet attempted to solve.
I introduced a naming scheme for toolchains so that each toolchain could
have a name. That allows the possiblity to specify in the CMakeLists.txt
file which toolchain should be used to build each target. There are also two
special toolchain names - HOST and TARGET. There are some usage examples in
the branch.
A more complete schema for toolchain files might involve looking for them in
standard locations such as ~/.cmake/Toolchains or an environment variable,
because they are machine-specific anyway and contain paths to sysroots and
sdks etc.
I don't know if it is possible to use multiple 'Visual Studio Toolsets', or
whatever Xcode uses in the same buildsystem, but if it is, I could imagine
those names in the same namespace as the toolchain names for a similar
purpose.
There is also a problem of how to specify and separate targets for different
toolchains. I think that needs to be done with a language extension, but for
now and for the examples in the branch I've hacked it with a target
property.
Of course, as toolchain files are really 'cmake lists files', they are not
limited to cross-compiling uses. One could define toolchains which build
both debug and release versions of a library at the same time. The Qt5
toolchain files which will be generated when this patch is integrated
contain a pre-set CMAKE_PREFIX_PATH for finding Qt5.
https://codereview.qt-project.org/#change,53858
CMake currently segfaults on exit (probably due to double-deletion - I
haven't investigated), and I broke several other features in the process of
creating this branch. So, don't judge the code too much, but if you've had
ideas about multiple toolchains for CMake, I'd like to hear them.
At least
http://www.cmake.org/Wiki/CMake_Cross_Compiling
claims multiple toolchain support is needed for building for the PS3. This
also means that 3 toolchains are needed, not just 2.
Thoughts?
Thanks,
Steve.
More information about the cmake-developers
mailing list