Initial commit.
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmGetDirectoryPropertyCommand.cxx
blob48b3a87fd9d937fe926a2ac9080910022cde03c6
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGetDirectoryPropertyCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.11 $
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 "cmGetDirectoryPropertyCommand.h"
19 #include "cmake.h"
21 // cmGetDirectoryPropertyCommand
22 bool cmGetDirectoryPropertyCommand
23 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
25 if(args.size() < 2 )
27 this->SetError("called with incorrect number of arguments");
28 return false;
31 std::vector<std::string>::const_iterator i = args.begin();
32 std::string variable = *i;
33 ++i;
34 std::string output = "";
36 // get the directory argument if there is one
37 cmMakefile *dir = this->Makefile;
38 if (*i == "DIRECTORY")
40 ++i;
41 if (i == args.end())
43 this->SetError
44 ("DIRECTORY argument provided without subsequent arguments");
45 return false;
47 std::string sd = *i;
48 // make sure the start dir is a full path
49 if (!cmSystemTools::FileIsFullPath(sd.c_str()))
51 sd = this->Makefile->GetStartDirectory();
52 sd += "/";
53 sd += *i;
56 // The local generators are associated with collapsed paths.
57 sd = cmSystemTools::CollapseFullPath(sd.c_str());
59 // lookup the makefile from the directory name
60 cmLocalGenerator *lg =
61 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()->
62 FindLocalGenerator(sd.c_str());
63 if (!lg)
65 this->SetError
66 ("DIRECTORY argument provided but requested directory not found. "
67 "This could be because the directory argument was invalid or, "
68 "it is valid but has not been processed yet.");
69 return false;
71 dir = lg->GetMakefile();
72 ++i;
75 // OK, now we have the directory to process, we just get the requested
76 // information out of it
78 if ( *i == "DEFINITION" )
80 ++i;
81 if (i == args.end())
83 this->SetError("A request for a variable definition was made without "
84 "providing the name of the variable to get.");
85 return false;
87 output = dir->GetSafeDefinition(i->c_str());
88 this->Makefile->AddDefinition(variable.c_str(), output.c_str());
89 return true;
92 const char *prop = dir->GetProperty(i->c_str());
93 if (prop)
95 this->Makefile->AddDefinition(variable.c_str(), prop);
96 return true;
98 this->Makefile->AddDefinition(variable.c_str(), "");
99 return true;