Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmGetCMakePropertyCommand.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 "cmGetCMakePropertyCommand.h"
13
14 #include "cmGlobalGenerator.h"
15 #include "cmLocalGenerator.h"
16 #include "cmake.h"
17
18 // cmGetCMakePropertyCommand
19 bool cmGetCMakePropertyCommand
20 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
21 {
22   if(args.size() < 2 )
23     {
24     this->SetError("called with incorrect number of arguments");
25     return false;
26     }
27
28   std::vector<std::string>::size_type cc;
29   std::string variable = args[0];
30   std::string output = "NOTFOUND";
31
32   if ( args[1] == "VARIABLES" )
33     {
34     int cacheonly = 0;
35     std::vector<std::string> vars = this->Makefile->GetDefinitions(cacheonly);
36     if (vars.size()>0)
37       {
38       output = vars[0];
39       }
40     for ( cc = 1; cc < vars.size(); ++cc )
41       {
42       output += ";";
43       output += vars[cc];
44       }
45     }
46   else if ( args[1] == "MACROS" )
47     {
48     this->Makefile->GetListOfMacros(output);
49     }
50   else if ( args[1] == "COMPONENTS" )
51     {
52     const std::set<cmStdString>* components
53       = this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
54         ->GetInstallComponents();
55     std::set<cmStdString>::const_iterator compIt;
56     output = "";
57     for (compIt = components->begin(); compIt != components->end(); ++compIt)
58       {
59       if (compIt != components->begin())
60         {
61         output += ";";
62         }
63       output += *compIt;
64       }
65     }
66   else
67     {
68     const char *prop =
69       this->Makefile->GetCMakeInstance()->GetProperty(args[1].c_str());
70     if (prop)
71       {
72       output = prop;
73       }
74     }
75
76   this->Makefile->AddDefinition(variable.c_str(), output.c_str());
77
78   return true;
79 }