ivansafrin/Polycode — pull request #84 by mcclure (2012-01-08 10:14:43+00:00)
Title: Support mingw

Here's a single large patch comprising all the work from my bitbucket fork to make Polycode buildable with a mingw cross compiler. I did not include in the patch any changes to outputs of create_lua_library (i.e. lua files or PolycodeLUA.cpp type files), so if you accept this patch you will need to rerun the bindings generation afterward.

My mingw build process is to cmake with --target="Windows" --cmake-args="-DCMAKE_TOOLCHAIN_FILE=/Users/mcc/work/p/tmp/toolchain.cmake", where the toolchain.cmake file is: http://pastie.org/3147648

Changes in this patch by file:

create_lua_library.py:
Exclude new opengl-related header files from the lua binding process, fix a build problem caused by ParticleEmitter (an abstract class) getting a lua binding.

CMake/ExternalAssimp.cmake, CMake/ExternalBox2D.cmake, CMake/ExternalBullet.cmake, CMake/ExternalFreetype.cmake, CMake/ExternalLua51.cmake, CMake/ExternalOpenAL.cmake, CMake/ExternalPhysFS.cmake:
Pass through -DCMAKE_TOOLCHAIN_FILE when invoking child cmake scripts. This is totally necessary to support a cross compiler of any kind.

CMake/ExternalOggVorbis.cmake, CMake/ExternalPNG.cmake, CMake/physfs.cmake
The -DCMAKE_TOOLCHAIN_FILE fix. Also some additional help to find libraries and headers built by previous steps (this may be due to the FIND_LIBRARY problems, see below). For PNG, also swap in the alternate zlib.cmake (see below).

CMake/PolycodeIncludes.cmake, CMake/lua51.cmake, Player/Contents/CMakeLists.txt, Standalone/CMakeLists.txt
Change MSVC to MSVC OR MINGW.

CMake/zlib.cmake
Work around a bug in the stock zlib cmake script where the name of the rc compiler windres.exe was being hardcoded instead of using ${CMAKE_RC_COMPILER} as correct. I am emailing the zlib maintainer about this.

CMakeLists.txt
The change in this file is sort of weird and ugly. For some reason I do not understand, none of the FIND_PACKAGE calls work when in mingw mode. For this reason I wound up specifying the library and include paths for all the dependency packages by hand by setting many variables like PHYSFS_INCLUDE_DIR. This is ugly and, for some reason I don't understand, when compiling with cmake requires you to run the cmake step 3-4 times before it finally goes through-- the first time it will fail claiming that one of the SET variables is not in fact set, the second time it finds it but it fails claiming a different SET variable was not set, and so on, eventually it just stops complaining. Rather than this huge block of SETs, It would be superior to fix the various FindPNG.cmake, etc scripts but I don't really understand how they work.

Core/Contents/CMakeLists.txt
Add GLee, but only in mingw mode. Change some MSVCs to MSVC OR MINGWs. For MSVC OR MINGW, install PolycodeView.h and PolycodeView.cpp in the install dir (previously this was happening for apple or linux, but not windows).

Core/Contents/Include/GLee.h, Core/Contents/Source/GLee.cpp
Because MinGW is missing some of the headers available to MSVC, in order to get things like get things like glDeleteShader I just threw in the GLee library. This increases binary size a bit but I don't know how else to get all this wgl stuff to work with mingw. GLee is only built into polycode if you are compiling with MinGW.

Core/Contents/Include/PolyGLHeaders.h, Core/Contents/Source/PolyGLSLProgram.cpp, Core/Contents/Source/PolyGLSLShader.cpp, Core/Contents/Source/PolyGLSLShaderModule.cpp, Core/Contents/Source/PolyGLTexture.cpp, Core/Contents/Source/PolyGLVertexBuffer.cpp, Core/Contents/Source/PolyWinCore.cpp
The boilerplate used to include opengl headers and repeated across many files in Polycode is condensed into a single file, PolyGLHeaders.h. PolyGLHeaders.h also serves the purpose of including GLee.h when compiling with MinGW, and (also when compiling with MinGW) contains some glue to make Polycode's existing wgl stuff work with GLee.

Core/Contents/Include/PolyGLRenderer.h, Core/Contents/Include/PolyRenderer.h
Don't use "near" and "far" as variable names; this breaks MinGW for some stupid reason related to addressing modes in Windows 3.1.

Core/Contents/Source/PolyGLRenderer.cpp
#ifdef out some stuff that conflicts with GLee, when _MINGW is defined.

Modules/Bindings/2DPhysics/CMakeLists.txt, Modules/Bindings/3DPhysics/CMakeLists.txt
More of the FIND_PACKAGE workarounds.