Imported Upstream version 2.8.12.2
[platform/upstream/cmake.git] / Source / cmQTWrapUICommand.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
8   This software is distributed WITHOUT ANY WARRANTY; without even the
9   implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10   See the License for more information.
11 ============================================================================*/
12 #include "cmQTWrapUICommand.h"
13
14 // cmQTWrapUICommand
15 bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& argsIn,
16                                     cmExecutionStatus &)
17 {
18   if(argsIn.size() < 4 )
19     {
20     this->SetError("called with incorrect number of arguments");
21     return false;
22     }
23
24   // This command supports source list inputs for compatibility.
25   std::vector<std::string> args;
26   this->Makefile->ExpandSourceListArguments(argsIn, args, 3);
27
28   // Get the uic and moc executables to run in the custom commands.
29   const char* uic_exe =
30     this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
31   const char* moc_exe =
32     this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
33
34   // Get the variable holding the list of sources.
35   std::string const& headerList = args[1];
36   std::string const& sourceList = args[2];
37   std::string headerListValue =
38     this->Makefile->GetSafeDefinition(headerList.c_str());
39   std::string sourceListValue =
40     this->Makefile->GetSafeDefinition(sourceList.c_str());
41
42   // Create rules for all sources listed.
43   for(std::vector<std::string>::iterator j = (args.begin() + 3);
44       j != args.end(); ++j)
45     {
46     cmSourceFile *curr = this->Makefile->GetSource(j->c_str());
47     // if we should wrap the class
48     if(!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE")))
49       {
50       // Compute the name of the files to generate.
51       std::string srcName =
52         cmSystemTools::GetFilenameWithoutLastExtension(*j);
53       std::string hName = this->Makefile->GetCurrentOutputDirectory();
54       hName += "/";
55       hName += srcName;
56       hName += ".h";
57       std::string cxxName = this->Makefile->GetCurrentOutputDirectory();
58       cxxName += "/";
59       cxxName += srcName;
60       cxxName += ".cxx";
61       std::string mocName = this->Makefile->GetCurrentOutputDirectory();
62       mocName += "/moc_";
63       mocName += srcName;
64       mocName += ".cxx";
65
66       // Compute the name of the ui file from which to generate others.
67       std::string uiName;
68       if(cmSystemTools::FileIsFullPath(j->c_str()))
69         {
70         uiName = *j;
71         }
72       else
73         {
74         if(curr && curr->GetPropertyAsBool("GENERATED"))
75           {
76           uiName = this->Makefile->GetCurrentOutputDirectory();
77           }
78         else
79           {
80           uiName = this->Makefile->GetCurrentDirectory();
81           }
82         uiName += "/";
83         uiName += *j;
84         }
85
86       // create the list of headers
87       if(!headerListValue.empty())
88         {
89         headerListValue += ";";
90         }
91       headerListValue += hName;
92
93       // create the list of sources
94       if(!sourceListValue.empty())
95         {
96         sourceListValue += ";";
97         }
98       sourceListValue += cxxName;
99       sourceListValue += ";";
100       sourceListValue += mocName;
101
102       // set up .ui to .h and .cxx command
103       cmCustomCommandLine hCommand;
104       hCommand.push_back(uic_exe);
105       hCommand.push_back("-o");
106       hCommand.push_back(hName);
107       hCommand.push_back(uiName);
108       cmCustomCommandLines hCommandLines;
109       hCommandLines.push_back(hCommand);
110
111       cmCustomCommandLine cxxCommand;
112       cxxCommand.push_back(uic_exe);
113       cxxCommand.push_back("-impl");
114       cxxCommand.push_back(hName);
115       cxxCommand.push_back("-o");
116       cxxCommand.push_back(cxxName);
117       cxxCommand.push_back(uiName);
118       cmCustomCommandLines cxxCommandLines;
119       cxxCommandLines.push_back(cxxCommand);
120
121       cmCustomCommandLine mocCommand;
122       mocCommand.push_back(moc_exe);
123       mocCommand.push_back("-o");
124       mocCommand.push_back(mocName);
125       mocCommand.push_back(hName);
126       cmCustomCommandLines mocCommandLines;
127       mocCommandLines.push_back(mocCommand);
128
129       std::vector<std::string> depends;
130       depends.push_back(uiName);
131       const char* no_main_dependency = 0;
132       const char* no_comment = 0;
133       const char* no_working_dir = 0;
134       this->Makefile->AddCustomCommandToOutput(hName.c_str(),
135                                                depends,
136                                                no_main_dependency,
137                                                hCommandLines,
138                                                no_comment,
139                                                no_working_dir);
140
141       depends.push_back(hName);
142       this->Makefile->AddCustomCommandToOutput(cxxName.c_str(),
143                                                depends,
144                                                no_main_dependency,
145                                                cxxCommandLines,
146                                                no_comment,
147                                                no_working_dir);
148
149       depends.clear();
150       depends.push_back(hName);
151       this->Makefile->AddCustomCommandToOutput(mocName.c_str(),
152                                                depends,
153                                                no_main_dependency,
154                                                mocCommandLines,
155                                                no_comment,
156                                                no_working_dir);
157       }
158     }
159
160   // Store the final list of source files and headers.
161   this->Makefile->AddDefinition(sourceList.c_str(),
162                                 sourceListValue.c_str());
163   this->Makefile->AddDefinition(headerList.c_str(),
164                                 headerListValue.c_str());
165   return true;
166 }