Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmVariableRequiresCommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmVariableRequiresCommand.h"
13 #include "cmCacheManager.h"
14
15 // cmLibraryCommand
16 bool cmVariableRequiresCommand
17 ::InitialPass(std::vector<std::string>const& args, cmExecutionStatus &)
18 {
19   if(args.size() < 3 )
20     {
21     this->SetError("called with incorrect number of arguments");
22     return false;
23     }
24
25   std::string testVariable = args[0]; 
26   if(!this->Makefile->IsOn(testVariable.c_str()))
27     {
28     return true;
29     }
30   std::string resultVariable = args[1];
31   bool requirementsMet = true;
32   std::string notSet;
33   bool hasAdvanced = false;
34   for(unsigned int i = 2; i < args.size(); ++i)
35     {
36     if(!this->Makefile->IsOn(args[i].c_str()))
37       {
38       requirementsMet = false;
39       notSet += args[i];
40       notSet += "\n";
41       cmCacheManager::CacheIterator it = 
42         this->Makefile->GetCacheManager()->GetCacheIterator(args[i].c_str());
43       if(!it.IsAtEnd() && it.GetPropertyAsBool("ADVANCED"))
44         {
45         hasAdvanced = true;
46         }
47       }
48     }
49   const char* reqVar = this->Makefile->GetDefinition(resultVariable.c_str());
50   // if reqVar is unset, then set it to requirementsMet 
51   // if reqVar is set to true, but requirementsMet is false , then
52   // set reqVar to false.
53   if(!reqVar || (!requirementsMet && this->Makefile->IsOn(reqVar)))
54     {
55     this->Makefile->AddDefinition(resultVariable.c_str(), requirementsMet);
56     }
57
58   if(!requirementsMet)
59     {
60     std::string message = "Variable assertion failed:\n";
61     message += testVariable + 
62       " Requires that the following unset variables are set:\n";
63     message += notSet;
64     message += "\nPlease set them, or set ";
65     message += testVariable + " to false, and re-configure.\n";
66     if(hasAdvanced)
67       {
68       message += 
69         "One or more of the required variables is advanced."
70         "  To set the variable, you must turn on advanced mode in cmake.";
71       }
72     cmSystemTools::Error(message.c_str());
73     }
74
75   return true;
76 }