ENH: fix uppercase version so defines are not upper as well
[cmake.git] / Source / cmInstallProgramsCommand.cxx
blobeb02750b005be1e790360b1a525bd2e5cdab5320
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmInstallProgramsCommand.cxx,v $
5 Language: C++
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 &)
23 if(args.size() < 2)
25 this->SetError("called with incorrect number of arguments");
26 return false;
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");
44 return true;
47 void cmInstallProgramsCommand::FinalPass()
49 bool files_mode = false;
50 if(!this->FinalArgs.empty() && this->FinalArgs[0] == "FILES")
52 files_mode = true;
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();
60 if(files_mode)
62 // Skip the FILES argument in files mode.
63 ++s;
65 for(;s != this->FinalArgs.end(); ++s)
67 // add to the result
68 this->Files.push_back(this->FindInstallSource(s->c_str()));
71 else // reg exp list
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
106 * returned.
108 std::string cmInstallProgramsCommand
109 ::FindInstallSource(const char* name) const
111 if(cmSystemTools::FileIsFullPath(name))
113 // This is a full path.
114 return name;
117 // This is a relative path.
118 std::string tb = this->Makefile->GetCurrentOutputDirectory();
119 tb += "/";
120 tb += name;
121 std::string ts = this->Makefile->GetCurrentDirectory();
122 ts += "/";
123 ts += name;
125 if(cmSystemTools::FileExists(tb.c_str()))
127 // The file exists in the binary tree. Use it.
128 return tb;
130 else if(cmSystemTools::FileExists(ts.c_str()))
132 // The file exists in the source tree. Use it.
133 return ts;
135 else
137 // The file doesn't exist. Assume it will be present in the
138 // binary tree when the install occurs.
139 return tb;