mingw-distro icon indicating copy to clipboard operation
mingw-distro copied to clipboard

FreeType needs to upstream a CMakeLists.txt patch for the MSYS environment

Open StephanTLavavej opened this issue 1 year ago • 9 comments

With CMake 3.28.1 in MSYS2/mingw-w64, I need to patch a couple of lines in FreeType's CMakeLists.txt:

https://github.com/StephanTLavavej/mingw-distro/blob/f74a2a8c7eeb7b9a21763553e06c0cf77434098d/freetype-fix-cmake-mingw.patch#L1-L21

This is because this environment identifies itself as both UNIX and WIN32, but it lacks unistd.h and fcntl.h, and builds/unix/ftsystem.c is completely inappropriate for it.

Checking UNIX AND NOT MSYS is my current minimally-invasive approach. UNIX AND NOT WIN32 would also work (and for the second location selecting ftsystem.c, simply checking WIN32 before UNIX), but I'm not sure if that would negatively impact Cygwin.

This (or some similar fix) should be upstreamed to FreeType.

StephanTLavavej avatar Jan 07 '24 21:01 StephanTLavavej

Aside: This issue also affects SDL2, although I'm not yet using CMake for it.

StephanTLavavej avatar Jan 08 '24 02:01 StephanTLavavej

If we switch order of WIN32 and UNIX checks, would it work too?

apodtele avatar Jan 09 '24 14:01 apodtele

I believe so; that's what I said originally:

(and for the second location selecting ftsystem.c, simply checking WIN32 before UNIX)

StephanTLavavej avatar Jan 11 '24 11:01 StephanTLavavej

@lemzwerg @madig This seems necessary for CMake to work with mingw. Ok?

apodtele avatar Jan 12 '24 03:01 apodtele

I've never worked with MSYS, so I can't tell whether it works. So please proceed as you think it's best.

lemzwerg avatar Jan 12 '24 05:01 lemzwerg

Note that I don't fully understand the CMake build environment - I suspect that UNIX AND NOT MINGW AND NOT MSYS may be a more proper fix. It should be low-risk either way.

StephanTLavavej avatar Jan 14 '24 00:01 StephanTLavavej

Elsewhere we check WIN32 before UNIX to make sure that Windows native calls have priority under MinGW. This is robust, also works with MSVC and does not confuse unixes. Please use WIN32 instead of MSYS/MINGW because CMake is supposed to work with MSVC too. Secondly, is it possible to consolidate both code segments?

apodtele avatar Jan 14 '24 02:01 apodtele

Committed.

apodtele avatar Jan 14 '24 03:01 apodtele

Thank you! :heart_eyes_cat:

StephanTLavavej avatar Jan 14 '24 06:01 StephanTLavavej