# If/how --fresh can be applied recursively to subdirectories

**URL:** https://discourse.cmake.org/t/if-how-fresh-can-be-applied-recursively-to-subdirectories/11348
**Category:** Development
**Created:** [July 29, 2024, 7:29pm UTC](https://discourse.cmake.org/t/if-how-fresh-can-be-applied-recursively-to-subdirectories/11348 "2024-07-29T19:29:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![JosephTremoulet](https://discourse.cmake.org/user_avatar/discourse.cmake.org/josephtremoulet/32/4811_2.png) [@JosephTremoulet](https://discourse.cmake.org/u/JosephTremoulet)
#### Post date: [July 29, 2024, 7:29pm UTC](https://discourse.cmake.org/t/if-how-fresh-can-be-applied-recursively-to-subdirectories/11348/1 "2024-07-29T19:29:08Z")

</div>

Hi,

I was surprised to see that configuring with `--fresh` deletes object files in my root directory, but not in directories added with `add_subdirectory`. My questions are:

1. Is this intentional?
2. If so, is there a separate, “recursive” variant of `--fresh` ?

To show what I mean, here’s a console transcript. Note how `cmake --fresh ..` deletes `in_root_dir.cpp.o` but not `in_subdir.cpp.o`.

```bash
$ ls -R
.:
CMakeLists.txt in_root_dir.cpp subdir

./subdir:
CMakeLists.txt in_subdir.cpp
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.29)

project(ReproCase VERSION 1.0)

add_library(in_root_dir STATIC in_root_dir.cpp)

add_subdirectory(subdir)
$ cat subdir/CMakeLists.txt

add_library(in_subdir STATIC in_subdir.cpp)
$ mkdir build && cd build && cmake .. && cmake --build .
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.4s)
-- Generating done (0.0s)
-- Build files have been written to: <path>/build
[4/4] Linking CXX static library subdir/libin_subdir.a
$ find . -name '*.cpp.o'
./subdir/CMakeFiles/in_subdir.dir/in_subdir.cpp.o
./CMakeFiles/in_root_dir.dir/in_root_dir.cpp.o
$ cmake --fresh ..
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (0.4s)
-- Generating done (0.0s)
-- Build files have been written to: <path>/build
$ find . -name '*.cpp.o'
./subdir/CMakeFiles/in_subdir.dir/in_subdir.cpp.o

```

I actually was initially wondering more generally what interaction to expect between `--fresh` and incremental building, then was surprised to see the empirical answer depend on whether sources are in a subdirectory or not, so came here to ask.

Thanks,  
-Joseph

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [July 30, 2024, 1:47pm UTC](https://discourse.cmake.org/t/if-how-fresh-can-be-applied-recursively-to-subdirectories/11348/2 "2024-07-30T13:47:35Z")

</div>

> [@JosephTremoulet](#):
>
> configuring with `--fresh` deletes object files in my root directory, but not in directories added with `add_subdirectory`.

Configuring with `--fresh` deletes the `CMakeCache.txt` and `CMakeFiles/` directories from the top of the build tree. Those are where CMake’s builtin system and toolchain inspection results are stored. Some generators (like Ninja) happen to also store object files for the top-level directory under `CMakeFiles/` too, so for those it is simply a side effect that the object files are removed.
