[hatari-devel] Windows cross compile build inconsistencies with SDL2

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


This is a follow-up to my post yesterday regarding windows builds on a windows machine with msys2/mingw64. As part of my troubleshooting, I started looking into cross compiling the Hatari windows binary on my debian 10.8 (buster) machine as this appears to be the common route for windows builds.

The inconsistency issue comes from these lines in the hatari CMakeLists.txt file:

# Additional CFLAGS suggested by the SDL library:
execute_process(COMMAND pkg-config --cflags-only-other sdl2
   OUTPUT_VARIABLE DETECTED_SDL_CFLAGS
   ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(DETECTED_SDL_CFLAGS)
   add_definitions(${DETECTED_SDL_CFLAGS})
   # message(STATUS "Additional CFLAGS of SDL: ${DETECTED_SDL_CFLAGS}")
endif(DETECTED_SDL_CFLAGS)

There are two scenarios to consider for cross compiled windows builds and SDL2. 

Scenario 1: Linux install of SDL2 via its package manager and mingw SDL2 install

on my debian machine, i installed SDL2 v2.0.9 using apt. I also installed the mingw SDL2 v2.0.14 by downloading the tgz file from libsdl and running make cross with the correct prefix install directory.

In this scenario, when you run cmake with the cross compile toolchain, you will actually be getting the cflags from the linux SDL2 install. that’s because, pkg-config doesn’t know about the mingw SDL2 package config file. If you run pkg-config from the command line (like cmake would), you will get this:

$ pkg-config --cflags-only-other sdl2
   -D_REENTRANT

and this is the cflag you will cross compile with.

The correct output for mingw SDL2 v 2.0.14 should be:   -Dmain=SDL_main

And as I mentioned in my last post, this opens up other issues on both msys2/mingw64 executable linking as well as the linux cross compile. You will need to add the SDL2_LIBRARY to all the executables that aren’t in the CMAKE_CROSSCOMPILING section of all CMakeLists.txt files.

Scenario 2: No Linux SDL2 install; mingw SDL2 install

in this scenario, the pkg-config command will return nothing as it won’t find any linux sdl2 package config file. And it will cross compile with no additional cflags even though the mingw SDL2 has additional clfags.

The least intrusive fix to ensure we pick up the correct pkg-config information for SDL2, is to add the following line to the tool chain cmake file:

set(ENV{PKG_CONFIG_PATH} ${MINGW_ROOT_PATH}/lib/pkgconfig)

What this does is prepend an additional path to the pkg-config search path. This will ensure it will pick up the package config files for mingw first. On my debian machine MINGW_ROOT_PATH is /usr/x86_64-w64-mingw32 (for 64bit builds).

With this change, Hatari is built with the correct cflags as intended by their SDL2 package manager whether you’re building on linux or cross compiling a windows binary from linux.

If you made it here, thanks for your time.




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/