ENH: mark some vars as advanced (and resort the list)
[cmake.git] / Source / cmInstallProgramsCommand.cxx
blob2e9ac9d22276b9eb731e94cc546fb97d1bf6ed19
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmInstallProgramsCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-09-27 20:23:55 $
7 Version: $Revision: 1.8 $
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 "cmInstallProgramsCommand.h"
19 // cmExecutableCommand
20 bool cmInstallProgramsCommand::InitialPass(std::vector<std::string> const& argsIn)
22 if(argsIn.size() < 2)
24 this->SetError("called with incorrect number of arguments");
25 return false;
27 std::vector<std::string> args;
28 cmSystemTools::ExpandListArguments(argsIn, args);
30 // Create an INSTALL_PROGRAMS target specifically for this path.
31 m_TargetName = "INSTALL_PROGRAMS_"+args[0];
32 cmTarget& target = m_Makefile->GetTargets()[m_TargetName];
33 target.SetInAll(false);
34 target.SetType(cmTarget::INSTALL_PROGRAMS);
35 target.SetInstallPath(args[0].c_str());
37 std::vector<std::string>::const_iterator s = args.begin();
38 for (++s;s != args.end(); ++s)
40 m_FinalArgs.push_back(*s);
43 return true;
46 void cmInstallProgramsCommand::FinalPass()
48 std::vector<std::string>& targetSourceLists =
49 m_Makefile->GetTargets()[m_TargetName].GetSourceLists();
51 // two different options
52 if (m_FinalArgs.size() > 1)
54 // for each argument, get the programs
55 for (std::vector<std::string>::iterator s = m_FinalArgs.begin();
56 s != m_FinalArgs.end(); ++s)
58 // add to the result
59 targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
62 else // reg exp list
64 std::vector<std::string> programs;
65 cmSystemTools::Glob(m_Makefile->GetCurrentDirectory(),
66 m_FinalArgs[0].c_str(), programs);
68 std::vector<std::string>::iterator s = programs.begin();
69 // for each argument, get the programs
70 for (;s != programs.end(); ++s)
72 targetSourceLists.push_back(this->FindInstallSource(s->c_str()));
77 /**
78 * Find a file in the build or source tree for installation given a
79 * relative path from the CMakeLists.txt file. This will favor files
80 * present in the build tree. If a full path is given, it is just
81 * returned.
83 std::string cmInstallProgramsCommand::FindInstallSource(const char* name) const
85 if(cmSystemTools::FileIsFullPath(name))
87 // This is a full path.
88 return name;
91 // This is a relative path.
92 std::string tb = m_Makefile->GetCurrentOutputDirectory();
93 tb += "/";
94 tb += name;
95 std::string ts = m_Makefile->GetCurrentDirectory();
96 ts += "/";
97 ts += name;
99 if(cmSystemTools::FileExists(tb.c_str()))
101 // The file exists in the binary tree. Use it.
102 return tb;
104 else if(cmSystemTools::FileExists(ts.c_str()))
106 // The file exists in the source tree. Use it.
107 return ts;
109 else
111 // The file doesn't exist. Assume it will be present in the
112 // binary tree when the install occurs.
113 return tb;