1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmInstallFilesCommand.cxx,v $
6 Date: $Date: 2002-09-27 20:23:55 $
7 Version: $Revision: 1.17 $
9 Copyright (c) 2002 Insight Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm 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 // cmExecutableCommand
20 bool cmInstallFilesCommand::InitialPass(std::vector
<std::string
> const& argsIn
)
24 this->SetError("called with incorrect number of arguments");
27 std::vector
<std::string
> args
;
28 m_Makefile
->ExpandSourceListArguments(argsIn
, args
, 2);
30 // Create an INSTALL_FILES target specifically for this path.
31 m_TargetName
= "INSTALL_FILES_"+args
[0];
32 cmTarget
& target
= m_Makefile
->GetTargets()[m_TargetName
];
33 target
.SetInAll(false);
34 target
.SetType(cmTarget::INSTALL_FILES
);
35 target
.SetInstallPath(args
[0].c_str());
37 if((args
.size() > 1) && (args
[1] == "FILES"))
40 for(std::vector
<std::string
>::const_iterator s
= args
.begin()+2;
43 // Find the source location for each file listed.
44 std::string f
= this->FindInstallSource(s
->c_str());
45 target
.GetSourceLists().push_back(f
);
50 m_IsFilesForm
= false;
51 std::vector
<std::string
>::const_iterator s
= args
.begin();
52 for (++s
;s
!= args
.end(); ++s
)
54 m_FinalArgs
.push_back(*s
);
61 void cmInstallFilesCommand::FinalPass()
63 // No final pass for "FILES" form of arguments.
70 std::string ext
= m_FinalArgs
[0];
71 std::vector
<std::string
>& targetSourceLists
=
72 m_Makefile
->GetTargets()[m_TargetName
].GetSourceLists();
74 // two different options
75 if (m_FinalArgs
.size() > 1)
77 // now put the files into the list
78 std::vector
<std::string
>::iterator s
= m_FinalArgs
.begin();
80 // for each argument, get the files
81 for (;s
!= m_FinalArgs
.end(); ++s
)
83 // replace any variables
84 std::string temps
= *s
;
85 if (cmSystemTools::GetFilenamePath(temps
).size() > 0)
87 testf
= cmSystemTools::GetFilenamePath(temps
) + "/" +
88 cmSystemTools::GetFilenameWithoutLastExtension(temps
) + ext
;
92 testf
= cmSystemTools::GetFilenameWithoutLastExtension(temps
) + ext
;
96 targetSourceLists
.push_back(this->FindInstallSource(testf
.c_str()));
101 std::vector
<std::string
> files
;
102 std::string regex
= m_FinalArgs
[0].c_str();
103 cmSystemTools::Glob(m_Makefile
->GetCurrentDirectory(),
104 regex
.c_str(), files
);
106 std::vector
<std::string
>::iterator s
= files
.begin();
107 // for each argument, get the files
108 for (;s
!= files
.end(); ++s
)
110 targetSourceLists
.push_back(this->FindInstallSource(s
->c_str()));
116 * Find a file in the build or source tree for installation given a
117 * relative path from the CMakeLists.txt file. This will favor files
118 * present in the build tree. If a full path is given, it is just
121 std::string
cmInstallFilesCommand::FindInstallSource(const char* name
) const
123 if(cmSystemTools::FileIsFullPath(name
))
125 // This is a full path.
129 // This is a relative path.
130 std::string tb
= m_Makefile
->GetCurrentOutputDirectory();
133 std::string ts
= m_Makefile
->GetCurrentDirectory();
137 if(cmSystemTools::FileExists(tb
.c_str()))
139 // The file exists in the binary tree. Use it.
142 else if(cmSystemTools::FileExists(ts
.c_str()))
144 // The file exists in the source tree. Use it.
149 // The file doesn't exist. Assume it will be present in the
150 // binary tree when the install occurs.