1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmVariableRequiresCommand.cxx,v $
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.15 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
17 #include "cmVariableRequiresCommand.h"
18 #include "cmCacheManager.h"
21 bool cmVariableRequiresCommand
22 ::InitialPass(std::vector
<std::string
>const& args
, cmExecutionStatus
&)
26 this->SetError("called with incorrect number of arguments");
30 std::string testVariable
= args
[0];
31 if(!this->Makefile
->IsOn(testVariable
.c_str()))
35 std::string resultVariable
= args
[1];
36 bool requirementsMet
= true;
38 bool hasAdvanced
= false;
39 for(unsigned int i
= 2; i
< args
.size(); ++i
)
41 if(!this->Makefile
->IsOn(args
[i
].c_str()))
43 requirementsMet
= false;
46 cmCacheManager::CacheIterator it
=
47 this->Makefile
->GetCacheManager()->GetCacheIterator(args
[i
].c_str());
48 if(!it
.IsAtEnd() && it
.GetPropertyAsBool("ADVANCED"))
54 const char* reqVar
= this->Makefile
->GetDefinition(resultVariable
.c_str());
55 // if reqVar is unset, then set it to requirementsMet
56 // if reqVar is set to true, but requirementsMet is false , then
57 // set reqVar to false.
58 if(!reqVar
|| (!requirementsMet
&& this->Makefile
->IsOn(reqVar
)))
60 this->Makefile
->AddDefinition(resultVariable
.c_str(), requirementsMet
);
65 std::string message
= "Variable assertion failed:\n";
66 message
+= testVariable
+
67 " Requires that the following unset variables are set:\n";
69 message
+= "\nPlease set them, or set ";
70 message
+= testVariable
+ " to false, and re-configure.\n";
74 "One or more of the required variables is advanced."
75 " To set the variable, you must turn on advanced mode in cmake.";
77 cmSystemTools::Error(message
.c_str());