# CMake commands cause project build to walk entire drive.

**URL:** https://discourse.cmake.org/t/cmake-commands-cause-project-build-to-walk-entire-drive/2913
**Category:** Usage
**Created:** [March 7, 2021, 9:14pm UTC](https://discourse.cmake.org/t/cmake-commands-cause-project-build-to-walk-entire-drive/2913 "2021-03-07T21:14:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![alecazam](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alecazam/32/1099_2.png) [@alecazam](https://discourse.cmake.org/u/alecazam)
#### Post date: [March 7, 2021, 9:14pm UTC](https://discourse.cmake.org/t/cmake-commands-cause-project-build-to-walk-entire-drive/2913/1 "2021-03-07T21:14:31Z")

</div>

These lines sent Cmake into a lengthy walk of the entire drive when trying to build a project, see if you can spot the mistake. I’ll post the answer in a bit, but seems like an easy mistake to make and that should be caught by the parser.

set(SDK\_DIR, “${PROJECT\_SOURCE\_DIR}”)  
set(SDK\_SOURCE\_DIR, “${SDK\_DIR}/foo”)

file(GLOB\_RECURSE sdkSources CONFIGURE\_DEPENDS  
“${SDK\_SOURCE\_DIR}/\*.cpp”  
)

---

<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: [March 7, 2021, 10:17pm UTC](https://discourse.cmake.org/t/cmake-commands-cause-project-build-to-walk-entire-drive/2913/2 "2021-03-07T22:17:13Z")

</div>

The comma? It’s a valid variable character (though one we could possibly deny as a literal name via a policy). This will still always work:

```cmake
set(varname "foo,")
set("${varname}" value)

```

That said…maybe one shouldn’t use `GLOB_RECURSE` for source file listings 🙂 . I, personally, [would never recommend it](https://discourse.cmake.org/t/is-glob-still-considered-harmful-with-configure-depends/808).

That said, there are warnings for unused/undefined variables you can ask for upon request (`--warn-unused` and `--warn-undefined`).

---

<div class="post-metadata">

### Author: ![alecazam](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alecazam/32/1099_2.png) [@alecazam](https://discourse.cmake.org/u/alecazam)
#### Post date: [March 7, 2021, 11:53pm UTC](https://discourse.cmake.org/t/cmake-commands-cause-project-build-to-walk-entire-drive/2913/3 "2021-03-07T23:53:50Z")

</div>

Correct version is this without commas on the set calls.

And one either explicitly lists files in huge directory listings, or GLOB\_RECURSE and exclude. Depends on how much effort one wants to go to listing everything out especially when the projects you pull are changing a lot. Personally prefer to limit changes to the CMakeLists.txt files in this case.

set(SDK\_DIR “${PROJECT\_SOURCE\_DIR}”)  
set(SDK\_SOURCE\_DIR “${SDK\_DIR}/foo”)

file(GLOB\_RECURSE sdkSources CONFIGURE\_DEPENDS  
“${SDK\_SOURCE\_DIR}/\*.cpp”  
)

---

<div class="post-metadata">

### Author: ![riggs](https://discourse.cmake.org/user_avatar/discourse.cmake.org/riggs/32/1284_2.png) [@riggs](https://discourse.cmake.org/u/riggs)
#### Post date: [March 13, 2021, 3:53am UTC](https://discourse.cmake.org/t/cmake-commands-cause-project-build-to-walk-entire-drive/2913/4 "2021-03-13T03:53:18Z")

</div>

> [@alecazam](#):
>
> Personally prefer to limit changes to the CMakeLists.txt files in this case.

Personally, I prefer to spend a bit of time explicitly listing the ~100 SDK files getting compiled into my binaries. It gives me security when updating SDK version, assurance that new installs are done correctly, avoids potential naming conflicts, and easily allows me to mock library APIs in tests.
