1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallProgramsCommand.cxx,v $
6 Date: $Date: 2008-07-08 15:52:25 $
7 Version: $Revision: 1.23 $
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"
18 #include "cmInstallFilesGenerator.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
);
41 this->Makefile
->GetLocalGenerator()->GetGlobalGenerator()
42 ->AddInstallComponent("Unspecified");
47 void cmInstallProgramsCommand::FinalPass()
49 bool files_mode
= false;
50 if(!this->FinalArgs
.empty() && this->FinalArgs
[0] == "FILES")
55 // two different options
56 if (this->FinalArgs
.size() > 1 || files_mode
)
58 // for each argument, get the programs
59 std::vector
<std::string
>::iterator s
= this->FinalArgs
.begin();
62 // Skip the FILES argument in files mode.
65 for(;s
!= this->FinalArgs
.end(); ++s
)
68 this->Files
.push_back(this->FindInstallSource(s
->c_str()));
73 std::vector
<std::string
> programs
;
74 cmSystemTools::Glob(this->Makefile
->GetCurrentDirectory(),
75 this->FinalArgs
[0].c_str(), programs
);
77 std::vector
<std::string
>::iterator s
= programs
.begin();
78 // for each argument, get the programs
79 for (;s
!= programs
.end(); ++s
)
81 this->Files
.push_back(this->FindInstallSource(s
->c_str()));
85 // Construct the destination. This command always installs under
86 // the prefix. We skip the leading slash given by the user.
87 std::string destination
= this->Destination
.substr(1);
88 cmSystemTools::ConvertToUnixSlashes(destination
);
90 // Use a file install generator.
91 const char* no_permissions
= "";
92 const char* no_rename
= "";
93 const char* no_component
= "Unspecified";
94 std::vector
<std::string
> no_configurations
;
95 this->Makefile
->AddInstallGenerator(
96 new cmInstallFilesGenerator(this->Files
,
97 destination
.c_str(), true,
98 no_permissions
, no_configurations
,
99 no_component
, no_rename
));
103 * Find a file in the build or source tree for installation given a
104 * relative path from the CMakeLists.txt file. This will favor files
105 * present in the build tree. If a full path is given, it is just
108 std::string cmInstallProgramsCommand
109 ::FindInstallSource(const char* name
) const
111 if(cmSystemTools::FileIsFullPath(name
))
113 // This is a full path.
117 // This is a relative path.
118 std::string tb
= this->Makefile
->GetCurrentOutputDirectory();
121 std::string ts
= this->Makefile
->GetCurrentDirectory();
125 if(cmSystemTools::FileExists(tb
.c_str()))
127 // The file exists in the binary tree. Use it.
130 else if(cmSystemTools::FileExists(ts
.c_str()))
132 // The file exists in the source tree. Use it.
137 // The file doesn't exist. Assume it will be present in the
138 // binary tree when the install occurs.