Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmGetDirectoryPropertyCommand.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 "cmGetDirectoryPropertyCommand.h"
13
14 #include "cmake.h"
15
16 // cmGetDirectoryPropertyCommand
17 bool cmGetDirectoryPropertyCommand
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
19 {
20   if(args.size() < 2 )
21     {
22     this->SetError("called with incorrect number of arguments");
23     return false;
24     }
25   
26   std::vector<std::string>::const_iterator i = args.begin();
27   std::string variable = *i;
28   ++i;
29   std::string output = "";
30     
31   // get the directory argument if there is one
32   cmMakefile *dir = this->Makefile;
33   if (*i == "DIRECTORY")
34     {
35     ++i;
36     if (i == args.end())
37       {
38       this->SetError
39         ("DIRECTORY argument provided without subsequent arguments");
40       return false;
41       }
42     std::string sd = *i;
43     // make sure the start dir is a full path
44     if (!cmSystemTools::FileIsFullPath(sd.c_str()))
45       {
46       sd = this->Makefile->GetStartDirectory();
47       sd += "/";
48       sd += *i;
49       }
50
51     // The local generators are associated with collapsed paths.
52     sd = cmSystemTools::CollapseFullPath(sd.c_str());
53
54     // lookup the makefile from the directory name
55     cmLocalGenerator *lg = 
56       this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
57       FindLocalGenerator(sd.c_str());
58     if (!lg)
59       {
60       this->SetError
61         ("DIRECTORY argument provided but requested directory not found. "
62          "This could be because the directory argument was invalid or, "
63          "it is valid but has not been processed yet.");
64       return false;
65       }
66     dir = lg->GetMakefile();
67     ++i;
68     }
69
70   // OK, now we have the directory to process, we just get the requested
71   // information out of it
72   
73   if ( *i == "DEFINITION" )
74     {
75     ++i;
76     if (i == args.end())
77       {
78       this->SetError("A request for a variable definition was made without "
79                      "providing the name of the variable to get.");
80       return false;
81       }
82     output = dir->GetSafeDefinition(i->c_str());
83     this->Makefile->AddDefinition(variable.c_str(), output.c_str());
84     return true;
85     }
86
87   const char *prop = dir->GetProperty(i->c_str());
88   if (prop)
89     {
90     this->Makefile->AddDefinition(variable.c_str(), prop);
91     return true;
92     }
93   this->Makefile->AddDefinition(variable.c_str(), "");
94   return true;
95 }
96