1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallProgramsCommand.cxx,v $
6 Date: $Date: 2008/01/28 13:38:35 $
7 Version: $Revision: 1.21 $
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 "cmInstallProgramsCommand.h"
19 // cmExecutableCommand
20 bool cmInstallProgramsCommand
21 ::InitialPass(std::vector
<std::string
> const& args
, cmExecutionStatus
&)
25 this->SetError("called with incorrect number of arguments");
29 // Enable the install target.
30 this->Makefile
->GetLocalGenerator()
31 ->GetGlobalGenerator()->EnableInstallTarget();
33 this->Destination
= args
[0];
35 std::vector
<std::string
>::const_iterator s
= args
.begin();
36 for (++s
;s
!= args
.end(); ++s
)
38 this->FinalArgs
.push_back(*s
);
44 void cmInstallProgramsCommand::FinalPass()
46 bool files_mode
= false;
47 if(!this->FinalArgs
.empty() && this->FinalArgs
[0] == "FILES")
52 // two different options
53 if (this->FinalArgs
.size() > 1 || files_mode
)
55 // for each argument, get the programs
56 std::vector
<std::string
>::iterator s
= this->FinalArgs
.begin();
59 // Skip the FILES argument in files mode.
62 for(;s
!= this->FinalArgs
.end(); ++s
)
65 this->Files
.push_back(this->FindInstallSource(s
->c_str()));
70 std::vector
<std::string
> programs
;
71 cmSystemTools::Glob(this->Makefile
->GetCurrentDirectory(),
72 this->FinalArgs
[0].c_str(), programs
);
74 std::vector
<std::string
>::iterator s
= programs
.begin();
75 // for each argument, get the programs
76 for (;s
!= programs
.end(); ++s
)
78 this->Files
.push_back(this->FindInstallSource(s
->c_str()));
82 // Construct the destination. This command always installs under
83 // the prefix. We skip the leading slash given by the user.
84 std::string destination
= this->Destination
.substr(1);
85 cmSystemTools::ConvertToUnixSlashes(destination
);
87 // Use a file install generator.
88 const char* no_permissions
= "";
89 const char* no_rename
= "";
90 const char* no_component
= "";
91 std::vector
<std::string
> no_configurations
;
92 this->Makefile
->AddInstallGenerator(
93 new cmInstallFilesGenerator(this->Files
,
94 destination
.c_str(), true,
95 no_permissions
, no_configurations
,
96 no_component
, no_rename
));
100 * Find a file in the build or source tree for installation given a
101 * relative path from the CMakeLists.txt file. This will favor files
102 * present in the build tree. If a full path is given, it is just
105 std::string cmInstallProgramsCommand
106 ::FindInstallSource(const char* name
) const
108 if(cmSystemTools::FileIsFullPath(name
))
110 // This is a full path.
114 // This is a relative path.
115 std::string tb
= this->Makefile
->GetCurrentOutputDirectory();
118 std::string ts
= this->Makefile
->GetCurrentDirectory();
122 if(cmSystemTools::FileExists(tb
.c_str()))
124 // The file exists in the binary tree. Use it.
127 else if(cmSystemTools::FileExists(ts
.c_str()))
129 // The file exists in the source tree. Use it.
134 // The file doesn't exist. Assume it will be present in the
135 // binary tree when the install occurs.