ENH: change the search path order (if several Tcl/Tk are installed, the "current...
[cmake.git] / Source / cmQTWrapUICommand.cxx
blobdf4870fdba21bcb76013ca7073e58e9a45a5c581
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmQTWrapUICommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-06-27 19:57:09 $
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 "cmQTWrapUICommand.h"
19 // cmQTWrapUICommand
20 bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& argsIn)
22 if(argsIn.size() < 4 )
24 this->SetError("called with incorrect number of arguments");
25 return false;
27 std::vector<std::string> args;
28 m_Makefile->ExpandSourceListArguments(argsIn, args, 3);
30 // Now check and see if the value has been stored in the cache
31 // already, if so use that value and don't look for the program
32 const char* QT_WRAP_UI_value = m_Makefile->GetDefinition("QT_WRAP_UI");
33 if (QT_WRAP_UI_value==0)
35 this->SetError("called with QT_WRAP_UI undefined");
36 return false;
39 if(cmSystemTools::IsOff(QT_WRAP_UI_value))
41 this->SetError("called with QT_WRAP_UI off : ");
42 return false;
45 // what is the current source dir
46 std::string cdir = m_Makefile->GetCurrentDirectory();
48 // keep the library name
49 m_LibraryName = args[0];
50 m_HeaderList = args[1];
51 m_SourceList = args[2];
52 std::string sourceListValue;
53 const char *def = m_Makefile->GetDefinition(m_SourceList.c_str());
54 if (def)
56 sourceListValue = def;
59 // get the list of classes for this library
60 for(std::vector<std::string>::iterator j = (args.begin() + 3);
61 j != args.end(); ++j)
63 cmSourceFile *curr = m_Makefile->GetSource(j->c_str());
65 // if we should wrap the class
66 if (!curr || !curr->GetWrapExclude())
68 cmSourceFile header_file;
69 cmSourceFile source_file;
70 cmSourceFile moc_file;
71 std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*j);
72 header_file.SetName(srcName.c_str(),
73 m_Makefile->GetCurrentOutputDirectory(),
74 "h",false);
75 source_file.SetName(srcName.c_str(),
76 m_Makefile->GetCurrentOutputDirectory(),
77 "cxx",false);
78 std::string moc_source_name("moc_");
79 moc_source_name = moc_source_name + srcName;
80 moc_file.SetName(moc_source_name.c_str(),
81 m_Makefile->GetCurrentOutputDirectory(),
82 "cxx",false);
83 std::string origname = cdir + "/" + *j;
84 std::string hname = header_file.GetFullPath();
85 m_WrapUserInterface.push_back(origname);
86 // add starting depends
87 moc_file.GetDepends().push_back(hname);
88 source_file.GetDepends().push_back(hname);
89 source_file.GetDepends().push_back(origname);
90 header_file.GetDepends().push_back(origname);
91 m_WrapHeadersClasses.push_back(header_file);
92 m_WrapSourcesClasses.push_back(source_file);
93 m_WrapMocClasses.push_back(moc_file);
94 m_Makefile->AddSource(header_file);
95 m_Makefile->AddSource(source_file);
96 m_Makefile->AddSource(moc_file);
98 // create the list of sources
99 if (sourceListValue.size() > 0)
101 sourceListValue += ";";
103 sourceListValue += header_file.GetSourceName() + ".h";
104 sourceListValue += ";";
105 sourceListValue += source_file.GetSourceName() + ".cxx";
106 sourceListValue += ";";
107 sourceListValue += moc_file.GetSourceName() + ".cxx";
111 m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
112 return true;
115 void cmQTWrapUICommand::FinalPass()
118 // first we add the rules for all the .ui to .h and .cxx files
119 size_t lastHeadersClass = m_WrapHeadersClasses.size();
120 std::vector<std::string> depends;
121 std::string uic_exe = "${QT_UIC_EXE}";
122 std::string moc_exe = "${QT_MOC_EXE}";
125 // wrap all the .h files
126 depends.push_back(uic_exe);
128 const char * GENERATED_QT_FILES_value=
129 m_Makefile->GetDefinition("GENERATED_QT_FILES");
130 std::string ui_list("");
131 if (GENERATED_QT_FILES_value!=0)
133 ui_list=ui_list+GENERATED_QT_FILES_value;
136 for(size_t classNum = 0; classNum < lastHeadersClass; classNum++)
138 // set up .ui to .h and .cxx command
140 std::string hres = m_Makefile->GetCurrentOutputDirectory();
141 hres += "/";
142 hres += m_WrapHeadersClasses[classNum].GetSourceName() + "." +
143 m_WrapHeadersClasses[classNum].GetSourceExtension();
145 std::string cxxres = m_Makefile->GetCurrentOutputDirectory();
146 cxxres += "/";
147 cxxres += m_WrapSourcesClasses[classNum].GetSourceName() + "." +
148 m_WrapSourcesClasses[classNum].GetSourceExtension();
150 std::string mocres = m_Makefile->GetCurrentOutputDirectory();
151 mocres += "/";
152 mocres += m_WrapMocClasses[classNum].GetSourceName() + "." +
153 m_WrapMocClasses[classNum].GetSourceExtension();
155 ui_list = ui_list + " " + hres + " " + cxxres + " " + mocres;
157 std::vector<std::string> hargs;
158 hargs.push_back("-o");
159 hargs.push_back(hres);
160 hargs.push_back(m_WrapUserInterface[classNum]);
162 std::vector<std::string> cxxargs;
163 cxxargs.push_back("-impl");
164 cxxargs.push_back(hres);
165 cxxargs.push_back("-o");
166 cxxargs.push_back(cxxres);
167 cxxargs.push_back(m_WrapUserInterface[classNum]);
169 std::vector<std::string> mocargs;
170 mocargs.push_back("-o");
171 mocargs.push_back(mocres);
172 mocargs.push_back(hres);
174 m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
175 uic_exe.c_str(), hargs, depends,
176 hres.c_str(), m_LibraryName.c_str());
178 depends.push_back(hres);
180 m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
181 uic_exe.c_str(), cxxargs, depends,
182 cxxres.c_str(), m_LibraryName.c_str());
184 depends.clear();
185 depends.push_back(moc_exe);
187 m_Makefile->AddCustomCommand(hres.c_str(),
188 moc_exe.c_str(), mocargs, depends,
189 mocres.c_str(), m_LibraryName.c_str());
193 m_Makefile->AddDefinition("GENERATED_QT_FILES",ui_list.c_str());