[CMake] Building a tool to run on the host when cross-compiling

Alexander Neundorf a.neundorf-work at gmx.net
Thu Jan 17 16:42:20 EST 2013


On Thursday 17 January 2013, Christopher Lansing wrote:
> Hi,
> 
> I'm trying to use CMake to build a set of libraries with the intention of
> being able to build the library on a few different systems, and also
> cross-compile. Some of the source code for the library is generated from
> description files using a tool included (as source) with the library code.
> I want to be able to build the tool, use it to generate the sources, then
> build the library. That part works.
> 
> When trying to compile for a system different from the host, it generates
> the tool for the target, which the host can't run. If I understand the
> wiki, the suggested approach to deal with this is two separate builds - one
> configured to build for the host, and one configured to build for the
> target, importing the tool generated by the host build (
> http://www.cmake.org/Wiki/CMake_Cross_Compiling#Using_executables_in_the_bu
> ild_created_during_the_build ).
> 
> I'm trying to find a way to do this without requiring a second build. I
> suppose I could have each CMakeLists.txt set up custom target properties
> for the compiler flags depending on whether I'm cross compiling or not for
> - but that seems like a lot of extra junk to stick in every file.
> 
> Is there a way to do this - 

Yes.
Or maybe you can do something with the ExternalProject support, to first do a 
native build in an external project, and then use the generated executable in 
the cross build.
I haven't tried this myself, but it might work.

Alex


More information about the CMake mailing list