how to use --build-config-sample?

ctest has an option called:

--build-config-sample

A sample executable to use to determine the configuration that should be used. e.g. Debug , Release etc.

I do not understand its purpose. Can someone explain the context in which this is applied? Am I providing the sample executable to cTest? How does it work?

Looking at the code, the argument is a filepath to a built executable, which if there are multiple configurations built will contain the name of its corresponding config as a directory name present in the full path to the executable.

Then CTest’s AddConfigurations will tease that configuration name out of the path:

void cmCTestTestHandler::AddConfigurations(
  cmCTest* ctest, std::vector<std::string>& attempted,
  std::vector<std::string>& attemptedConfigs, std::string filepath,
  std::string& filename)
{
  std::string tempPath;

  if (!filepath.empty() && filepath[filepath.size() - 1] != '/') {
    filepath += "/";
  }
  tempPath = filepath + filename;
  attempted.push_back(tempPath);
  attemptedConfigs.emplace_back();

  if (!ctest->GetConfigType().empty()) {
    tempPath = cmStrCat(filepath, ctest->GetConfigType(), '/', filename);
    attempted.push_back(tempPath);
    attemptedConfigs.push_back(ctest->GetConfigType());
    // If the file is an OSX bundle then the configtype
    // will be at the start of the path
    tempPath = cmStrCat(ctest->GetConfigType(), '/', filepath, filename);
    attempted.push_back(tempPath);
    attemptedConfigs.push_back(ctest->GetConfigType());
  } else {
    // no config specified - try some options...
    tempPath = cmStrCat(filepath, "Release/", filename);
    attempted.push_back(tempPath);
    attemptedConfigs.emplace_back("Release");
    tempPath = cmStrCat(filepath, "Debug/", filename);
    attempted.push_back(tempPath);
    attemptedConfigs.emplace_back("Debug");
    tempPath = cmStrCat(filepath, "MinSizeRel/", filename);
    attempted.push_back(tempPath);
    attemptedConfigs.emplace_back("MinSizeRel");
    tempPath = cmStrCat(filepath, "RelWithDebInfo/", filename);
    attempted.push_back(tempPath);
    attemptedConfigs.emplace_back("RelWithDebInfo");
    tempPath = cmStrCat(filepath, "Deployment/", filename);
    attempted.push_back(tempPath);
    attemptedConfigs.emplace_back("Deployment");
    tempPath = cmStrCat(filepath, "Development/", filename);
    attempted.push_back(tempPath);
    attemptedConfigs.emplace_back("Deployment");
  }
}

So, it’s purely a scripting/automation convenience, for situations where lists of tests are being iterated over, or perhaps are the result of a glob, and it’s easier to have some tool divine the configuration that corresponds to each file programmatically than it is for the script to make assumptions about that info or try to account for all possibilities up front…

1 Like