[cmake-developers] A CMAKE_EMULATOR variable

Brad King brad.king at kitware.com
Thu Mar 5 09:51:15 EST 2015


On 03/04/2015 08:15 PM, Matt McCormick wrote:
> On Wed, Mar 4, 2015 at 12:00 PM, Brad King wrote:
>> I do not think a global setting like this makes sense.  We cannot
>> unconditionally add the cross-compiling target launcher in front of
>> all tests.  Some tests may be running host tools.  See below.
> 
> This set of patches does not globally and unconditionally add a
> launcher in front of all tests. It uses build system knowledge to add
> the emulator commands in front of target executables only.

Good, but it may take more work.  I see the key logic here:

>    cmTarget* target = mf->FindTargetToUse(exe);
>    if(target && target->GetType() == cmTarget::EXECUTABLE)
>      {
>      // Use the target file on disk.
>      exe = target->GetFullPath(config);
> +
> +    // Prepend with the emulator when cross compiling if required.

This if() condition is not sufficient to know that the executable
is for the target architecture.  The cmTarget could be IMPORTED, in
which case we don't know whether it references a host tool or one
built for the target architecture.  Some kind of target property
may be needed to say "use the emulator to run me" more explicitly.
Once we have such a property, then it might as well refer to the
tool to be used, e.g.

  add_executable(myexe ...)
  set_property(TARGET myexe PROPERTY CROSSCOMPILING_EMULATOR ${emulator})

> The point about the overloaded meaning of "targets" is a good one.  I
> think the best name is then CMAKE_CROSSCOMPILING_EMULATOR.

Sounds good.  This variable could be used to initialize the above
property on target creation (see SetPropertyDefault calls).  In
try_run we simply need to pass the value into the inner project
and its executable will pick it up too.

-Brad



More information about the cmake-developers mailing list