[CMake] how to use a cross linker

Alexander Neundorf a.neundorf-work at gmx.net
Mon Jun 18 08:53:46 EDT 2007


Hi,

On Saturday 16 June 2007 03:54, kitts wrote:
> On Friday 15 Jun 2007 6:06:14 pm Alexander Neundorf wrote:
> > Hi,
> >
> > On Friday 15 June 2007 02:54, kitts wrote:
> > ...
> >
> > > I cannot publish the source but let me describe how i do it now with my
> > > project at work.
> > >
> > > In the top level cmakelists.txt I include the subdirectories of the
> > > various modules in our project. The first subdirectory included is
> > > called platform.
> > >
> > > The platforms folder contains configuration details about a particular
> > > board that we support. This is the only information that is passed to
> > > CMake on the command (ex: -DPLATFORM=ABC). The configuration includes
> > > information on which compiler to use and which processor, the drives
> > > that are to be included and the modules that need to be included.
> >
> > How do you do this ?
> > INCLUDE(${PLATFORM}) in your top level CMakeLists.txt ?
>
> No. A platform here is not like the usual. Platforms here are custom boards
> that developed in house. Much like the evaluation boards that are available
> with most processors. These platform settings are specific to the design of
> the hardware. Things like the amount of RAM and FLASH available on the
> hardware, their starting address etc. This information is set as
> definitions so that the code compiles with those values defined.
>
> Other information definitions are things like which are the IO pins or Chip
> selects used by a specific hardware peripheral.
>
> Then there is information for cmake. Things like which files (modules) are
> to be included in the build. Information like what hardware is present on
> the board and which driver to use for it.

Yes, I understand this.
Still I wanted to know, what do you do with the PLATFORM information in your 
cmake files and how do you set the compiler etc. ?

> That limitation is generally fine enough. Now that you mention, i think of
> a use case where there are multiple toolchains involved. Consider tools.
> Tools for testing and tools used by the end customer. These tools are built
> for the host PC and interact with the embedded system over some mode of
> communication that is differrent for each platform. I would want these to
> get built when building for the platform. Currently these are built
> separately as another project in another source tree.

You can do this by manual tweaking, i.e. working around the official cmake 
method of detecting the compiler etc.
If cmake runs, it detects the compiler and all the tests you do are for this 
compiler and cmake presumes that all the executables and libraries you build 
in your tree are compatible to each other and are for the system for which it 
runs the tests.

You can ignore all this by just setting the compiler and rule variables in 
some subdirs manually.  See Modules/UseEcos.cmake .

> > > 2) Setting up an assembler. We invariably need assembly file support
> > > when dealing with embedded systems.
> >
> > Ok.
> > How do you do this currently ?
>
> Currently, i have a macro PROCESS_ASM_SOURCES() that i call before each
> ADD_EXECUTABLE() or ADD_LIBRARY(). I pass the sources list to the macro. In
> the macro i look for files with a .s extention and assemble them to objects
> (placed in the binary directory) using the custom command (This is again
> toolchain dependent), remove the .s files from the list of sources and add
> the object files instead. I have to take care to ensure the order of the
> sources in the list as when liking an executable the startup files for the
> hardware should be the first files passed to the linker.

Ok.

> > > 4) calling PROJECT() seems to destroy a lot of settings already
> > > configured. If called before making custom settings the compiler is set
> > > and cannot be changed...
> >
> > Changing the compiler from within a cmake file is not really supported.
> > This means you can do it but it's not the "official" way.
>
> Yes. This was my first project with cmake and i dint know the ways in which
> i had to use it. I know i dint want to place any files into the cmake
> installation as that would be hard to maintain and distribute unless
> supported upstream.

You are using the IAR toolchain, right ?
We would like to have builtin support for this toolchain in cmake. 
Mainly a Generic-<name_of_the_compiler>.cmake file in Modules/Platform/ is 
needed for this.

If you have the cmake files which have the build rule variables can you please 
post them ?

Bye
Alex


More information about the CMake mailing list