Imported Upstream version 2.8.9
[platform/upstream/cmake.git] / Source / cmGetSourceFilePropertyCommand.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 "cmGetSourceFilePropertyCommand.h"
13
14 #include "cmSourceFile.h"
15
16 // cmSetSourceFilePropertyCommand
17 bool cmGetSourceFilePropertyCommand
18 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
19 {
20   if(args.size() != 3 )
21     {
22     this->SetError("called with incorrect number of arguments");
23     return false;
24     }
25   const char* var = args[0].c_str();
26   const char* file = args[1].c_str();
27   cmSourceFile* sf = this->Makefile->GetSource(file);
28
29   // for the location we must create a source file first
30   if (!sf && args[2] == "LOCATION")
31     {
32     sf = this->Makefile->GetOrCreateSource(file);
33     }
34   if(sf)
35     {
36     if(args[2] == "LANGUAGE")
37       {
38       this->Makefile->AddDefinition(var, sf->GetLanguage());
39       return true;
40       }
41     const char *prop = sf->GetPropertyForUser(args[2].c_str());
42     if (prop)
43       {
44       this->Makefile->AddDefinition(var, prop);
45       return true;
46       }
47     }
48
49   this->Makefile->AddDefinition(var, "NOTFOUND");
50   return true;
51 }
52