1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
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"
15 bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& argsIn,
18 if(argsIn.size() < 4 )
20 this->SetError("called with incorrect number of arguments");
24 // This command supports source list inputs for compatibility.
25 std::vector<std::string> args;
26 this->Makefile->ExpandSourceListArguments(argsIn, args, 3);
28 // Get the uic and moc executables to run in the custom commands.
30 this->Makefile->GetRequiredDefinition("QT_UIC_EXECUTABLE");
32 this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
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());
42 // Create rules for all sources listed.
43 for(std::vector<std::string>::iterator j = (args.begin() + 3);
46 cmSourceFile *curr = this->Makefile->GetSource(j->c_str());
47 // if we should wrap the class
48 if(!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE")))
50 // Compute the name of the files to generate.
52 cmSystemTools::GetFilenameWithoutLastExtension(*j);
53 std::string hName = this->Makefile->GetCurrentOutputDirectory();
57 std::string cxxName = this->Makefile->GetCurrentOutputDirectory();
61 std::string mocName = this->Makefile->GetCurrentOutputDirectory();
66 // Compute the name of the ui file from which to generate others.
68 if(cmSystemTools::FileIsFullPath(j->c_str()))
74 if(curr && curr->GetPropertyAsBool("GENERATED"))
76 uiName = this->Makefile->GetCurrentOutputDirectory();
80 uiName = this->Makefile->GetCurrentDirectory();
86 // create the list of headers
87 if(!headerListValue.empty())
89 headerListValue += ";";
91 headerListValue += hName;
93 // create the list of sources
94 if(!sourceListValue.empty())
96 sourceListValue += ";";
98 sourceListValue += cxxName;
99 sourceListValue += ";";
100 sourceListValue += mocName;
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);
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);
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);
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(),
141 depends.push_back(hName);
142 this->Makefile->AddCustomCommandToOutput(cxxName.c_str(),
150 depends.push_back(hName);
151 this->Makefile->AddCustomCommandToOutput(mocName.c_str(),
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());