cmake/Source/cmVariableRequiresCommand.cxx

65 lines
2.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 "cmVariableRequiresCommand.h"
2016-07-09 11:21:54 +02:00
2017-04-14 19:02:05 +02:00
#include "cmMakefile.h"
2015-08-17 11:37:30 +02:00
#include "cmState.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
class cmExecutionStatus;
// cmLibraryCommand
2016-07-09 11:21:54 +02:00
bool cmVariableRequiresCommand::InitialPass(
std::vector<std::string> const& args, cmExecutionStatus&)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 3) {
this->SetError("called with incorrect number of arguments");
return false;
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
std::string const& testVariable = args[0];
2016-07-09 11:21:54 +02:00
if (!this->Makefile->IsOn(testVariable)) {
return true;
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
std::string const& resultVariable = args[1];
bool requirementsMet = true;
std::string notSet;
bool hasAdvanced = false;
2015-08-17 11:37:30 +02:00
cmState* state = this->Makefile->GetState();
2016-07-09 11:21:54 +02:00
for (unsigned int i = 2; i < args.size(); ++i) {
if (!this->Makefile->IsOn(args[i])) {
requirementsMet = false;
notSet += args[i];
notSet += "\n";
2016-07-09 11:21:54 +02:00
if (state->GetCacheEntryValue(args[i]) &&
state->GetCacheEntryPropertyAsBool(args[i], "ADVANCED")) {
hasAdvanced = true;
}
}
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
const char* reqVar = this->Makefile->GetDefinition(resultVariable);
2013-03-16 19:13:01 +02:00
// if reqVar is unset, then set it to requirementsMet
// if reqVar is set to true, but requirementsMet is false , then
// set reqVar to false.
2016-07-09 11:21:54 +02:00
if (!reqVar || (!requirementsMet && this->Makefile->IsOn(reqVar))) {
2015-04-27 22:25:09 +02:00
this->Makefile->AddDefinition(resultVariable, requirementsMet);
2016-07-09 11:21:54 +02:00
}
2016-07-09 11:21:54 +02:00
if (!requirementsMet) {
std::string message = "Variable assertion failed:\n";
2016-07-09 11:21:54 +02:00
message +=
testVariable + " Requires that the following unset variables are set:\n";
message += notSet;
message += "\nPlease set them, or set ";
message += testVariable + " to false, and re-configure.\n";
2016-07-09 11:21:54 +02:00
if (hasAdvanced) {
2013-03-16 19:13:01 +02:00
message +=
"One or more of the required variables is advanced."
" To set the variable, you must turn on advanced mode in cmake.";
}
2016-07-09 11:21:54 +02:00
cmSystemTools::Error(message.c_str());
}
return true;
}