Skip to content

Conversation

@jschueller
Copy link
Contributor

@jschueller jschueller commented Dec 13, 2025

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 f91fb3c. You can customize this summary. It will automatically update as commits are pushed.

@jschueller jschueller requested a review from brtnfld as a code owner December 13, 2025 17:24
@github-project-automation github-project-automation bot moved this to To be triaged in HDF5 - TRIAGE & TRACK Dec 13, 2025
@jschueller jschueller changed the title CMake: Fix cross-compilation support CMake: Fix Fortran cross-compilation support Dec 13, 2025
@jschueller jschueller force-pushed the cross branch 2 times, most recently from 93ef341 to f91fb3c Compare December 20, 2025 17:10
@brtnfld
Copy link
Collaborator

brtnfld commented Dec 30, 2025

Location: config/toolchain/mingw64.cmake:28-29

Problem: The toolchain file sets CMAKE_CROSSCOMPILING_EMULATOR=wine64 without WINEPATH configuration. Current State:

set(CMAKE_CROSSCOMPILING_EMULATOR wine64) # Missing WINEPATH!
set(CROSSCOMPILING_PATH "WINEPATH=/usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/") # Ignored!

Option A: Simple solution:
set(CMAKE_CROSSCOMPILING_EMULATOR
env WINEPATH=/usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/ wine64
)

Option B (Wrapper script - cleaner):

Create wrapper script at configure time

file(WRITE "${CMAKE_BINARY_DIR}/mingw-wine-wrapper.sh" "#!/bin/sh
export WINEPATH=/usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin
exec wine64 "$@"
")
file(CHMOD "${CMAKE_BINARY_DIR}/mingw-wine-wrapper.sh"
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE)

set(CMAKE_CROSSCOMPILING_EMULATOR "${CMAKE_BINARY_DIR}/mingw-wine-wrapper.sh")

ALSO:

Current:

if (NOT CMAKE_CROSSCOMPILING OR (CMAKE_CROSSCOMPILING AND CMAKE_CROSSCOMPILING_EMULATOR))

Simplified:

if (NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR)

Summary:

Proposed Change to config/toolchain/mingw64.cmake:

Untested

# CMAKE_CROSSCOMPILING_EMULATOR: Wrapper script for running Windows binaries during build
# Must include WINEPATH so Wine can find system DLLs
file(WRITE "${CMAKE_BINARY_DIR}/cmake-wine-wrapper.sh" "#!/bin/sh
# Wine wrapper for MinGW cross-compilation
export WINEPATH=/usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin
exec wine64 \"$@\"
")
file(CHMOD "${CMAKE_BINARY_DIR}/cmake-wine-wrapper.sh" 
     PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE)

set(CMAKE_CROSSCOMPILING_EMULATOR "${CMAKE_BINARY_DIR}/cmake-wine-wrapper.sh")

# CROSSCOMPILING_PATH: Used by CTest ENVIRONMENT property for test execution
# This is separate from CMAKE_CROSSCOMPILING_EMULATOR and still needed for tests
set(CROSSCOMPILING_PATH "WINEPATH=/usr/${TOOLCHAIN_PREFIX}/sys-root/mingw/bin/")

@brtnfld brtnfld self-assigned this Dec 30, 2025
@jschueller jschueller force-pushed the cross branch 2 times, most recently from 4f6c278 to 2591ce2 Compare January 1, 2026 14:21
@jschueller jschueller force-pushed the cross branch 5 times, most recently from a94f659 to 4549437 Compare January 1, 2026 19:37
@jschueller jschueller force-pushed the cross branch 2 times, most recently from a4b08e1 to bcfa3cb Compare January 1, 2026 19:44
@jschueller
Copy link
Contributor Author

@brtnfld no need for cmake to generate the wrapper script, it can be a preexisting file like the toolchain script, see the file wine64.sh I added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To be triaged

Development

Successfully merging this pull request may close these issues.

3 participants