hdf5 icon indicating copy to clipboard operation
hdf5 copied to clipboard

CMake: Fix Fortran cross-compilation support

Open jschueller opened this issue 1 month ago • 2 comments

The current CMAKE_CROSSCOMPILING paths lead here to dummy commands "cmake -E env" being emitted that dont seem to do anything even when CROSSCOMPILING_PATH is set (#5720) as it must be followed by an actual command, and not another COMMAND entry:

cmake -E env: no command given

It seems CROSSCOMPILING_PATH is intented to pass environment variables to the emulator. A cleaner way is to set them via a script that actually calls the emulator instead of adding CROSSCOMPILING_PATH to every executable target invocation. Then this script would be passed as CMAKE_CROSSCOMPILING_EMULATOR instead of the emulator itself. A common use-case is to pass WINEPATH to wine so that standard dlls are found when running mingw executables:

#!/bin/sh
mingw_prefix=/usr/i686-w64-mingw32
export WINEPATH=${mingw_prefix}/bin
/usr/bin/wine "$@"

Anyway we can simplify the two paths of the if/else, CMAKE_CROSSCOMPILING_EMULATOR being empty when CMAKE_CROSSCOMPILING is false. Note that we need to use CMAKE_CROSSCOMPILING_EMULATOR explicitely here otherwise it would be omitted by cmake when generator expressions like these, and you cannot always rely on binfmt_misc to forward to the right emulator.

/cc @byrnHDF

Tested with mingw from linux.


[!IMPORTANT] Simplifies CMake cross-compilation by merging paths and using CMAKE_CROSSCOMPILING_EMULATOR consistently across multiple files.

  • Behavior:
    • Simplifies cross-compilation by merging if/else paths in fortran/src/CMakeLists.txt, fortran/test/CMakeLists.txt, and hl/fortran/src/CMakeLists.txt.
    • Uses CMAKE_CROSSCOMPILING_EMULATOR consistently for executing target files.
  • Commands:
    • Removes dummy command cmake -E env ${CROSSCOMPILING_PATH} in favor of CMAKE_CROSSCOMPILING_EMULATOR.
    • Ensures generated files must exist beforehand if CMAKE_CROSSCOMPILING_EMULATOR is not set.
  • Testing:
    • Tested with MinGW from Linux.

This description was created by Ellipsis for f91fb3c630dd1ff404624b6318ca741fcd7d0e77. You can customize this summary. It will automatically update as commits are pushed.

jschueller avatar Dec 13 '25 17:12 jschueller