# How to use Resource Files (.rc) in CMake?

**URL:** <https://discourse.cmake.org/t/how-to-use-resource-files-rc-in-cmake/2628>\
**Category:** Usage\
**Tags:** comp:msvc, gen:vs, gen:ninja\
**Created:** [January 26, 2021, 12:38am UTC](https://discourse.cmake.org/t/how-to-use-resource-files-rc-in-cmake/2628 "2021-01-26T00:38:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Post date:** [January 26, 2021, 12:38am UTC](https://discourse.cmake.org/t/how-to-use-resource-files-rc-in-cmake/2628/1 "2021-01-26T00:38:13Z")

</div>

I have added a resource file to my project like so:

```auto
target_sources(foobar PRIVATE foobar.rc)

```

I’m able to successfully compile my project with Visual Studio. However, my Ninja build fails.

---

<div class="post-metadata">

**Author:** ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)\
**Post date:** [January 26, 2021, 7:02am UTC](https://discourse.cmake.org/t/how-to-use-resource-files-rc-in-cmake/2628/2 "2021-01-26T07:02:21Z")

</div>

> [@YMba9g8j9CJp0wLoQf5y](#):
>
> However, my Ninja build fails.

What’s the error?

---

<div class="post-metadata">

**Author:** ![YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ymba9g8j9cjp0wloqf5y/32/1244_2.png) [@YMba9g8j9CJp0wLoQf5y](https://discourse.cmake.org/u/YMba9g8j9CJp0wLoQf5y)\
**Post date:** [January 26, 2021, 7:58pm UTC](https://discourse.cmake.org/t/how-to-use-resource-files-rc-in-cmake/2628/4 "2021-01-26T19:58:24Z")

</div>

I figured out the cause of my issue.

For future CMake users the following code should be enough.

```auto
target_sources(foobar PRIVATE foobar.rc)

```

However, I was providing a custom toolchain. Which was the cause of my problem.

And here is the problem.

On visual studio here is how you set the system include directories:

```auto
set(CMAKE_VS_SDK_INCLUDE_DIRECTORIES ${CUSTOM_INCLUDE_DIRECTORIES})

```

On Ninja (IE everything else) you have to do this:

```auto
        # Include Directories
        foreach(LANG C CXX)
            set(CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES ${CUSTOM_INCLUDE_DIRECTORIES})
        endforeach()

```

Do you see the bug? It took me having to manually run the RC commands to find it.  
Because Ninja was hiding/obscuring the RC fatal error message.

```auto
fatal error RC1015: cannot open include file 'winres.h'

```

The problem was CMAKE\_RC\_STANDARD\_INCLUDE\_DIRECTORIES was set to nothing!  
Here is the fix:

```auto
        # Include Directories, NOTE THE RC LANGUAGE IS IMPORTANT!
        foreach(LANG C CXX RC)
            set(CMAKE_${LANG}_STANDARD_INCLUDE_DIRECTORIES ${CUSTOM_INCLUDE_DIRECTORIES})
        endforeach()

```

This is why my build was working on Visual Studio but not Ninja.
