Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / cmQTWrapUICommand.cxx
blob0a78cb580677efdbace960dc21a910c5e9ba86d3
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmQTWrapUICommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008/01/23 15:27:59 $
7 Version: $Revision: 1.26 $
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 "cmQTWrapUICommand.h"
19 // cmQTWrapUICommand
20 bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& argsIn,
21 cmExecutionStatus &)
23 if(argsIn.size() < 4 )
25 this->SetError("called with incorrect number of arguments");
26 return false;
29 // This command supports source list inputs for compatibility.
30 std::vector<std::string> args;
31 this->Makefile->ExpandSourceListArguments(argsIn, args, 3);
33 // Get the uic and moc executables to run in the custom commands.
34 const char* uic_exe =
35 this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
36 const char* moc_exe =
37 this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
39 // Get the variable holding the list of sources.
40 std::string const& headerList = args[1];
41 std::string const& sourceList = args[2];
42 std::string headerListValue =
43 this->Makefile->GetSafeDefinition(headerList.c_str());
44 std::string sourceListValue =
45 this->Makefile->GetSafeDefinition(sourceList.c_str());
47 // Create rules for all sources listed.
48 for(std::vector<std::string>::iterator j = (args.begin() + 3);
49 j != args.end(); ++j)
51 cmSourceFile *curr = this->Makefile->GetSource(j->c_str());
52 // if we should wrap the class
53 if(!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE")))
55 // Compute the name of the files to generate.
56 std::string srcName =
57 cmSystemTools::GetFilenameWithoutLastExtension(*j);
58 std::string hName = this->Makefile->GetCurrentOutputDirectory();
59 hName += "/";
60 hName += srcName;
61 hName += ".h";
62 std::string cxxName = this->Makefile->GetCurrentOutputDirectory();
63 cxxName += "/";
64 cxxName += srcName;
65 cxxName += ".cxx";
66 std::string mocName = this->Makefile->GetCurrentOutputDirectory();
67 mocName += "/moc_";
68 mocName += srcName;
69 mocName += ".cxx";
71 // Compute the name of the ui file from which to generate others.
72 std::string uiName;
73 if(cmSystemTools::FileIsFullPath(j->c_str()))
75 uiName = *j;
77 else
79 if(curr && curr->GetPropertyAsBool("GENERATED"))
81 uiName = this->Makefile->GetCurrentOutputDirectory();
83 else
85 uiName = this->Makefile->GetCurrentDirectory();
87 uiName += "/";
88 uiName += *j;
91 // create the list of headers
92 if(!headerListValue.empty())
94 headerListValue += ";";
96 headerListValue += hName;
98 // create the list of sources
99 if(!sourceListValue.empty())
101 sourceListValue += ";";
103 sourceListValue += cxxName;
104 sourceListValue += ";";
105 sourceListValue += mocName;
107 // set up .ui to .h and .cxx command
108 cmCustomCommandLine hCommand;
109 hCommand.push_back(uic_exe);
110 hCommand.push_back("-o");
111 hCommand.push_back(hName);
112 hCommand.push_back(uiName);
113 cmCustomCommandLines hCommandLines;
114 hCommandLines.push_back(hCommand);
116 cmCustomCommandLine cxxCommand;
117 cxxCommand.push_back(uic_exe);
118 cxxCommand.push_back("-impl");
119 cxxCommand.push_back(hName);
120 cxxCommand.push_back("-o");
121 cxxCommand.push_back(cxxName);
122 cxxCommand.push_back(uiName);
123 cmCustomCommandLines cxxCommandLines;
124 cxxCommandLines.push_back(cxxCommand);
126 cmCustomCommandLine mocCommand;
127 mocCommand.push_back(moc_exe);
128 mocCommand.push_back("-o");
129 mocCommand.push_back(mocName);
130 mocCommand.push_back(hName);
131 cmCustomCommandLines mocCommandLines;
132 mocCommandLines.push_back(mocCommand);
134 std::vector<std::string> depends;
135 depends.push_back(uiName);
136 const char* no_main_dependency = 0;
137 const char* no_comment = 0;
138 const char* no_working_dir = 0;
139 this->Makefile->AddCustomCommandToOutput(hName.c_str(),
140 depends,
141 no_main_dependency,
142 hCommandLines,
143 no_comment,
144 no_working_dir);
146 depends.push_back(hName);
147 this->Makefile->AddCustomCommandToOutput(cxxName.c_str(),
148 depends,
149 no_main_dependency,
150 cxxCommandLines,
151 no_comment,
152 no_working_dir);
154 depends.clear();
155 depends.push_back(hName);
156 this->Makefile->AddCustomCommandToOutput(mocName.c_str(),
157 depends,
158 no_main_dependency,
159 mocCommandLines,
160 no_comment,
161 no_working_dir);
165 // Store the final list of source files and headers.
166 this->Makefile->AddDefinition(sourceList.c_str(),
167 sourceListValue.c_str());
168 this->Makefile->AddDefinition(headerList.c_str(),
169 headerListValue.c_str());
170 return true;