Testing in a superbuild

If I have a superbuild, ie. one that just consists of a sequence of ExternalProject calls, how can I use CTest to run all of the tests in all of the subprojects? Using enable_testing() won’t do anything, but maybe there’s some way to generate a CTest file that include()s the subproject files?

1 Like

I’ve done a hack for this in our superbuild infrastructure. You can likely adapt it for your project. The files in question:

The logic gathers the projects we want to test, extracts their binary directories and configures a CTestTestfile.cmake to do the work. It then uses the trampoline to do the actual subdirs calls for each project we’re interested in. This file is added to the list of files for CTest to include.

You actually don’t need the custom CTestTestfile.cmake most likely…that is an oddity of the way that project is meant to be used.

I just used this today to make a cross-compiling superbuild experience a bit better…

The minimal version of this approach that I’m using is the following:

ExternalProject_Get_Property(cross-build BINARY_DIR)
file(CONFIGURE OUTPUT "CTestTestfile.cmake"
     CONTENT [[

and I just take care to not call enable_testing() in my (very short) super-build.

Is there any chance that this functionality can be integrated into ExternalProject_Add()? That would be very helpful if this is available out of the box rather than through a hack.

Given the horrible hack it does to make subdirs() work, I think the proper way is to add support to CTest to chain into other CTestTestfile.cmake files given a list of directories rather than…that :slight_smile: .

Yeah, the hack with subdirs() is a hack. I’m not sure where the proper fix should be. From the user prospective, I would prefer to have an extra parameter for ExternalProject_Add() that would signal that tests need to be exported to the parent context. Not sure that it is possible, through. But that would be ideal.

I think first would be to add some support to CTest for “chain off into this other directory” natively (probably via a directory property like CTEST_ADDITIONAL_SUBDIRS or something). Once that is done, ExternalProject_add can gain an argument like BUILD_ADD_TO_CTEST 1 or something to hook into that property.