cmake/Source/CTest/cmCTestConfigureCommand.cxx

154 lines
5.0 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"
#include "cmCTest.h"
#include "cmCTestGenericHandler.h"
2016-07-09 11:21:54 +02:00
#include "cmGlobalGenerator.h"
2016-10-30 18:24:19 +01:00
#include "cmMakefile.h"
#include "cmSystemTools.h"
#include "cmake.h"
#include <sstream>
#include <string.h>
#include <vector>
2009-10-04 10:30:41 +03:00
cmCTestConfigureCommand::cmCTestConfigureCommand()
{
this->Arguments[ctc_OPTIONS] = "OPTIONS";
2016-10-30 18:24:19 +01:00
this->Arguments[ctc_LAST] = CM_NULLPTR;
2009-10-04 10:30:41 +03:00
this->Last = ctc_LAST;
}
cmCTestGenericHandler* cmCTestConfigureCommand::InitializeHandler()
{
2009-10-04 10:30:41 +03:00
std::vector<std::string> options;
2016-07-09 11:21:54 +02:00
if (this->Values[ctc_OPTIONS]) {
2009-10-04 10:30:41 +03:00
cmSystemTools::ExpandListArgument(this->Values[ctc_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");
2016-10-30 18:24:19 +01:00
return CM_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");
2016-10-30 18:24:19 +01:00
return CM_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";
2016-07-09 11:21:54 +02:00
if (!cmSystemTools::FileExists(cmakelists_file.c_str())) {
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());
2016-10-30 18:24:19 +01:00
return CM_NULLPTR;
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
bool multiConfig = false;
bool cmakeBuildTypeInOptions = false;
2016-07-09 11:21:54 +02:00
cmGlobalGenerator* gg =
2010-03-17 14:00:29 +02:00
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();
delete gg;
2016-07-09 11:21:54 +02:00
}
2010-03-17 14:00:29 +02:00
std::string cmakeConfigureCommand = "\"";
2014-08-03 19:52:23 +02:00
cmakeConfigureCommand += cmSystemTools::GetCMakeCommand();
2009-10-04 10:30:41 +03:00
cmakeConfigureCommand += "\"";
std::vector<std::string>::const_iterator it;
std::string option;
2016-07-09 11:21:54 +02:00
for (it = options.begin(); it != options.end(); ++it) {
2009-10-04 10:30:41 +03:00
option = *it;
2010-03-17 14:00:29 +02:00
2009-10-04 10:30:41 +03:00
cmakeConfigureCommand += " \"";
cmakeConfigureCommand += option;
cmakeConfigureCommand += "\"";
2010-03-17 14:00:29 +02:00
2016-10-30 18:24:19 +01:00
if ((CM_NULLPTR != strstr(option.c_str(), "CMAKE_BUILD_TYPE=")) ||
(CM_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.");
2016-10-30 18:24:19 +01:00
return CM_NULLPTR;
}
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
cmCTestGenericHandler* handler =
this->CTest->GetInitializedHandler("configure");
if (!handler) {
this->SetError(
"internal CTest error. Cannot instantiate configure handler");
2016-10-30 18:24:19 +01:00
return CM_NULLPTR;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
handler->SetQuiet(this->Quiet);
return handler;
}