CVS resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmGetFilenameComponentCommand.cxx
blob87f534ac13101470cf7471fd276b9271de889396
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmGetFilenameComponentCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.17 $
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 "cmGetFilenameComponentCommand.h"
18 #include "cmSystemTools.h"
20 // cmGetFilenameComponentCommand
21 bool cmGetFilenameComponentCommand
22 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
24 if(args.size() < 3)
26 this->SetError("called with incorrect number of arguments");
27 return false;
30 // Check and see if the value has been stored in the cache
31 // already, if so use that value
32 if(args.size() == 4 && args[3] == "CACHE")
34 const char* cacheValue = this->Makefile->GetDefinition(args[0].c_str());
35 if(cacheValue && !cmSystemTools::IsNOTFOUND(cacheValue))
37 return true;
41 std::string result;
42 std::string filename = args[1];
43 cmSystemTools::ExpandRegistryValues(filename);
44 std::string storeArgs;
45 std::string programArgs;
46 if (args[2] == "PATH")
48 result = cmSystemTools::GetFilenamePath(filename);
50 else if (args[2] == "NAME")
52 result = cmSystemTools::GetFilenameName(filename);
54 else if (args[2] == "PROGRAM")
56 for(unsigned int i=2; i < args.size(); ++i)
58 if(args[i] == "PROGRAM_ARGS")
60 i++;
61 if(i < args.size())
63 storeArgs = args[i];
67 cmSystemTools::SplitProgramFromArgs(filename.c_str(),
68 result, programArgs);
70 else if (args[2] == "EXT")
72 result = cmSystemTools::GetFilenameExtension(filename);
74 else if (args[2] == "NAME_WE")
76 result = cmSystemTools::GetFilenameWithoutExtension(filename);
78 else if (args[2] == "ABSOLUTE")
80 // If the path given is relative evaluate it relative to the
81 // current source directory.
82 if(!cmSystemTools::FileIsFullPath(filename.c_str()))
84 std::string fname = this->Makefile->GetCurrentDirectory();
85 if(!fname.empty())
87 fname += "/";
88 fname += filename;
89 filename = fname;
93 // Collapse the path to its simplest form.
94 result = cmSystemTools::CollapseFullPath(filename.c_str());
96 else
98 std::string err = "unknown component " + args[2];
99 this->SetError(err.c_str());
100 return false;
103 if(args.size() == 4 && args[3] == "CACHE")
105 if(programArgs.size() && storeArgs.size())
107 this->Makefile->AddCacheDefinition
108 (storeArgs.c_str(), programArgs.c_str(),
109 "", args[2] == "PATH" ? cmCacheManager::FILEPATH
110 : cmCacheManager::STRING);
112 this->Makefile->AddCacheDefinition
113 (args[0].c_str(), result.c_str(), "",
114 args[2] == "PATH" ? cmCacheManager::FILEPATH
115 : cmCacheManager::STRING);
117 else
119 if(programArgs.size() && storeArgs.size())
121 this->Makefile->AddDefinition(storeArgs.c_str(), programArgs.c_str());
123 this->Makefile->AddDefinition(args[0].c_str(), result.c_str());
126 return true;