# \`CTest --preset\` doesn't appear to allow for out-of-tree builds

**URL:** https://discourse.cmake.org/t/ctest-preset-doesnt-appear-to-allow-for-out-of-tree-builds/6275
**Category:** Usage
**Tags:** tool:ctest
**Created:** [August 15, 2022, 6:23pm UTC](https://discourse.cmake.org/t/ctest-preset-doesnt-appear-to-allow-for-out-of-tree-builds/6275 "2022-08-15T18:23:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![steven-johnson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/steven-johnson/32/448_2.png) [@steven-johnson](https://discourse.cmake.org/u/steven-johnson)
#### Post date: [August 15, 2022, 6:23pm UTC](https://discourse.cmake.org/t/ctest-preset-doesnt-appear-to-allow-for-out-of-tree-builds/6275/1 "2022-08-15T18:23:44Z")

</div>

When I configure a build in CMake using a build-preset, I can have a handy default for the build dir (e.g. `--preset=release` can default to `build/Release`)… but I can always use `-B build_dir` to override this if I want (e.g., if I need a completely-out-of-tree build directory, for buildbots or other unusual environments). This is great!

Unfortunately, it doesn’t seem possible to use test-presets in CTest with this kind of setup: there doesn’t seem to be a flag to override the default for binaryDir in the test preset (using `--test-dir` appears to do nothing in this situation).

This seems like a disappointing oversight for presets; ideally, there would be a (common?) flag that could be used to override the binaryDir for a given preset. The only workaround I’ve found is to maintain a separate set of presets, which is something that really should be necessary.

Is there any way to make this work as of recent versions of CMake? If not, could we find a way to make it work in the future?

Example reproducer (courtesy of Alex Reinking):

```auto
{
  "version": 3,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 22,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "default",
      "displayName": "default",
      "description": "default",
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build"
    }
  ],
  "testPresets": [
    {
      "name": "default",
      "configurePreset": "default"
    }
  ]
}

```

```auto
cmake_minimum_required(VERSION 3.23)
project(test)

enable_testing()

add_test(NAME check COMMAND true)

```

```auto
$ cmake --preset=default -B override
$ ctest --preset=default --test-dir override
Internal ctest changing into directory: /usr/local/google/home/reinking/test/override
Test project /usr/local/google/home/reinking/test/build
No tests were found!!!

```

---

<div class="post-metadata">

### Author: ![steven-johnson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/steven-johnson/32/448_2.png) [@steven-johnson](https://discourse.cmake.org/u/steven-johnson)
#### Post date: [August 18, 2022, 5:41pm UTC](https://discourse.cmake.org/t/ctest-preset-doesnt-appear-to-allow-for-out-of-tree-builds/6275/2 "2022-08-18T17:41:00Z")

</div>

I guess there isn’t a workaround? Seems hard to believe I’m the only one who has run into this limitation 🙂

---

<div class="post-metadata">

### Author: ![steven-johnson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/steven-johnson/32/448_2.png) [@steven-johnson](https://discourse.cmake.org/u/steven-johnson)
#### Post date: [September 19, 2022, 11:35pm UTC](https://discourse.cmake.org/t/ctest-preset-doesnt-appear-to-allow-for-out-of-tree-builds/6275/3 "2022-09-19T23:35:22Z")

</div>

I just want to ping this one last time – it seems really surprising to me that this isn’t currently possible. If anyone could at least confirm (or deny) that this is actually impossible, I’d really appreciate it.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [September 20, 2022, 11:05pm UTC](https://discourse.cmake.org/t/ctest-preset-doesnt-appear-to-allow-for-out-of-tree-builds/6275/4 "2022-09-20T23:05:40Z")

</div>

Issue created for this in CMake’s issue tracker here: [https://gitlab.kitware.com/cmake/cmake/-/issues/23982](https://gitlab.kitware.com/cmake/cmake/-/issues/23982)
