# Nightly build invoking CMake from outside build directory

**URL:** https://discourse.cmake.org/t/nightly-build-invoking-cmake-from-outside-build-directory/1453
**Category:** Development
**Created:** [June 28, 2020, 9:58am UTC](https://discourse.cmake.org/t/nightly-build-invoking-cmake-from-outside-build-directory/1453 "2020-06-28T09:58:15Z")
**Posts on this page:** 5
**Page:** 1

<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: [June 28, 2020, 9:58am UTC](https://discourse.cmake.org/t/nightly-build-invoking-cmake-from-outside-build-directory/1453/1 "2020-06-28T09:58:15Z")

</div>

Do we have any nightly builds which run `cmake` and `ctest` from a directory other than the build directory? If not, we should try to get at least one build site to do that. This might help catch things like situations that apply to policy CMP0070 and [issue 20885](https://gitlab.kitware.com/cmake/cmake/-/issues/20885). I’m wondering how many other similar issues might be lurking as well. Maybe we could also potentially modify some of the test cases to do that too, but getting a good cross-section of feature coverage may be difficult.

---

<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: [June 29, 2020, 12:01pm UTC](https://discourse.cmake.org/t/nightly-build-invoking-cmake-from-outside-build-directory/1453/2 "2020-06-29T12:01:18Z")

</div>

Please clarify what you mean by “from a directory other than the build”. Do you mean the working directory, the location of the `cmake` executable, or something else?

---

<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: [June 29, 2020, 12:18pm UTC](https://discourse.cmake.org/t/nightly-build-invoking-cmake-from-outside-build-directory/1453/3 "2020-06-29T12:18:11Z")

</div>

I meant the working directory should be something other than the top of the build directory. The following scenarios come to mind:

- People invoking `cmake -S xxx -B yyy` from a directory that is neither `xxx` nor `yyy`. This might be more common when defining the steps of a CI job.
- Running `ctest` in a subdirectory of the build directory. This can be used to run a subset of the tests based on directory structure.

I more had invoking `cmake` in mind when I wrote the original post, but I added `ctest` too after realising it may also have cases that could be relevant. My comments about build sites more apply to the `cmake` case than `ctest` (I think the latter would be more about test cases than the setup of build sites).

---

<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: [June 30, 2020, 10:15am UTC](https://discourse.cmake.org/t/nightly-build-invoking-cmake-from-outside-build-directory/1453/4 "2020-06-30T10:15:26Z")

</div>

Most of the test suite drives its own runs of `ctest` and/or `cmake` so the working directory of the outer ctest wouldn’t matter much. Many of the RunCMake tests could probably be updated to use `-S` and `-B` with a separate working directory. Many other tests use `ctest --build-and-test`, which currently relies on the working directory for invoking its internal `cmake` too. An option could be added to that to switch to `-S` and `-B` for some tests.

---

<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: [June 30, 2020, 11:23am UTC](https://discourse.cmake.org/t/nightly-build-invoking-cmake-from-outside-build-directory/1453/5 "2020-06-30T11:23:38Z")

</div>

I’m increasingly thinking this will be valuable. I just found another case while working on the MR for the `file(ARCHIVE_EXTRACT)` updates.
