# Usage of ctest\_empty\_binary\_directory

**URL:** https://discourse.cmake.org/t/usage-of-ctest-empty-binary-directory/7632
**Category:** Usage
**Created:** [March 8, 2023, 2:54pm UTC](https://discourse.cmake.org/t/usage-of-ctest-empty-binary-directory/7632 "2023-03-08T14:54:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![codeling](https://discourse.cmake.org/user_avatar/discourse.cmake.org/codeling/32/1700_2.png) [@codeling](https://discourse.cmake.org/u/codeling)
#### Post date: [March 8, 2023, 2:54pm UTC](https://discourse.cmake.org/t/usage-of-ctest-empty-binary-directory/7632/1 "2023-03-08T14:54:25Z")

</div>

We have our own CTest script runner.  
In that, I’m not sure how best to use [`ctest_empty_binary_directory`](https://cmake.org/cmake/help/latest/command/ctest_empty_binary_directory.html), and its interplay with `ctest_start`.

The bin folder seems to be created in ctest\_start; so it seems that `ctest_empty_binary_directory` should be called before it?  
The problem is, I only want to empty the directory in case the build actually runs; meaning that for “Continuous” mode, it should only empty the bin folder if there were any updates; but if I do the emptying after the update step, then the configure step complains about a missing bin directory.  
If I do the update before the `ctest_start`, it complains that `ctest_start` has to be called before `ctest_update`.  
How is this handled in the “default” script? (i.e. whatever runs the dashboard mode when no user script is given; Is that default script available as a cmake script somewhere maybe so that I could look it up how it’s handled there?) Is the emptying of the bin folder even triggered there under some conditions?  
(EDIT: does share\cmake-CMAKE\_VERSION\Templates\CTestScript.cmake.in get used somehow? - there `CTEST_EMPTY_BINARY_DIRECTORY` is commented out?)

---

<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 11, 2023, 1:03am UTC](https://discourse.cmake.org/t/usage-of-ctest-empty-binary-directory/7632/2 "2023-03-11T01:03:03Z")

</div>

It feels like there’s some other mechanism going on here that it matters whether the build is going to run or not. Is there another use case being layered on top of this?

FWIW, `ctest_start` will set up `<builddir>/Testing/Temporary/TAG` or some such. `ctest_update` expects to reuse the metadata written there. Therefore, `ctest_empty_binary_directory` needs to be before `ctest_start`.
