0

I'm writing tests for a Cmake project. The project contains a library subproject and a test subproject, which is meant to test the library.

The tests require to compare some output images to some stored values, so the project contains an [ImageReferences] and [ImageOutputs] directories.

The structure of the project is as follows:

-[root]
---CMakeList.txt
---[library]
------CMakeList.txt
---[test]
------[ImageReferences]
------[ImageOutputs]
------CMakeList.txt
---[build]
------[library]
------[test]

If I run cmake in the [build] folder, the test executable will end up in the [build/test] folder. This is good and intended, but when I run ctest, I have no way to reference where the [ImageReferences] and [ImageOutputs] are.

Currently, in code, I'm doing:

ref_path = "../../test/ImageReferences"
out_path = "../../test/ImageOutputs"

This is clearly not ideal and prone to break.

The solution I would like to implement is to change the directory from which the executable is run. If I could specify [test] as the running directory, then I could just reference the [ImageReferences] and [ImageOutputs] folders directly, while leaving the executables in the [build/test] folder.

I tried to do this either in cmake or as an argument to ctest, and I couldn't. I was wondering if there is a way to achieve this.

In case the answer is no, I'd like to understand which alternatives I have to not depend anymore on shaky local paths.

Ryno
  • 403
  • 2
  • 7
  • 11

1 Answers1

0

I managed to got it to work through ctest by doing:

add_test(
    NAME ${TESTNAME}
    COMMAND ${TESTNAME}
    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

However, this is not working when using CMake with Visual Studio 2017 and running the tests from the Test Explorer panel.

Ryno
  • 403
  • 2
  • 7
  • 11