CMake: Add Application Icon on Windows

Problem

When building for Windows, cmake generated executables do not contain application icon.

Solution

First, create an empty .rc file in your project, say bt.rc and fill with the following content:

IDI_ICON1 ICON DISCARDABLE "icon.ico"

Put icon.ico into the same folder. This is the folder where your CMakeLists.txt and bt.rc lies.

CMakeLists.txt should add the .rc file as the last argument i.e.

add_executable (bt "bt.cpp" bt.rc)

Note that it cannot be in filters but has to be explicitly the last argument!

Result:

Have a question⁉ Contact me.