If your a cross platform game dev like me, one of the many issues that come up are how to get an exe to have an Icon on windows. Well it turns out you can do it easily with mingw (I’m sure you can get it to work using other compilers).

Here is the link to the stack overflow article  http://stackoverflow.com/questions/708238/how-do-i-add-an-icon-to-a-mingw-gcc-compiled-executable. All you do is create a file, run this program called “windres” on it (It apparently comes on Windows). That turns the file into object code that you can statically link into your binary. Works awesome,  but “windres” is picky about the image file format, so watch out.

It isn’t really very strait forward to get this to work on CMake. The following is code out of my CMakeLists.txt file that seems to do the trick:

# This sets up the exe icon for windows under mingw.
set(RES_FILES "")
if(MINGW)
 set(RES_FILES "Win32/client.rc")
 set(CMAKE_RC_COMPILER_INIT windres)
 ENABLE_LANGUAGE(RC)
 SET(CMAKE_RC_COMPILE_OBJECT
 "<CMAKE_RC_COMPILER> <FLAGS> -O coff <DEFINES> -i <SOURCE> -o <OBJECT>")
endif(MINGW)

add_executable(OpenSpaceClient client-main ${RES_FILES})

 

This works by creating some sort of additional compiler that calls “windres” as a RC compiler (RC is a made up name, I think you can use anything). As you can see this only gets run if the development environment is mingw.

I hope this is useful.