# How to properly use TEST\_XML\_OUTPUT\_DIR?

**URL:** https://discourse.cmake.org/t/how-to-properly-use-test-xml-output-dir/1630
**Category:** Usage
**Created:** [July 27, 2020, 12:53pm UTC](https://discourse.cmake.org/t/how-to-properly-use-test-xml-output-dir/1630 "2020-07-27T12:53:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mojca](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mojca/32/610_2.png) [@mojca](https://discourse.cmake.org/u/mojca)
#### Post date: [July 27, 2020, 12:53pm UTC](https://discourse.cmake.org/t/how-to-properly-use-test-xml-output-dir/1630/1 "2020-07-27T12:53:18Z")

</div>

I’m writing a CI script for an existing repository.

I would like to simply run all the gtest-based unit tests with `ctest` (in parallel, if possible) and store the summary into one or more xml files, so that the CI system knows where to look for them and can display the results in some user-friendly way.

I’ve seen [https://github.com/google/googletest/issues/2506](https://github.com/google/googletest/issues/2506) which points to the recently added `TEST_XML_OUTPUT_DIR` in commit [https://gitlab.kitware.com/cmake/cmake/-/commit/e9ab39eb1db8f072b030a929992df828bc05cc63](https://gitlab.kitware.com/cmake/cmake/-/commit/e9ab39eb1db8f072b030a929992df828bc05cc63), but I struggle to understand how to use this without the need to change the `CMakeLists.txt` itself. According to my understanding this variable needs to be added to `gtest_discover_tests()`? Is this really the only way?

I mean: In the same way as I wouldn’t want to hardcode `/home/penguin/mycoolnewicecreamproject/build/x86_64-linux-clang` inside `CMakeLists.txt` as the directory where the project is supposed to be built on my own machine, I wouldn’t want to hardcode the directory where I want to have my google tests results either. (I don’t want to hardcode that the results should be in `xml` format either.)

I tried a couple of things in the command-line, but I didn’t get any of those working according to my expectations.

---

<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: [November 11, 2020, 8:52pm UTC](https://discourse.cmake.org/t/how-to-properly-use-test-xml-output-dir/1630/2 "2020-11-11T20:52:03Z")

</div>

Yes, the CMakeLists.txt would need to be modified. You could do something like this though:

```cmake
set(gtest_xml_output_args)
if (NOT "$ENV{CI}" STREQUAL "")
  list(APPEND gtest_xml_output_args
    TEST_XML_OUTPUT_DIR "${CMAKE_BINARY_DIR}/output")
endif ()
gtest_discover_tests(… ${gtest_xml_output_args})

```

Alternatively, do `if (DEFINED CI_XML_OUTPUT_DIR)` and use it instead by passing `-DCI_XML_OUTPUT_DIR` during your CI instructions.
