-
-
Save Niakr1s/749a88643e154320768e5972c80347cb to your computer and use it in GitHub Desktop.
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! |
thank you! In my case, i didn't have to compile it with windres, CMAKE_AUTORCC
did it.
This is the only way to do it, what the heck is written in their manual
Thanks!
Amazing, the only one i tried that works.
btw excuse me @b1ek , can you elaborate more on your CMAKE_AUTORCC
method?
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
Generate the object file is not a good way for cross platform, this can add the icon on Windows by my test.
Hi! I was using this method but actually discovered you can simply add the ".rc" file to the sources and it should just work...
how do i use the icon with multiple windows?
This post is incorrect. The Doc identify option /fo resname for anyone using cmake here is a snippet that generates the .RES script form RC compilation. Also make sure the resource.h file include windows.h header file .
adds a custom build step to a file. Generates the resources
add_custom_command(
TARGET LibTransactX
PRE_BUILD
DEPENDS RC
COMMAND RC /v /r ${CMAKE_SOURCE_DIR}/res/app.rc
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/res"
COMMENT "Build step to produce the icon file"
)
Hi! I was using this method but actually discovered you can simply add the ".rc" file to the sources and it should just work...
Thank you for sharing, just including the .rc in sources allowed me to skip step 3 and 4.
ImGui GLFW window add icon
stbi_load function
https://github.com/nothings/stb/blob/master/stb_image.h
GLFWimage images[1];
images[0].pixels = stbi_load("icon_should_be_same_folder_with_exe.png", &images[0].width, &images[0].height, 0, 4);
glfwSetWindowIcon(window, 1, images);
stbi_image_free(images[0].pixels);
You can use magick to convert png to icon. The main thing is that the png sizes are the right size.
PNG dimensions: 16x16, 32x32, 256x256
In the console, we convert using magick:
magick.exe convert myIcon.png icon.ico
In CMakeLists.txt we specify the path to the rc file in add_executable, I had it like this:
add_executable(${PROJECT_NAME} WIN32
${ALL_HEADERS}
${ALL_SOURCES}
qml.qrc
resource/resource.qrc
resource/app.rc
)
app.rc file:
IDI_ICON1 ICON DISCARDABLE "icon.ico"
this is easier
https://www.icoconverter.com/
This totally works :D