# googletest discovery and environment

**URL:** https://discourse.cmake.org/t/googletest-discovery-and-environment/7363
**Category:** Usage
**Created:** [January 30, 2023, 11:48am UTC](https://discourse.cmake.org/t/googletest-discovery-and-environment/7363 "2023-01-30T11:48:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [January 30, 2023, 11:48am UTC](https://discourse.cmake.org/t/googletest-discovery-and-environment/7363/1 "2023-01-30T11:48:57Z")

</div>

Hi,

I am trying to use googletest tests on Windows that need external Qt DLLs.

So I tried:

```auto
gtest_discover_tests ( ${targetName}UnitTests
  TEST_PREFIX ${targetName}.
  PROPERTIES
    ENVIRONMENT_MODIFICATION
      "PATH=path_list_prepend:${QT_RUNTIME_DIR}"
  DISCOVERY_MODE PRE_TEST )

```

However, the environment modification is **not honored** when running the **test discovery**.

My alternative is to use `configure_file()` to create a `RunTest.bat` that sets up the environment and set the CROSSCOMPILING\_EMULATOR property on the executable. This is a lot slower, looks like a hack and thus I would like to avoid that.

I cannot modify the environment outside of the cmake/ctest call because that clumsy, error-prone and also Visual Studio with the RUN\_TESTS target is involved.

I do no want to copy the Qt DLLs to the output directory because this also involves plugins and other data, consumes lots of disk space and should not be necessary.

Any ideas? File a bug?

Hendrik

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [January 30, 2023, 1:13pm UTC](https://discourse.cmake.org/t/googletest-discovery-and-environment/7363/2 "2023-01-30T13:13:57Z")

</div>

Solved with a generated script that prepends the Qt directory to PATH environment. This is included with

```auto
set_property ( DIRECTORY . APPEND PROPERTY TEST_INCLUDE_FILES ${CMAKE_BINARY_DIR}/QtRuntimeDirInPath.cmake )

```

This make the test 5x faster than the cmd wrapper!

Still feels like a hack (but a better one)

---

<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: [February 6, 2023, 1:13am UTC](https://discourse.cmake.org/t/googletest-discovery-and-environment/7363/3 "2023-02-06T01:13:19Z")

</div>

There’s already an open issue capturing this problem:

[https://gitlab.kitware.com/cmake/cmake/-/issues/21453](https://gitlab.kitware.com/cmake/cmake/-/issues/21453)
