[CMake] Cross Compiling

Alexander Neundorf a.neundorf-work at gmx.net
Tue Jan 5 13:55:59 EST 2010


On Tuesday 05 January 2010, Michael Wild wrote:
> On 4. Jan, 2010, at 19:15 , Alexander Neundorf wrote:
> [snip]
>
> >> - There is no distinction between install prefixes for the target and
> >> the host. Sometimes I'd like to put various build tools on the host
> >> system at the same time as libs and binaries on the target root.
> >
> > In CMake one build tree uses one toolchain. So in one build tree you can
> > only create executable which run either for the target, of for the host,
> > not both in one go.
> > So if you need first to create host build tools, and later on use them
> > for the actual cross compile, you need two build trees. I would recommend
> > to "export" the executable and "import" them again in the cross build.
> >
> > If this is not your problem, but really just the install location, you
> > can set the install location of every install() command separately, this
> > is completely independent from the cross compiling support.
>
> To automate this you can use the ExternalProject.cmake that comes with
> CMake-2.8 to build the host tools. 

Maybe, I haven't tried to combine this yet.

> You can then use add_executable(tool 
> IMPORTED) and set_target_properties(tool PROPERTIES IMPORTED_LOCATION ...)
> to import the tool target into the cross-compiling project.

That's not necessary to do manually. You can use the EXPORT feature for the 
necessary executables, something like this:
If you don't want to install the project first, you can add an
if(NOT CMAKE_CROSSCOMPILING)
   export(TARGETS ... )
endif(NOT CMAKE_CROSSCOMPILING)
to create such a export file in the buildtree.

Alex


More information about the CMake mailing list