# add\_test in CTestTestfile.cmake to contain relative paths.

**URL:** https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340
**Category:** Usage
**Created:** [June 7, 2020, 8:14am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340 "2020-06-07T08:14:54Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![Jacob\_Varghese](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jacob_varghese/32/670_2.png) [@Jacob\_Varghese](https://discourse.cmake.org/u/Jacob_Varghese)
#### Post date: [June 7, 2020, 8:14am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/1 "2020-06-07T08:14:54Z")

</div>

Can CTestTestfile.cmake hold relative paths instead of absolute ? I’m trying to move my build and test folders and executables to another VM and test it there where the folder structure is obviously different.

I need to use ctest and the aggregation and Text.xml generation utilities it has.

---

<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: [June 8, 2020, 12:52pm UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/2 "2020-06-08T12:52:07Z")

</div>

CTest (and CMake build trees in general) are pretty well-rooted in using absolute paths. In your other question, I mentioned `CMAKE_CROSSCOMPILING_EMULATOR` which should be able to get you want from the host. I remember discussing `install(TEST)` at some point, but maybe that was just musing and never made it to an issue? @robert.maynard?

I also see you opened [an issue](https://gitlab.kitware.com/cmake/cmake/-/issues/20797) already.

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [June 8, 2020, 1:00pm UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/3 "2020-06-08T13:00:12Z")

</div>

It was a musing that we could install things such as `CTestTestfile` since we could transform the absolute paths to new path. Initially this would only captures paths generated by CMake.

---

<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: [June 8, 2020, 1:05pm UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/4 "2020-06-08T13:05:48Z")

</div>

Ah. That then requires things like transforming data paths as well (at least) since they are typically in the source (e.g., git-lfs) or build (e.g., ExternalData) too and passed as arguments.

---

<div class="post-metadata">

### Author: ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)
#### Post date: [June 8, 2020, 1:10pm UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/5 "2020-06-08T13:10:44Z")

</div>

It requires project tests to be relocatable and load data based on information derived at runtime. Projects that codify runtime information at CMake configuration time would not eligible for this feature.

Passing paths such as those of files in git-lfs would be fine, but you would pass the relative path based on the executable location.

---

<div class="post-metadata">

### Author: ![Grant\_Anderson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/grant_anderson/32/498_2.png) [@Grant\_Anderson](https://discourse.cmake.org/u/Grant_Anderson)
#### Post date: [June 8, 2020, 11:56pm UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/6 "2020-06-08T23:56:12Z")

</div>

Hi Rob:  
On a side topic: Do you know where the “exported global variables” are stored, and how to access them?

When I execute this command ’ cmake -G “Eclipse CDT4 - Unix Makefiles” source ’ I see a comment in the generated “readme.md” file as follows:

“The project will export a global variable MACRO\_UTILS\_INC\_FOLDER that points to the folder needed to be included so that the '#include “azure\_macro\_utils/macro\_utils.h” ’ resolves properly”

I cannot find this “exported global variable”. Also, I don’t know how to include these “exported global variables” into a unix makefile to be built with “make”. Any help would be much appreciated.

Thanks,  
Garry Anderson.

---

<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: [June 9, 2020, 2:26am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/7 "2020-06-09T02:26:35Z")

</div>

> [@Grant\_Anderson](#):
>
> The project will export a global variable MACRO\_UTILS\_INC\_FOLDER that points to the folder needed to be included so that the '#include “azure\_macro\_utils/macro\_utils.h” ’ resolves properly

“Exported global variables” are not a CMake thing. I’d check that project specifically for what that means.

---

<div class="post-metadata">

### Author: ![Jacob\_Varghese](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jacob_varghese/32/670_2.png) [@Jacob\_Varghese](https://discourse.cmake.org/u/Jacob_Varghese)
#### Post date: [June 9, 2020, 5:31am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/8 "2020-06-09T05:31:43Z")

</div>

Yup, sorry I didn’t know about this forum, but at any rate,

Would you folks be open to a PR if it writes relative paths when possible and if requested to do so using an option or is is it not useful enough to warrant any benefit?

If not I’ll just close the issue and this thread.

---

<div class="post-metadata">

### Author: ![Grant\_Anderson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/grant_anderson/32/498_2.png) [@Grant\_Anderson](https://discourse.cmake.org/u/Grant_Anderson)
#### Post date: [June 9, 2020, 5:53am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/9 "2020-06-09T05:53:15Z")

</div>

Hi Jacob:

What is a PR?

Garry.

---

<div class="post-metadata">

### Author: ![Jacob\_Varghese](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jacob_varghese/32/670_2.png) [@Jacob\_Varghese](https://discourse.cmake.org/u/Jacob_Varghese)
#### Post date: [June 9, 2020, 6:00am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/11 "2020-06-09T06:00:28Z")

</div>

Sorry looks like it’s called a merge request on gitLab.

---

<div class="post-metadata">

### Author: ![Grant\_Anderson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/grant_anderson/32/498_2.png) [@Grant\_Anderson](https://discourse.cmake.org/u/Grant_Anderson)
#### Post date: [June 12, 2020, 4:24am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/12 "2020-06-12T04:24:56Z")

</div>

Hi Ben:

According to the CMake web-site, Environment variables can be “global” with global scope with the CMake build operation. See here: [https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#cmake-language-environment-variables](https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#cmake-language-environment-variables)  
The problem appears to be that such global variables disappear when CMake execution terminates, thus any subsequent makefile will never see these global variables. It looks like somebody in the CMake community really messed up here.

---

<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: [June 12, 2020, 7:08am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/13 "2020-06-12T07:08:54Z")

</div>

Environment variables defined within CMake configuration stage work like in any other program. After execution, their scope ends unless you spawn a direct sub-process and forward your environment.

Or maybe you meant something else?

---

<div class="post-metadata">

### Author: ![Grant\_Anderson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/grant_anderson/32/498_2.png) [@Grant\_Anderson](https://discourse.cmake.org/u/Grant_Anderson)
#### Post date: [June 12, 2020, 6:36pm UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/14 "2020-06-12T18:36:04Z")

</div>

Hendrick:

Exactly. So after CMake Generator finishes generating a “Unix Makefile”, the Generator cannot pass any of its global variables to any subsequent “make” operation, since make is not spawned by CMake; it is an entirely separate program that may be executed weeks later.

So, how can the CMake Generator attempt to pass a variable like “INC\_FOLDER” to be used by “make”? Thus any “makefile” created by the Generator cannot rely upon such a variable, and needs to be self-contained. Thus the Generator fails to make a complete “makefile” when it fails to pass along any INC\_FOLDER paths.

This looks like an Error with the CMake Generator. What do you think?

Garry.

---

<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: [June 12, 2020, 10:23pm UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/15 "2020-06-12T22:23:28Z")

</div>

Calling the proper include\_directories($ENV{INC\_FOLDER}) is too hard?

---

<div class="post-metadata">

### Author: ![Grant\_Anderson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/grant_anderson/32/498_2.png) [@Grant\_Anderson](https://discourse.cmake.org/u/Grant_Anderson)
#### Post date: [June 12, 2020, 10:51pm UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/16 "2020-06-12T22:51:33Z")

</div>

Hi Hendrik:

How do I make this call from using “make makefile” command?

I have not figured that out yet, because “include\_directories(…)” is a CMake command, not a make command.

Am I missing something?

Thanks,  
Garry  
.

---

<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: [June 13, 2020, 1:20am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/17 "2020-06-13T01:20:40Z")

</div>

> [@Grant\_Anderson](#):
>
> How do I make this call from using “make makefile” command?

You don’t. Generating makefiles that change behavior based on the environment like this is not supported in CMake (obviously there is `LD_LIBRARY_PATH` and other similar variables, but CMake can’t really block those).

What is your use case? Can you be specific? Though this really feels like a new question rather than something about CTestTestfile anymore.

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [June 13, 2020, 9:42am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/18 "2020-06-13T09:42:12Z")

</div>

> [@ben.boeckel](#):
>
> Though this really feels like a new question rather than something about CTestTestfile anymore.

@Grant_Anderson has been asking the same question in several threads:

- the first thread: [MACRO\_UTILS\_INC\_FOLDER Location?](https://discourse.cmake.org/t/macro-utils-inc-folder-location/1291) (which contains the necessary details to understand what they are talking about)
- [Where are Exported Global Variables?](https://discourse.cmake.org/t/where-are-exported-global-variables/1299), which nobody replied to because it doesn’t contain enough information
- the current thread: [add\_test in CTestTestfile.cmake to contain relative paths. - #6 by Grant\_Anderson](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/6)
- [Can I create a global variable to use for future projects? - #6 by Grant\_Anderson](https://discourse.cmake.org/t/can-i-create-a-global-variable-to-use-for-future-projects/1359/6), another thread where they attempted to get an answer to their question because the original post was on a similar topic
- and the most recent one: [CMake Generator Error for Unix Makefiles - Would like a Solution.](https://discourse.cmake.org/t/cmake-generator-error-for-unix-makefiles-would-like-a-solution/1385)

Let’s continue this discussion in [MACRO\_UTILS\_INC\_FOLDER Location?](https://discourse.cmake.org/t/macro-utils-inc-folder-location/1291) or [CMake Generator Error for Unix Makefiles - Would like a Solution.](https://discourse.cmake.org/t/cmake-generator-error-for-unix-makefiles-would-like-a-solution/1385) please.

---

<div class="post-metadata">

### Author: ![Grant\_Anderson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/grant_anderson/32/498_2.png) [@Grant\_Anderson](https://discourse.cmake.org/u/Grant_Anderson)
#### Post date: [June 14, 2020, 1:12am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/19 "2020-06-14T01:12:37Z")

</div>

Thanks Alain. Moving discussion to 1385 as you suggested.  
Garry.

---

<div class="post-metadata">

### Author: ![Grant\_Anderson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/grant_anderson/32/498_2.png) [@Grant\_Anderson](https://discourse.cmake.org/u/Grant_Anderson)
#### Post date: [June 14, 2020, 1:15am UTC](https://discourse.cmake.org/t/add-test-in-ctesttestfile-cmake-to-contain-relative-paths/1340/20 "2020-06-14T01:15:05Z")

</div>

Thanks Ben. I don’t know how my question got into this topic.  
As suggested by Alain, I am moving the question here:  
[https://discourse.cmake.org/t/cmake-generator-error-for-unix-makefiles-would-like-a-solution/1385](https://discourse.cmake.org/t/cmake-generator-error-for-unix-makefiles-would-like-a-solution/1385)

Garry.
