CMAKE_CROSSCOMPILING_EMULATOR for cross-compilation being ignored with generator expressions
I have a project that cross-compiles binaries from a Linux host to a Windows target using the MinGW compiler.
I have successfully been able to run these unit tests on my Linux host by setting the variable CMAKE_CROSSCOMPILING_EMULATOR
to 'wine64', so that the Windows .EXE files are invoked via Wine at CTest time.
This worked successfully with the following code:
add_test(NAME hellotest COMMAND helloworld)
I then attempted to expand this to use generator expressions:
add_test(NAME hellotest COMMAND $<TARGET_FILE:helloworld>)
At this point, the unit test will fail as it appears not to be invoked with CMAKE_CROSSCOMPILING_EMULATOR
under MinGW.
Curiously, if I attempt to run the same example but with normal GCC and CMAKE_SYSTEM_NAME
of Linux
, it will detect the CMAKE_CROSSCOMPILING_EMULATOR
variable successfully.
Therefore, CMAKE_CROSSCOMPILING_EMULATOR
is only being ignored when CMAKE_SYSTEM_NAME
is Windows
AND generator expressions are used on tests.
A complete example is attached:
If I run the following command:
CC=cc CXX=c++ cmake ../ && cmake --build . && ctest .
This command will succeed without error.
Conversely, if I invoke the command with MinGW targetting Windows, the generator command will fail:
CC=x86_64-w64-mingw32-gcc-posix CXX=x86_64-w64-mingw32-g++-posix cmake .. -DMINGW=1 && cmake --build . && ctest .
This command will only fail on the generator test. Looking in to LastTest.log it is clear that CMAKE_CROSSCOMPILING_EMULATOR
is not being prepended and instead CTest is attempting to execute the binary directly.
As far as I can tell, generator expressions in add_test
should not interfere with CMAKE_CROSSCOMPILING_EMULATOR
, which should be prepended to all instances of add_test
regardless.