rougier / freetype-gl

OpenGL text using one vertex buffer, one texture and FreeType
Other
1.65k stars 266 forks source link

Add support for building with msys2 MinGW #133

Closed schmittl closed 7 years ago

schmittl commented 8 years ago

Hi, I got all demos running on Windows using the msys2 MinGW64 gcc toolchain. msys2 provides easy access to all required packages / dependencies (except AntTweakBar, but see below), so it makes building native binaries on Windows less of a headache. It took me some nights to figure all out, so I wanted to propose some changes to make it easier for others using Windows. (if there is anyone)

Most demos work without needing any changes, but for some I had to make some adjustments:

makefont demo

I needed to change the makefont target in CMakeLists.txt to only add MATH_LIBRARY if the library is found. This is already done in the other CMakeLists.txt files so I guess that is the reasonable thing to do:

if(MATH_LIBRARY)
     target_link_libraries(makefont ${MATH_LIBRARY})
endif()

To support modern format specifiers like %zu in fprintfI also needed to add this flag:

if(MINGW)
    add_definitions(-D__USE_MINGW_ANSI_STDIO)
endif()

markup demo

Currently a runtime error is produced on windows with the following messages:

"font_manager_match_description" not implemented for windows. "font_manager_get_from_description" not implemented yet. Houston, we've got a problem !

To make it work:

atb-agg demo

gcc can link the import libraries from windows/AntTweakBar/lib/ without problems, just one change is required in FindAntTweakBar.cmake. CMake seems to default to .dll extension, so that needs to change into .lib. Relevant snippet: FIND_LIBRARY( ANT_TWEAK_BAR_LIBRARY AntTweakBar.lib

Caveat: This works fine for 32-bit, but for 64-bit it fails. It still includes the 32-bit lib, but should include AntTweakbar64.lib. I am not sure yet what the best way is to handle different library names for 32 and 64-bit with CMake.

It was also necessary to link fontconfig for the target in demos/CMakeLists.txt

target_link_libraries(atb-agg ${ANT_TWEAK_BAR_LIBRARY} ${FONTCONFIG_LIBRARY})

harfbuzz and hb-texture demos

On Windows symlinks are a bit problematic and are thus disabled for git by default. See git-for-windows/wiki for details.

I did the following to make it work:

Caveat: include "texture-font.h" would need to come before other freetype-gl includes in demo-harfbuzz.c and demo-texture.c. Otherwise the texture-font.h from the project root directory would get included, making it not compile.

I took some notes and can provide full install instructions to setup the toolchain e.g. to include in INSTALL.md.

I'd be happy to make a PR for all this (it is probably easier to discuss code there), but I wanted to hear you guys thoughts on this first. There are perhaps better solutions for some of the problems I mentioned.

PS Sorry for the wall of text, but thanks for reading.

adrianbroher commented 7 years ago

Fixed with #134