cmakensisbmpcpack

How to set an Icon in NSIS install (CMake)


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 ?


Solution

  • 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.