# How to easily add CMake files to be visibile in IDE generators (Visual Studio)?

**URL:** https://discourse.cmake.org/t/how-to-easily-add-cmake-files-to-be-visibile-in-ide-generators-visual-studio/937
**Category:** Usage
**Tags:** os:windows, gen:vs
**Created:** [April 3, 2020, 11:30pm UTC](https://discourse.cmake.org/t/how-to-easily-add-cmake-files-to-be-visibile-in-ide-generators-visual-studio/937 "2020-04-03T23:30:16Z")
**Posts on this page:** 5
**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: [April 3, 2020, 11:30pm UTC](https://discourse.cmake.org/t/how-to-easily-add-cmake-files-to-be-visibile-in-ide-generators-visual-studio/937/1 "2020-04-03T23:30:16Z")

</div>

Throughout my code base I have this re-ocurring pattern to provide friendly Visual Studio Support.

```auto
target_sources(foo PRIVATE
        # Add CMakeLists.txt so it shows up in Visual Studio generated projects
	CMakeLists.txt
	...
)

```

I even do this for my custom modules:

```auto
target_sources(foo PRIVATE
        # Add modules so they shows up in Visual Studio generated projects
	foo.cmake
	...
)

```

Is there an easy, good, fast way to do this? Adding them manually as shown above does work but is tedious and error prone.

I tried globbing but our project is pretty big and that adds 10 seconds to the configuration time.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 6, 2020, 2:19pm UTC](https://discourse.cmake.org/t/how-to-easily-add-cmake-files-to-be-visibile-in-ide-generators-visual-studio/937/2 "2020-04-06T14:19:51Z")

</div>

I think how you’ve described it is how I’d do it. If you wrapped `add_library`, you could probably do this in such a wrapper.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [April 7, 2020, 6:56am UTC](https://discourse.cmake.org/t/how-to-easily-add-cmake-files-to-be-visibile-in-ide-generators-visual-studio/937/3 "2020-04-07T06:56:10Z")

</div>

FWIW, you don’t have to add them extra via `target_sources`. You can just list them directly in the `add_library`/`add_executable` command. All our projects at work do it this way, and it works just fine.

---

<div class="post-metadata">

### Author: ![vre](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/v/f04885/32.png) [@vre](https://discourse.cmake.org/u/vre)
#### Post date: [April 7, 2020, 7:41am UTC](https://discourse.cmake.org/t/how-to-easily-add-cmake-files-to-be-visibile-in-ide-generators-visual-studio/937/4 "2020-04-07T07:41:18Z")

</div>

Interesting, we do not add them but they are automagically added to the targets in the generated Visual Studio solution. But I guess it only works when you define a target in a CMakeLists.txt.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [April 7, 2020, 10:56am UTC](https://discourse.cmake.org/t/how-to-easily-add-cmake-files-to-be-visibile-in-ide-generators-visual-studio/937/5 "2020-04-07T10:56:51Z")

</div>

The `CMakeLists.txt` for a target should be added automatically, but this is only the one for the directory owning the `add_library` or `add_executable` call. If you gather sources in subdirectories or have helper files, they’d need manually listed.
