cmake/Source/cmOptionCommand.cxx

58 lines
2.1 KiB
C++
Raw Normal View History

2009-10-04 10:30:41 +03:00
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
2009-10-04 10:30:41 +03:00
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
2009-10-04 10:30:41 +03:00
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "cmOptionCommand.h"
// cmOptionCommand
2016-07-09 11:21:54 +02:00
bool cmOptionCommand::InitialPass(std::vector<std::string> const& args,
cmExecutionStatus&)
{
bool argError = false;
2016-07-09 11:21:54 +02:00
if (args.size() < 2) {
argError = true;
2016-07-09 11:21:54 +02:00
}
// for VTK 4.0 we have to support the option command with more than 3
// arguments if CMAKE_MINIMUM_REQUIRED_VERSION is not defined, if
// CMAKE_MINIMUM_REQUIRED_VERSION is defined, then we can have stricter
// checking.
2016-07-09 11:21:54 +02:00
if (this->Makefile->GetDefinition("CMAKE_MINIMUM_REQUIRED_VERSION")) {
if (args.size() > 3) {
argError = true;
}
2016-07-09 11:21:54 +02:00
}
if (argError) {
std::string m = "called with incorrect number of arguments: ";
2015-08-17 11:37:30 +02:00
m += cmJoin(args, " ");
2015-04-27 22:25:09 +02:00
this->SetError(m);
return false;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
std::string initialValue = "Off";
// Now check and see if the value has been stored in the cache
// already, if so use that value and don't look for the program
2015-08-17 11:37:30 +02:00
cmState* state = this->Makefile->GetState();
const char* existingValue = state->GetCacheEntryValue(args[0]);
2016-07-09 11:21:54 +02:00
if (existingValue) {
if (state->GetCacheEntryType(args[0]) != cmState::UNINITIALIZED) {
2015-08-17 11:37:30 +02:00
state->SetCacheEntryProperty(args[0], "HELPSTRING", args[1]);
return true;
}
2016-07-09 11:21:54 +02:00
initialValue = existingValue;
}
if (args.size() == 3) {
initialValue = args[2];
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
bool init = cmSystemTools::IsOn(initialValue.c_str());
2016-07-09 11:21:54 +02:00
this->Makefile->AddCacheDefinition(args[0], init ? "ON" : "OFF",
2015-08-17 11:37:30 +02:00
args[1].c_str(), cmState::BOOL);
return true;
}