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 "cmInstallProgramsCommand.h"
13 #include "cmInstallFilesGenerator.h"
14 // cmExecutableCommand
15 bool cmInstallProgramsCommand
16 ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
20 this->SetError("called with incorrect number of arguments");
24 // Enable the install target.
25 this->Makefile->GetLocalGenerator()
26 ->GetGlobalGenerator()->EnableInstallTarget();
28 this->Destination = args[0];
30 std::vector<std::string>::const_iterator s = args.begin();
31 for (++s;s != args.end(); ++s)
33 this->FinalArgs.push_back(*s);
36 this->Makefile->GetLocalGenerator()->GetGlobalGenerator()
37 ->AddInstallComponent(this->Makefile->GetSafeDefinition(
38 "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME"));
43 void cmInstallProgramsCommand::FinalPass()
45 bool files_mode = false;
46 if(!this->FinalArgs.empty() && this->FinalArgs[0] == "FILES")
51 // two different options
52 if (this->FinalArgs.size() > 1 || files_mode)
54 // for each argument, get the programs
55 std::vector<std::string>::iterator s = this->FinalArgs.begin();
58 // Skip the FILES argument in files mode.
61 for(;s != this->FinalArgs.end(); ++s)
64 this->Files.push_back(this->FindInstallSource(s->c_str()));
69 std::vector<std::string> programs;
70 cmSystemTools::Glob(this->Makefile->GetCurrentDirectory(),
71 this->FinalArgs[0].c_str(), programs);
73 std::vector<std::string>::iterator s = programs.begin();
74 // for each argument, get the programs
75 for (;s != programs.end(); ++s)
77 this->Files.push_back(this->FindInstallSource(s->c_str()));
81 // Construct the destination. This command always installs under
82 // the prefix. We skip the leading slash given by the user.
83 std::string destination = this->Destination.substr(1);
84 cmSystemTools::ConvertToUnixSlashes(destination);
85 if(destination.empty())
90 // Use a file install generator.
91 const char* no_permissions = "";
92 const char* no_rename = "";
93 std::string no_component = this->Makefile->GetSafeDefinition(
94 "CMAKE_INSTALL_DEFAULT_COMPONENT_NAME");
95 std::vector<std::string> no_configurations;
96 this->Makefile->AddInstallGenerator(
97 new cmInstallFilesGenerator(this->Files,
98 destination.c_str(), true,
99 no_permissions, no_configurations,
100 no_component.c_str(), no_rename));
104 * Find a file in the build or source tree for installation given a
105 * relative path from the CMakeLists.txt file. This will favor files
106 * present in the build tree. If a full path is given, it is just
109 std::string cmInstallProgramsCommand
110 ::FindInstallSource(const char* name) const
112 if(cmSystemTools::FileIsFullPath(name))
114 // This is a full path.
118 // This is a relative path.
119 std::string tb = this->Makefile->GetCurrentOutputDirectory();
122 std::string ts = this->Makefile->GetCurrentDirectory();
126 if(cmSystemTools::FileExists(tb.c_str()))
128 // The file exists in the binary tree. Use it.
131 else if(cmSystemTools::FileExists(ts.c_str()))
133 // The file exists in the source tree. Use it.
138 // The file doesn't exist. Assume it will be present in the
139 // binary tree when the install occurs.