# How to automatically add header and source files to executable without file(GLOB )?

**URL:** <https://discourse.cmake.org/t/how-to-automatically-add-header-and-source-files-to-executable-without-file-glob/395>\
**Category:** Code\
**Created:** [December 17, 2019, 1:19pm UTC](https://discourse.cmake.org/t/how-to-automatically-add-header-and-source-files-to-executable-without-file-glob/395 "2019-12-17T13:19:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![waxta](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/w/dec6dc/32.png) [@waxta](https://discourse.cmake.org/u/waxta)\
**Post date:** [December 17, 2019, 1:19pm UTC](https://discourse.cmake.org/t/how-to-automatically-add-header-and-source-files-to-executable-without-file-glob/395/1 "2019-12-17T13:19:11Z")

</div>

Hello. For now, I use `file(GLOB_RECURSE source_list "*.cpp" "*.h")` in order to automatically add new files to project. I work with Clion and it “doesn’t like” this function. I mean, when I want to generate function’s definition, Clion opens MOC generated files (I work with Qt). The problem has started to occur when I deleted source and headers variable definiotions (_set()_) and added _file(GLOB …)_. What’s the best way to substitute _file()_?

---

<div class="post-metadata">

**Author:** ![erk](https://discourse.cmake.org/user_avatar/discourse.cmake.org/erk/32/114_2.png) [@erk](https://discourse.cmake.org/u/erk)\
**Post date:** [December 17, 2019, 5:08pm UTC](https://discourse.cmake.org/t/how-to-automatically-add-header-and-source-files-to-executable-without-file-glob/395/2 "2019-12-17T17:08:39Z")

</div>

Using `file(GLOB_RECURSE...)` to include source files is a bad idea, the doc is clear on this subject:  
[https://cmake.org/cmake/help/latest/command/file.html?highlight=file#filesystem](https://cmake.org/cmake/help/latest/command/file.html?highlight=file#filesystem)

You should maintain an explicit list of files in your CMakeLists.txt.  
If those file are hand-edited file you have to add them _by hand_ in CMakeLists.txt just like you will add them manually in your favorite VCS.

If the file are generated files this is another story, you may have look at this blog entry:

> **[Generated Sources In CMake Builds - Crascit](https://crascit.com/2017/04/18/generated-sources-in-cmake-builds/)**
>
> Using the right methods, generated sources can be seamlessly incorporated into CMake builds with robust dependencies.
