Setting default document icon with CMake for windows


To create an installer for my juce application I am using CPack with NSIS. My application generate .myExt files to save its data. And I want .myExt files to have a fancy icon.

To do so, for what I understand, I need to do this with CPack :

		WriteRegStr HKCR '.myExt' '' 'myfile'
		WriteRegStr HKCR 'myfile' '' 'MyApp Document'
		WriteRegStr HKCR 'myfile\\\\DefaultIcon' '' '$INSTDIR\\\\bin\\\\${EXECUTABLE_NAME}.exe,0'
		WriteRegStr HKCR 'myfile\\\\shell\\\\open\\\\command' '' '$INSTDIR\\\\bin\\\\${EXECUTABLE_NAME}.exe %1'
		WriteRegStr HKCR 'myfile\\\\shell\\\\print\\\\command' '' '$INSTDIR\\\\bin\\\\${EXECUTABLE_NAME}.exe /p %1'
		WriteRegStr HKLM 'Software\\\\RegisteredApplications' '${EXECUTABLE_NAME}' '$INSTDIR\\\\bin\\\\${EXECUTABLE_NAME}.exe'
		WriteRegStr HKCU 'Software\\\\RegisteredApplications' '${EXECUTABLE_NAME}' '$INSTDIR\\\\bin\\\\${EXECUTABLE_NAME}.exe'
		WriteRegStr HKCU 'Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Explorer\\\\FileExts\\\\.myExt\\\\OpenWithList' 'a' '$INSTDIR\\\\bin\\\\${EXECUTABLE_NAME}.exe'

The important line is :

WriteRegStr HKCR 'myfile\\\\DefaultIcon' '' '$INSTDIR\\\\bin\\\\${EXECUTABLE_NAME}.exe,0'

The index at the end of the file is the one of the icon I want to use. It is specified in the .rc files of the application.

Here is my problem, the cmake api of Juce already generate and link a rc file. I cannot generate and use my custom .rc file. If I use the index 0 or 1, it will use the application icon ICON_BIG or ICON_SMALL specify in :

  ICON_BIG "${PLACEHOLDER_DIR}/icon_big.png"                      # ICON_* arguments specify a path to an image file to use as an icon
  ICON_SMALL "${PLACEHOLDER_DIR}/icon_small.png"

Is there a way to specify a third icon in the juce rc file ?
Should I use another method to link a fancy icon to my .myExt files ? Which one ?

Thank you for your help.

Resource files generated by the Projucer and CMake use the preprocessor like so:

#pragma code_page(65001)


// predefined data goes here



This means you can write your own resources.rc and add something like JUCE_USER_DEFINED_RC_FILE=${CMAKE_CURRENT_SOURCE_DIR}/path/to/resources.rc to your target_compile_definitions call. The generated resources.rc will then include your custom file.

1 Like

That completely solve my problem.
Thank you @reuk !