# What does adding a module definition file via target\_sources do?

**URL:** https://discourse.cmake.org/t/what-does-adding-a-module-definition-file-via-target-sources-do/7610
**Category:** Usage
**Created:** [March 6, 2023, 7:11pm UTC](https://discourse.cmake.org/t/what-does-adding-a-module-definition-file-via-target-sources-do/7610 "2023-03-06T19:11:22Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![buildSystemPerson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/buildsystemperson/32/2851_2.png) [@buildSystemPerson](https://discourse.cmake.org/u/buildSystemPerson)
#### Post date: [March 6, 2023, 9:01pm UTC](https://discourse.cmake.org/t/what-does-adding-a-module-definition-file-via-target-sources-do/7610/3 "2023-03-06T21:01:37Z")

</div>

> What you might be thinking about is how does a `*.def` file listed in the sources for a target end up being handled.

Yes that is what I was trying to ask. I tried reading the CMake code but it was unclear to me.

> I don’t know if the special handling for `MSVC` in your example is necessary.

I’m not sure based on my past experience it seems there are minor differences between Ninja / Visual  
Studio builds on MSVC:

> [@Does adding \`.natvis\` files via target\_sources work on Ninja?](https://discourse.cmake.org/t/does-adding-natvis-files-via-target-sources-work-on-ninja/7316):
>
> According to the docs as of CMake 3.7 [Visual Studio Generators](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#visual-studio-generators) for VS 2010 and above learned to place .natvis source files into VS project files properly. Which means the following will work correctly with Visual Studio generators. target\_sources(foobar PRIVATE foobar.natvis) Will this also work for Ninja on MSVC? Do I need to guard this with a check for MSVC?

---

_[View the full topic](https://discourse.cmake.org/t/what-does-adding-a-module-definition-file-via-target-sources-do/7610)._
