Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmInstallFilesCommand.cxx
blob928bcd7e02f507711edd160ceacd2340d1dcebab
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallFilesCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2009-02-04 15:34:08 $
7 Version: $Revision: 1.31 $
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 "cmInstallFilesCommand.h"
19 #include "cmInstallFilesGenerator.h"
21 // cmExecutableCommand
22 bool cmInstallFilesCommand
23 ::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
25 if(argsIn.size() < 2)
27 this->SetError("called with incorrect number of arguments");
28 return false;
31 // Enable the install target.
32 this->Makefile->GetLocalGenerator()
33 ->GetGlobalGenerator()->EnableInstallTarget();
35 std::vector<std::string> args;
36 this->Makefile->ExpandSourceListArguments(argsIn, args, 2);
38 this->Destination = args[0];
40 if((args.size() > 1) && (args[1] == "FILES"))
42 this->IsFilesForm = true;
43 for(std::vector<std::string>::const_iterator s = args.begin()+2;
44 s != args.end(); ++s)
46 // Find the source location for each file listed.
47 std::string f = this->FindInstallSource(s->c_str());
48 this->Files.push_back(f);
50 this->CreateInstallGenerator();
52 else
54 this->IsFilesForm = false;
55 std::vector<std::string>::const_iterator s = args.begin();
56 for (++s;s != args.end(); ++s)
58 this->FinalArgs.push_back(*s);
62 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
63 ->AddInstallComponent("Unspecified");
65 return true;
68 void cmInstallFilesCommand::FinalPass()
70 // No final pass for "FILES" form of arguments.
71 if(this->IsFilesForm)
73 return;
76 std::string testf;
77 std::string ext = this->FinalArgs[0];
79 // two different options
80 if (this->FinalArgs.size() > 1)
82 // now put the files into the list
83 std::vector<std::string>::iterator s = this->FinalArgs.begin();
84 ++s;
85 // for each argument, get the files
86 for (;s != this->FinalArgs.end(); ++s)
88 // replace any variables
89 std::string temps = *s;
90 if (cmSystemTools::GetFilenamePath(temps).size() > 0)
92 testf = cmSystemTools::GetFilenamePath(temps) + "/" +
93 cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
95 else
97 testf = cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
100 // add to the result
101 this->Files.push_back(this->FindInstallSource(testf.c_str()));
104 else // reg exp list
106 std::vector<std::string> files;
107 std::string regex = this->FinalArgs[0].c_str();
108 cmSystemTools::Glob(this->Makefile->GetCurrentDirectory(),
109 regex.c_str(), files);
111 std::vector<std::string>::iterator s = files.begin();
112 // for each argument, get the files
113 for (;s != files.end(); ++s)
115 this->Files.push_back(this->FindInstallSource(s->c_str()));
119 this->CreateInstallGenerator();
122 void cmInstallFilesCommand::CreateInstallGenerator() const
124 // Construct the destination. This command always installs under
125 // the prefix. We skip the leading slash given by the user.
126 std::string destination = this->Destination.substr(1);
127 cmSystemTools::ConvertToUnixSlashes(destination);
128 if(destination.empty())
130 destination = ".";
133 // Use a file install generator.
134 const char* no_permissions = "";
135 const char* no_rename = "";
136 const char* no_component = "Unspecified";
137 std::vector<std::string> no_configurations;
138 this->Makefile->AddInstallGenerator(
139 new cmInstallFilesGenerator(this->Files,
140 destination.c_str(), false,
141 no_permissions, no_configurations,
142 no_component, no_rename));
147 * Find a file in the build or source tree for installation given a
148 * relative path from the CMakeLists.txt file. This will favor files
149 * present in the build tree. If a full path is given, it is just
150 * returned.
152 std::string cmInstallFilesCommand::FindInstallSource(const char* name) const
154 if(cmSystemTools::FileIsFullPath(name))
156 // This is a full path.
157 return name;
160 // This is a relative path.
161 std::string tb = this->Makefile->GetCurrentOutputDirectory();
162 tb += "/";
163 tb += name;
164 std::string ts = this->Makefile->GetCurrentDirectory();
165 ts += "/";
166 ts += name;
168 if(cmSystemTools::FileExists(tb.c_str()))
170 // The file exists in the binary tree. Use it.
171 return tb;
173 else if(cmSystemTools::FileExists(ts.c_str()))
175 // The file exists in the source tree. Use it.
176 return ts;
178 else
180 // The file doesn't exist. Assume it will be present in the
181 // binary tree when the install occurs.
182 return tb;