[CMake] Cross compilation and native executables

Michael Wild themiwi at gmail.com
Wed Jan 27 02:54:01 EST 2010


On 26. Jan, 2010, at 21:28 , Guillaume Duhamel wrote:

> Hi,
> 
> I'm one of the Yabause ( http://yabause.org ) developers and we're currently
> porting our build system from Autotools to CMake. We made it to the point
> were basic stuff is working and we now want to get cross compilation working
> too.
> 
> One of Yabause compilation step require to generate and run an executable on
> the build platform; The CMake documentation (
> http://www.itk.org/Wiki/CMake_Cross_Compiling ) suggests that we use two
> compilation phase to do that, one for the native build and one for the cross
> compilation. Does that means you have to launch CMake + make twice or is
> there any way to automate the process?
> 
> On the other hand, I've found out about the ExternalProject module in the
> CMake documentation, could it be used to create a native-only CMake
> sub-project?
> 
> What I would really like is some way to have all compilation work done with
> only one CMake + make invocation ; is there any way to achieve that?
> *<http://www.cmake.org/cmake/help/cmake-2-8-docs.html#module:ExternalProject>
> *

Hi

Although I don't have any experience with cross-compiling and toolchain files, I remember that there was a discussion some weeks ago where ExternalProject indeed was brought up as a possibility to achieve what you need.

The only tricky part is to infer the output location of the sub-projects executable and then do a

add_executable(XXX IMPORTED)
set_target_properties(XXX PROPERTIES IMPORTED_LOCATION YYY)

The tricky part in determining the output location is that you need to consider CMAKE_EXECUTABLE_SUFFIX and CMAKE_CFG_INTDIR when the user uses a multi-config IDE such as Xcode or VisualStudio.

HTH

Michael


More information about the CMake mailing list