cmake/ctest generate Test.xml (without rebuilding?) / could not load cache

I have a cmake based (C++) project which includes tests created via add_test().
The build process is basically:

  • cmake
  • make all testsuite
  • make test

This has worked well for some time.

I am now trying to get my build to generate a Test.xml to be submitted as part of a pipeline build. It is not working for this project.

Q1 Can I tell cmake that I want a Test.xml to be generated when it (make test) runs the tests?

Currently I believe that a Test.xml can only be created by running ctest.
Presumably ctest aggregates the test results whereas cmake just runs them blindly?
Can someone confirm or refute this?

So I am currently trying to run ctest using:

ctest -vv -debug --output-on-failure -T test

As this does create the Test.xml file I need.
I had to add include(CTest) & include(Dart) to fix “could not find DartConfiguration.tcl”.

However, even if I have previously run “make test” which guarantees the build is up to date it still tries to build and I get:

Error: could not load cache

For tests that run a compiled test (script based tests work fine).
The command it is executing is:

/opt/cmake-3.18.1/bin/cmake "--build" "<projectDir>/test/<TestName>" --target "<test_exe>"

The CMakeCache.txt & CMakeLists.txt actually live in “<projectDir>/cmake” which is why the cache cannot be loaded.
The command should be:

/opt/cmake-3.18.1/bin/cmake "--build" "<projectDir>/cmake" --target "<test_exe>"

Where does the value for “–build” used come from? Can I fix this by configuration or is it a bug (or subtle off-design use)?

Q2 Is there some way to tell ctest it does not need to run cmake?

My suspicion is no. Does ctest have to invoke cmake to run the tests? Does it just monitor and aggregate the output?

If I look in DartConfiguration.tcl I have:

SourceDirectory: <projectDir/cmake
BuildDirectory: <projectDir/cmake
ConfigureCommand: "/opt/cmake-3.18.1/bin/cmake" "<projectDir/cmake"
MakeCommand: /opt/cmake-3.18.1/bin/cmake --build . --config "${CTEST_CONFIGURATION_TYPE}" -- -i

I am running ctest -T test rather than ctest -T build-and-test why is ctest trying to build at all?

I’ve tried setting Ctest_build_command but it seems to have no effect on the DartConfiguration.tcl generated.

Some clarifications:

  • ctest works for me for other projects which use out of source builds

  • This one cannot yet use an out of source build without massive refactoring.

  • The source root is actually “<projectDir>

  • The CMakeLists.txt lives in “<projectDir>/cmake

  • Program source code lives in “<projectDir>/src

  • Test scripts and code live in “<projectDir>/test

  • My build worked using:

    enable_testing()

I never previously had to use:

include(CTest)
include(Dart)

One or other of these creates the DartConfiguration.tcl which is just a list of “key: value” pairs. I think this is used when ctest is invoked directly which was not the case here.
I’m not entirely clear on why and what are they actually for despite reading Testing-With-CTest

I also posted this on stackoverflow but as its quite subtle I think support here is more appropriate.