cmake/Source/CTest/cmCTestConfigureCommand.cxx

150 lines
4.9 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCTestConfigureCommand.h"
2020-02-01 23:06:01 +01:00
#include <cstring>
#include <sstream>
#include <vector>
2020-08-30 11:54:41 +02:00
#include <cmext/string_view>
2020-02-01 23:06:01 +01:00
#include "cmCTest.h"
2019-11-11 23:01:05 +01:00
#include "cmCTestConfigureHandler.h"
2016-07-09 11:21:54 +02:00
#include "cmGlobalGenerator.h"
2016-10-30 18:24:19 +01:00
#include "cmMakefile.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2016-10-30 18:24:19 +01:00
#include "cmSystemTools.h"
#include "cmake.h"
2020-02-01 23:06:01 +01:00
void cmCTestConfigureCommand::BindArguments()
2009-10-04 10:30:41 +03:00
{
2020-02-01 23:06:01 +01:00
this->cmCTestHandlerCommand::BindArguments();
this->Bind("OPTIONS"_s, this->Options);
2009-10-04 10:30:41 +03:00
}
cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
{
2009-10-04 10:30:41 +03:00
std::vector<std::string> options;
2020-02-01 23:06:01 +01:00
if (!this->Options.empty()) {
cmExpandList(this->Options, options);
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
if (this->CTest->GetCTestConfiguration("BuildDirectory").empty()) {
this->SetError(
"Build directory not specified. Either use BUILD "
"argument to CTEST_CONFIGURE command or set CTEST_BINARY_DIRECTORY "
"variable");
2018-01-26 17:06:56 +01:00
return nullptr;
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
const char* ctestConfigureCommand =
this->Makefile->GetDefinition("CTEST_CONFIGURE_COMMAND");
2010-03-17 14:00:29 +02:00
2016-07-09 11:21:54 +02:00
if (ctestConfigureCommand && *ctestConfigureCommand) {
this->CTest->SetCTestConfiguration("ConfigureCommand",
2016-07-09 11:21:54 +02:00
ctestConfigureCommand, this->Quiet);
} else {
const char* cmakeGeneratorName =
this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR");
if (cmakeGeneratorName && *cmakeGeneratorName) {
const std::string& source_dir =
this->CTest->GetCTestConfiguration("SourceDirectory");
if (source_dir.empty()) {
this->SetError(
"Source directory not specified. Either use SOURCE "
"argument to CTEST_CONFIGURE command or set CTEST_SOURCE_DIRECTORY "
"variable");
2018-01-26 17:06:56 +01:00
return nullptr;
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
const std::string cmakelists_file = source_dir + "/CMakeLists.txt";
2018-04-23 21:13:27 +02:00
if (!cmSystemTools::FileExists(cmakelists_file)) {
2015-04-27 22:25:09 +02:00
std::ostringstream e;
2016-07-09 11:21:54 +02:00
e << "CMakeLists.txt file does not exist [" << cmakelists_file << "]";
2015-04-27 22:25:09 +02:00
this->SetError(e.str());
2018-01-26 17:06:56 +01:00
return nullptr;
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
bool multiConfig = false;
bool cmakeBuildTypeInOptions = false;
2020-08-30 11:54:41 +02:00
auto gg = this->Makefile->GetCMakeInstance()->CreateGlobalGenerator(
cmakeGeneratorName);
2016-07-09 11:21:54 +02:00
if (gg) {
2010-03-17 14:00:29 +02:00
multiConfig = gg->IsMultiConfig();
2020-08-30 11:54:41 +02:00
gg.reset();
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
2020-02-01 23:06:01 +01:00
std::string cmakeConfigureCommand =
cmStrCat('"', cmSystemTools::GetCMakeCommand(), '"');
2009-10-04 10:30:41 +03:00
2018-01-26 17:06:56 +01:00
for (std::string const& option : options) {
2009-10-04 10:30:41 +03:00
cmakeConfigureCommand += " \"";
cmakeConfigureCommand += option;
cmakeConfigureCommand += "\"";
2010-03-17 14:00:29 +02:00
2018-01-26 17:06:56 +01:00
if ((nullptr != strstr(option.c_str(), "CMAKE_BUILD_TYPE=")) ||
(nullptr != strstr(option.c_str(), "CMAKE_BUILD_TYPE:STRING="))) {
2010-03-17 14:00:29 +02:00
cmakeBuildTypeInOptions = true;
}
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
if (!multiConfig && !cmakeBuildTypeInOptions &&
2016-07-09 11:21:54 +02:00
!this->CTest->GetConfigType().empty()) {
2010-03-17 14:00:29 +02:00
cmakeConfigureCommand += " \"-DCMAKE_BUILD_TYPE:STRING=";
cmakeConfigureCommand += this->CTest->GetConfigType();
cmakeConfigureCommand += "\"";
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
2017-04-14 19:02:05 +02:00
if (this->Makefile->IsOn("CTEST_USE_LAUNCHERS")) {
cmakeConfigureCommand += " \"-DCTEST_USE_LAUNCHERS:BOOL=TRUE\"";
}
2009-10-04 10:30:41 +03:00
cmakeConfigureCommand += " \"-G";
cmakeConfigureCommand += cmakeGeneratorName;
2009-10-04 10:30:41 +03:00
cmakeConfigureCommand += "\"";
2015-04-27 22:25:09 +02:00
const char* cmakeGeneratorPlatform =
this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR_PLATFORM");
2016-07-09 11:21:54 +02:00
if (cmakeGeneratorPlatform && *cmakeGeneratorPlatform) {
2015-04-27 22:25:09 +02:00
cmakeConfigureCommand += " \"-A";
cmakeConfigureCommand += cmakeGeneratorPlatform;
cmakeConfigureCommand += "\"";
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2013-03-16 19:13:01 +02:00
const char* cmakeGeneratorToolset =
this->Makefile->GetDefinition("CTEST_CMAKE_GENERATOR_TOOLSET");
2016-07-09 11:21:54 +02:00
if (cmakeGeneratorToolset && *cmakeGeneratorToolset) {
2013-03-16 19:13:01 +02:00
cmakeConfigureCommand += " \"-T";
cmakeConfigureCommand += cmakeGeneratorToolset;
cmakeConfigureCommand += "\"";
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2009-10-04 10:30:41 +03:00
cmakeConfigureCommand += " \"";
cmakeConfigureCommand += source_dir;
cmakeConfigureCommand += "\"";
2009-10-04 10:30:41 +03:00
2016-07-09 11:21:54 +02:00
this->CTest->SetCTestConfiguration(
"ConfigureCommand", cmakeConfigureCommand.c_str(), this->Quiet);
} else {
this->SetError(
"Configure command is not specified. If this is a "
2010-03-17 14:00:29 +02:00
"\"built with CMake\" project, set CTEST_CMAKE_GENERATOR. If not, "
"set CTEST_CONFIGURE_COMMAND.");
2018-01-26 17:06:56 +01:00
return nullptr;
}
2016-07-09 11:21:54 +02:00
}
2018-01-26 17:06:56 +01:00
if (const char* labelsForSubprojects =
this->Makefile->GetDefinition("CTEST_LABELS_FOR_SUBPROJECTS")) {
this->CTest->SetCTestConfiguration("LabelsForSubprojects",
labelsForSubprojects, this->Quiet);
}
2019-11-11 23:01:05 +01:00
cmCTestConfigureHandler* handler = this->CTest->GetConfigureHandler();
handler->Initialize();
2015-08-17 11:37:30 +02:00
handler->SetQuiet(this->Quiet);
return handler;
}