How to set an Icon in NSIS install (CMake)
Asked Answered
S

2

6

The documentation for CPACK_PACKAGE_ICON is very limited on cmake wiki page.

The following is not working for me (as per):

set(CPACK_PACKAGE_ICON  "${CMAKE_CURRENT_SOURCE_DIR}/images/MyIcon.bmp")
include(CPack)

It leads to:

File: "C:/proj/my_library/images/MyIcon.bmp" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
   /oname=outfile one_file_only)
Error in macro MUI_HEADERIMAGE_INIT on macroline 24
Error in macro MUI_GUIINIT on macroline 3
Error in macro MUI_FUNCTION_GUIINIT on macroline 4
Error in macro MUI_INSERT on macroline 11
Error in macro MUI_LANGUAGE on macroline 7
Error in script "C:/proj/bin-win/_CPack_Packages/win32/NSIS/project.nsi" on line 574 -- aborting creation process

So how does one actually set a working icon during the install process of a NSIS installer ? Also what format is actually needed for the icon ?

Sanjiv answered 27/2, 2015 at 15:20 Comment(0)
S
11

After some trial-and-error I finally found out two tricks required:

The syntax is actually:

set(CPACK_PACKAGE_ICON  "${CMAKE_CURRENT_SOURCE_DIR}/images\\\\MyIcon.bmp")

And the BMP file is restricted to an older format, which is not the default for imagemagick. Eg:

$ file MyIcon.bmp
MyIcon.bmp: PC bitmap, Windows 98/2000 and newer format, 128 x 128 x 24

what is needed is this:

$ convert MyIcon.bmp BMP3:MyIcon2.bmp
$ file MyIcon2.bmp
MyIcon2.bmp: PC bitmap, Windows 3.x format, 128 x 128 x 24

The first representation (Windows 98/2000 and newer format) did not work for me.

Sanjiv answered 27/2, 2015 at 15:23 Comment(3)
Isn't it 150x57 in size (under MUI_HEADERIMAGE_BITMAP_RTL if you expand Interface settings, Page header)?Lyall
This was haunting me, now after 6 years, you still have to generate images in BPM Windows 3.x format which few tools seem to support.Jasonjasper
I think this is due to the NSIS installer, I think PNG support or something should be added to NSIS. Related issue: sourceforge.net/p/nsis/feature-requests/559Bellicose
I
0

For me that command in CMakeLists.txt works fine:

set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/images\\\\icon.ico")

I found it here https://cmake.org/cmake/help/v3.0/module/CPackNSIS.html

Intuitive answered 9/6, 2022 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.