[CMake] patch for supporting multiple toolchain in single source tree

Alexander Neundorf a.neundorf-work at gmx.net
Tue May 13 16:05:53 EDT 2008


Hi Yinyin,

thanks for the explanation :-)
Comments see below.

On Tuesday 13 May 2008, Yinyin wrote:
> > On Monday 05 May 2008, Yinyin wrote:
> > > The attached file (multi-toolchain.patch.bz2) is a patch I made for
> > > supporting multiple tool-chain in single source tree.
> > > The idea is add an extra property "TARGET_ARCH" to target
> > > and make the variable expansion routine lookup toolchain according to
> > > TARGET_ARCH.
> > > For example, if TARGET_ARCH is set as CPUX (ie:
> > > SET_TARGET_PROPERTIES(my_target  PROPERTIES  TARGET_ARCH  CPUX) ), the
> > > modified expansion routine will check CMAKE_C_COMPILER_CPUX first when
> > > cmake attempts to generate statements which reference to C compiler.
> >
> > The patch is not that small, so, I just ask...
> >
> > How does it deal with CMakeCache.txt (which may contain different results
> > for different toolchains) ?
>
> in CMakeCache.txt , there will have additional entries for extra
> tool-chains.
>
> for example, in CMakeCache.txt of Cell HelloWorld, there are:
> {{{
> CMAKE_C_COMPILER:FILEPATH=/opt/cell/toolchain/bin/ppu-gcc
>
> //The path of SPU targeted C compiler
> CMAKE_C_COMPILER_SPU256K:STRING=/opt/cell/toolchain/bin/spu-gcc
>
> //Rule for compiling C source into object code
> CMAKE_C_COMPILE_OBJECT_SPU256K:STRING=<CMAKE_C_COMPILER> <DEFINES> 
> -march=cell -mtune=cell -mea32  <FLAGS> -o <OBJECT>   -c <SOURCE> }}}
>
> The 1st one comes for the "default" tool-chain.
>
> The 2nd and 3rd come for the "additional" tool-chain.

Ok, this doesn't look too bad, but...

> These additional entries are added by toolchain file (or module included by
> toolchain file).
>
>
> For CellBE / PS3 -
>
> In the files I uploaded, there is a module named  "UseCellBESDK3.cmake" and
> contained in "cellsdk3_cmake_modules.tar.bz2".
>
> This module would declare the rules and provide additional cmake functions
> to support the build process for CellBE / PS3.
>
> > What does it do with the CMakeFiles/ directory (which may contain
> > different object files for different toolchains) ?
>
> In this patch, the additional tool-chain will not be tested,
>
> so, there is nothing to do with CMakeFiles/.

...here we have some problem.
In CMakeFiles/ there are also the object files for the target stored. Ah, you 
build every target just for one architecture. And for the not-native 
architectures the test results in the CMakeCache.txt may be wrong.
So this part with the automatic handling of TARGET_ARCH is not ready for 
committing to cvs. Also cmake would have to handle that architecture 
everywhere so that you can only link matching libraries and executables 
together. 

But I also had a look at the Find...cmake and the Use...cmake file.
I think you can use them also without the first patch (may need some 
modifications).
If you just use SET() in some directory to set the compiler etc. variables, 
these new values will be used there and in subdirs.
So if you just to find_package(CellBESDK3) e.g. in the top level 
CMakeLists.txt and then have a macro/function like cell_enable_toolchain() 
which just set()s the appropriate variables to the cell specific values this 
should work good enough so you can build cell software in these directories 
(you have to take care not to build native software in subdirs of these 
directories).

This is somewhat similar to what I did with eCos (see UseEcos.cmake) before 
cmake supported cross compiling. But nowadays I actually consider this more a 
hack. Anyway, if you get this in good shape this part may go into cmake cvs 
if the cmake maintainers don't object.

Alex


More information about the CMake mailing list