Skip to content

Instantly share code, notes, and snippets.

@Niakr1s
Created November 23, 2019 19:55
Show Gist options
  • Save Niakr1s/749a88643e154320768e5972c80347cb to your computer and use it in GitHub Desktop.
Save Niakr1s/749a88643e154320768e5972c80347cb to your computer and use it in GitHub Desktop.
How to add icon to cmake app in windows
1. Put app.ico in directory.
2. Create app.rc in same directory with one line:
IDI_ICON1 ICON DISCARDABLE "app.ico"
3. Run command (Warning: it's app.o, not app.res, how it is mentioned in other manuals!)
windres app.rc -o app.o
4. add_executable(app
...
app.o
)
5. Proofit!
@Sourabh-AnanyaTech
Copy link

This is the only way to do it, what the heck is written in their manual

@F1Soda
Copy link

F1Soda commented Aug 27, 2023

Thanks!

@etherealxx
Copy link

Amazing, the only one i tried that works.

btw excuse me @b1ek , can you elaborate more on your CMAKE_AUTORCC method?

@b1ek
Copy link

b1ek commented Dec 6, 2023

Amazing, the only one i tried that works.

btw excuse me @b1ek , can you elaborate more on your CMAKE_AUTORCC method?

I set(CMAKE_AUTORCC ON) in the CMakeLists.txt, and it automatically picked up the icon from one of the resource files which i forgot where i put it.

I think I put the icon into the "IDI_ICON" resource with RCC which cmake put into windres for me. Im sorry if that's not clear enough, that project is more than a few years old and i was kinda in a hurry writing it so it is quite a mess 😅

Edit: found the .rc file

@xiaoweiChen
Copy link

Generate the object file is not a good way for cross platform, this can add the icon on Windows by my test.

@vinnyhorgan
Copy link

Hi! I was using this method but actually discovered you can simply add the ".rc" file to the sources and it should just work...

@Niyachelowick
Copy link

how do i use the icon with multiple windows?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment