Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the application icon with CMake

Is there a cross-platform way to set the application icon with CMake? I am using Cmake 3.0.2 with Qt 5.4.

In the Qt documentation a method is shown but it is not cross-platform.

like image 284
TheHube Avatar asked Mar 19 '15 13:03

TheHube


1 Answers

CMake doesn't handle this for you.

On some platforms are are several "application icons". For example, on a UNIX-like system which follows the FreeDesktop.org standards (essentially anything you can see today on Linux, no matter if it's KDE, Gnome, Unity, XFCE or some other DE-du-jour), this is done by setting an appropriate Icon entry in the application's .desktop file. See the .desktop spec for details. This is what gets shown as a launcher's icon, and some DEs such as the recent Plasma will use this for a window icon in the taskbar, with appropriate theme overrides.

Maybe you are shipping a Windows installer, too, perhaps based on the NSIS. Then you should probably specify this in your .nsi as well.

Actual window icons are something which should be set up by the programmer, too. As you can see, there's plenty of places where an "application icon" might be set. If you're looking for a real-world example, check out Trojitá's source code. Look for actual icon file installation through CMake, for the NSIS code, for creating a Windows RC file, and finally for setting the application icon from the C++ code.

like image 158
Jan Kundrát Avatar answered Sep 18 '22 03:09

Jan Kundrát