# Setting default document icon with CMake for windows

**URL:** <https://forum.juce.com/t/setting-default-document-icon-with-cmake-for-windows/43653>\
**Category:** Windows\
**Created:** [January 5, 2021, 10:23am UTC](https://forum.juce.com/t/setting-default-document-icon-with-cmake-for-windows/43653 "2021-01-05T10:23:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicobert](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nicobert/32/10191_2.png) [@Nicobert](https://forum.juce.com/u/Nicobert)\
**Post date:** [January 5, 2021, 10:23am UTC](https://forum.juce.com/t/setting-default-document-icon-with-cmake-for-windows/43653/1 "2021-01-05T10:23:03Z")

</div>

Hello,

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 :

```auto
    set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
		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 :

```auto
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 :

```auto
juce_add_gui_app(${EXECUTABLE_NAME}
  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.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [January 5, 2021, 7:01pm UTC](https://forum.juce.com/t/setting-default-document-icon-with-cmake-for-windows/43653/2 "2021-01-05T19:01:04Z")

</div>

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

```cpp
#pragma code_page(65001)

#ifdef JUCE_USER_DEFINED_RC_FILE
 #include JUCE_USER_DEFINED_RC_FILE
#else

// predefined data goes here

#endif

IDI_ICON1 ICON DISCARDABLE "icon.ico"
IDI_ICON2 ICON DISCARDABLE "icon.ico"

```

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.

---

<div class="post-metadata">

**Author:** ![Nicobert](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nicobert/32/10191_2.png) [@Nicobert](https://forum.juce.com/u/Nicobert)\
**Post date:** [January 6, 2021, 3:24pm UTC](https://forum.juce.com/t/setting-default-document-icon-with-cmake-for-windows/43653/3 "2021-01-06T15:24:44Z")

</div>

That completely solve my problem.  
Thank you @reuk !

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [April 7, 2022, 2:54am UTC](https://forum.juce.com/t/setting-default-document-icon-with-cmake-for-windows/43653/4 "2022-04-07T02:54:43Z")

</div>

> [@reuk](#):
>
> Resource files generated by the Projucer and CMake use the preprocessor like so:

@reuk - is it possible for you to explain how you would use this for a custom resources.rc file in a Projucer Project for VS 2019? I’m trying to understand how you might do this, and not coming up with a lot. A lot of old posts seem to talk about it “not working” or “being a bug”.

Where do I put my custom resources.rc file? Do I include it into the Projucer sources? Or it just sits in a folder in my sources, and I provide a path to it?

Where do I define JUCE\_USER\_DEFINED\_RC\_FILE? This is defined as the path to the file? And what field/box do I put this info in in the Projucer?

Sorry if this may be obvious, I’m confused.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 7, 2022, 3:33pm UTC](https://forum.juce.com/t/setting-default-document-icon-with-cmake-for-windows/43653/5 "2022-04-07T15:33:00Z")

</div>

I think this is not currently supported in the Projucer. It might not be too difficult to enable, I’ll take a look.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 11, 2022, 12:52pm UTC](https://forum.juce.com/t/setting-default-document-icon-with-cmake-for-windows/43653/6 "2022-04-11T12:52:54Z")

</div>

I’ve updated the Projucer on develop so that this should work now:

- Create a custom resources file in your Source directory
- Add `JUCE_USER_DEFINED_RC_FILE="/path/to/file"` to the custom preprocessor definitions for your project

Depending on the path you use, you may also need to add an entry to the additional header search paths, so that the include can be found.

> <https://github.com/juce-framework/JUCE/commit/14ab027b0e968408b6b7a8bf531f7ffa38d2a6b1>
>
> This more closely matches the behaviour of CMake when adding rc files to
> targets….

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [April 14, 2022, 10:00pm UTC](https://forum.juce.com/t/setting-default-document-icon-with-cmake-for-windows/43653/9 "2022-04-14T22:00:33Z")

</div>

Thanks @reuk! It’s working great.
