mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-08 16:50:48 +00:00
ctest_configure: move command construction into separate function
A large portion of cmCTestConfigureCommand::ExecuteCommand() deals with constructing the configure command in the case when `CTEST_CONFIGURE_COMMAND` is not specified. Move this logic into its own separate function. This improves readability and will make it easier to review subsequent changes to this class.
This commit is contained in:
@@ -27,23 +27,14 @@
|
|||||||
#include "cmXMLWriter.h"
|
#include "cmXMLWriter.h"
|
||||||
#include "cmake.h"
|
#include "cmake.h"
|
||||||
|
|
||||||
bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args,
|
namespace {
|
||||||
cmExecutionStatus& status) const
|
|
||||||
|
bool ConstructConfigureCommand(cmExecutionStatus& status, cmMakefile& mf,
|
||||||
|
std::string const sourceDirectory,
|
||||||
|
std::string const buildDirectory,
|
||||||
|
std::string const options,
|
||||||
|
std::string& configureCommand)
|
||||||
{
|
{
|
||||||
cmMakefile& mf = status.GetMakefile();
|
|
||||||
|
|
||||||
std::string const buildDirectory = !args.Build.empty()
|
|
||||||
? args.Build
|
|
||||||
: mf.GetDefinition("CTEST_BINARY_DIRECTORY");
|
|
||||||
if (buildDirectory.empty()) {
|
|
||||||
status.SetError("called with no build directory specified. "
|
|
||||||
"Either use the BUILD argument or set the "
|
|
||||||
"CTEST_BINARY_DIRECTORY variable.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string configureCommand = mf.GetDefinition("CTEST_CONFIGURE_COMMAND");
|
|
||||||
if (configureCommand.empty()) {
|
|
||||||
cmValue cmakeGenerator = mf.GetDefinition("CTEST_CMAKE_GENERATOR");
|
cmValue cmakeGenerator = mf.GetDefinition("CTEST_CMAKE_GENERATOR");
|
||||||
if (!cmNonempty(cmakeGenerator)) {
|
if (!cmNonempty(cmakeGenerator)) {
|
||||||
status.SetError(
|
status.SetError(
|
||||||
@@ -53,17 +44,6 @@ bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const sourceDirectory = !args.Source.empty()
|
|
||||||
? args.Source
|
|
||||||
: mf.GetDefinition("CTEST_SOURCE_DIRECTORY");
|
|
||||||
if (sourceDirectory.empty() ||
|
|
||||||
!cmSystemTools::FileExists(sourceDirectory + "/CMakeLists.txt")) {
|
|
||||||
status.SetError("called with invalid source directory. "
|
|
||||||
"CTEST_SOURCE_DIRECTORY must be set to a directory "
|
|
||||||
"that contains CMakeLists.txt.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool const multiConfig = [&]() -> bool {
|
bool const multiConfig = [&]() -> bool {
|
||||||
cmake* cm = mf.GetCMakeInstance();
|
cmake* cm = mf.GetCMakeInstance();
|
||||||
auto gg = cm->CreateGlobalGenerator(cmakeGenerator);
|
auto gg = cm->CreateGlobalGenerator(cmakeGenerator);
|
||||||
@@ -71,13 +51,13 @@ bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args,
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
bool const buildTypeInOptions =
|
bool const buildTypeInOptions =
|
||||||
args.Options.find("CMAKE_BUILD_TYPE=") != std::string::npos ||
|
options.find("CMAKE_BUILD_TYPE=") != std::string::npos ||
|
||||||
args.Options.find("CMAKE_BUILD_TYPE:STRING=") != std::string::npos;
|
options.find("CMAKE_BUILD_TYPE:STRING=") != std::string::npos;
|
||||||
|
|
||||||
configureCommand = cmStrCat('"', cmSystemTools::GetCMakeCommand(), '"');
|
configureCommand = cmStrCat('"', cmSystemTools::GetCMakeCommand(), '"');
|
||||||
|
|
||||||
auto const options = cmList(args.Options);
|
auto const optionsList = cmList(options);
|
||||||
for (std::string const& option : options) {
|
for (std::string const& option : optionsList) {
|
||||||
configureCommand += " \"";
|
configureCommand += " \"";
|
||||||
configureCommand += option;
|
configureCommand += option;
|
||||||
configureCommand += "\"";
|
configureCommand += "\"";
|
||||||
@@ -121,6 +101,42 @@ bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args,
|
|||||||
configureCommand += " \"-B";
|
configureCommand += " \"-B";
|
||||||
configureCommand += cmSystemTools::CollapseFullPath(buildDirectory);
|
configureCommand += cmSystemTools::CollapseFullPath(buildDirectory);
|
||||||
configureCommand += "\"";
|
configureCommand += "\"";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
bool cmCTestConfigureCommand::ExecuteConfigure(ConfigureArguments const& args,
|
||||||
|
cmExecutionStatus& status) const
|
||||||
|
{
|
||||||
|
cmMakefile& mf = status.GetMakefile();
|
||||||
|
|
||||||
|
std::string const buildDirectory = !args.Build.empty()
|
||||||
|
? args.Build
|
||||||
|
: mf.GetDefinition("CTEST_BINARY_DIRECTORY");
|
||||||
|
if (buildDirectory.empty()) {
|
||||||
|
status.SetError("called with no build directory specified. "
|
||||||
|
"Either use the BUILD argument or set the "
|
||||||
|
"CTEST_BINARY_DIRECTORY variable.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string const sourceDirectory = !args.Source.empty()
|
||||||
|
? args.Source
|
||||||
|
: mf.GetDefinition("CTEST_SOURCE_DIRECTORY");
|
||||||
|
if (sourceDirectory.empty() ||
|
||||||
|
!cmSystemTools::FileExists(sourceDirectory + "/CMakeLists.txt")) {
|
||||||
|
status.SetError("called with invalid source directory. "
|
||||||
|
"CTEST_SOURCE_DIRECTORY must be set to a directory "
|
||||||
|
"that contains CMakeLists.txt.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string configureCommand = mf.GetDefinition("CTEST_CONFIGURE_COMMAND");
|
||||||
|
if (configureCommand.empty() &&
|
||||||
|
!ConstructConfigureCommand(status, mf, sourceDirectory, buildDirectory,
|
||||||
|
args.Options, configureCommand)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Configure project\n",
|
cmCTestOptionalLog(this->CTest, HANDLER_OUTPUT, "Configure project\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user