1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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 "cmInstallFilesCommand.h"
14 #include "cmInstallFilesGenerator.h"
16 // cmExecutableCommand
17 bool cmInstallFilesCommand
18 ::InitialPass(std::vector<std::string> const& argsIn, cmExecutionStatus &)
22 this->SetError("called with incorrect number of arguments");
26 // Enable the install target.
27 this->Makefile->GetLocalGenerator()
28 ->GetGlobalGenerator()->EnableInstallTarget();
30 std::vector<std::string> args;
31 this->Makefile->ExpandSourceListArguments(argsIn, args, 2);
33 this->Destination = args[0];
35 if((args.size() > 1) && (args[1] == "FILES"))
37 this->IsFilesForm = true;
38 for(std::vector<std::string>::const_iterator s = args.begin()+2;
41 // Find the source location for each file listed.
42 std::string f = this->FindInstallSource(s->c_str());
43 this->Files.push_back(f);
45 this->CreateInstallGenerator();
49 this->IsFilesForm = false;
50 std::vector<std::string>::const_iterator s = args.begin();
51 for (++s;s != args.end(); ++s)
53 this->FinalArgs.push_back(*s);
57 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
58 ->AddInstallComponent(this->Makefile->GetSafeDefinition(
59 "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
64 void cmInstallFilesCommand::FinalPass()
66 // No final pass for "FILES" form of arguments.
73 std::string ext = this->FinalArgs[0];
75 // two different options
76 if (this->FinalArgs.size() > 1)
78 // now put the files into the list
79 std::vector<std::string>::iterator s = this->FinalArgs.begin();
81 // for each argument, get the files
82 for (;s != this->FinalArgs.end(); ++s)
84 // replace any variables
85 std::string temps = *s;
86 if (cmSystemTools::GetFilenamePath(temps).size() > 0)
88 testf = cmSystemTools::GetFilenamePath(temps) + "/" +
89 cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
93 testf = cmSystemTools::GetFilenameWithoutLastExtension(temps) + ext;
97 this->Files.push_back(this->FindInstallSource(testf.c_str()));
102 std::vector<std::string> files;
103 std::string regex = this->FinalArgs[0].c_str();
104 cmSystemTools::Glob(this->Makefile->GetCurrentDirectory(),
105 regex.c_str(), files);
107 std::vector<std::string>::iterator s = files.begin();
108 // for each argument, get the files
109 for (;s != files.end(); ++s)
111 this->Files.push_back(this->FindInstallSource(s->c_str()));
115 this->CreateInstallGenerator();
118 void cmInstallFilesCommand::CreateInstallGenerator() const
120 // Construct the destination. This command always installs under
121 // the prefix. We skip the leading slash given by the user.
122 std::string destination = this->Destination.substr(1);
123 cmSystemTools::ConvertToUnixSlashes(destination);
124 if(destination.empty())
129 // Use a file install generator.
130 const char* no_permissions = "";
131 const char* no_rename = "";
132 std::string no_component = this->Makefile->GetSafeDefinition(
133 "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
134 std::vector<std::string> no_configurations;
135 this->Makefile->AddInstallGenerator(
136 new cmInstallFilesGenerator(this->Files,
137 destination.c_str(), false,
138 no_permissions, no_configurations,
139 no_component.c_str(), no_rename));
144 * Find a file in the build or source tree for installation given a
145 * relative path from the CMakeLists.txt file. This will favor files
146 * present in the build tree. If a full path is given, it is just
149 std::string cmInstallFilesCommand::FindInstallSource(const char* name) const
151 if(cmSystemTools::FileIsFullPath(name))
153 // This is a full path.
157 // This is a relative path.
158 std::string tb = this->Makefile->GetCurrentOutputDirectory();
161 std::string ts = this->Makefile->GetCurrentDirectory();
165 if(cmSystemTools::FileExists(tb.c_str()))
167 // The file exists in the binary tree. Use it.
170 else if(cmSystemTools::FileExists(ts.c_str()))
172 // The file exists in the source tree. Use it.
177 // The file doesn't exist. Assume it will be present in the
178 // binary tree when the install occurs.