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 ?

malat
  • 12,152
  • 13
  • 89
  • 158

2 Answers2

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.

malat
  • 12,152
  • 13
  • 89
  • 158
  • 3
    Isn't it [150x57 in size](http://nsis.sourceforge.net/Docs/Modern%20UI/Readme.html) (under MUI_HEADERIMAGE_BITMAP_RTL if you expand Interface settings, Page header)? – mlt Dec 11 '15 at 22:16
  • 1
    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. – thoni56 May 26 '21 at 13:03
  • I think this is due to the NSIS installer, I think PNG support or something should be added to NSIS. Related issue: https://sourceforge.net/p/nsis/feature-requests/559/ – Melroy van den Berg Jan 21 '22 at 23:00
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

Nikita
  • 1
  • 1