ENH: mark some vars as advanced (and resort the list)
[cmake.git] / Source / cmQTWrapCPPCommand.cxx
blob05e6ffadcc38ada14877c01325929c68e6d93620
1 /*=========================================================================
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: cmQTWrapCPPCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2002-09-02 11:03:43 $
7 Version: $Revision: 1.13 $
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 "cmQTWrapCPPCommand.h"
19 // cmQTWrapCPPCommand
20 bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& argsIn)
22 if(argsIn.size() < 3 )
24 this->SetError("called with incorrect number of arguments");
25 return false;
27 std::vector<std::string> args;
28 m_Makefile->ExpandSourceListArguments(argsIn, args, 2);
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_CPP_value = m_Makefile->GetDefinition("QT_WRAP_CPP");
33 if (QT_WRAP_CPP_value==0)
35 this->SetError("called with QT_WRAP_CPP undefined");
36 return false;
39 if(cmSystemTools::IsOff(QT_WRAP_CPP_value))
41 this->SetError("called with QT_WRAP_CPP 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_SourceList = args[1];
52 std::string sourceListValue;
54 // was the list already populated
55 const char *def = m_Makefile->GetDefinition(m_SourceList.c_str());
56 if (def)
58 sourceListValue = def;
61 // get the list of classes for this library
62 for(std::vector<std::string>::iterator j = (args.begin() + 2);
63 j != args.end(); ++j)
65 cmSourceFile *curr = m_Makefile->GetSource(j->c_str());
67 // if we should wrap the class
68 if (!curr || !curr->GetPropertyAsBool("WRAP_EXCLUDE"))
70 cmSourceFile file;
71 if (curr)
73 file.SetProperty("ABSTRACT",curr->GetProperty("ABSTRACT"));
75 std::string srcName = cmSystemTools::GetFilenameWithoutExtension(*j);
76 std::string newName = "moc_" + srcName;
77 file.SetName(newName.c_str(), m_Makefile->GetCurrentOutputDirectory(),
78 "cxx",false);
79 std::string hname = cdir + "/" + *j;
80 m_WrapHeaders.push_back(hname);
81 // add starting depends
82 file.GetDepends().push_back(hname);
83 m_WrapClasses.push_back(file);
84 if (sourceListValue.size() > 0)
86 sourceListValue += ";";
88 sourceListValue += newName + ".cxx";
92 m_Makefile->AddDefinition(m_SourceList.c_str(), sourceListValue.c_str());
93 return true;
96 void cmQTWrapCPPCommand::FinalPass()
99 // first we add the rules for all the .h to Moc files
100 size_t lastClass = m_WrapClasses.size();
101 std::vector<std::string> depends;
102 std::string moc_exe = "${QT_MOC_EXECUTABLE}";
104 // wrap all the .h files
105 depends.push_back(moc_exe);
107 const char * GENERATED_QT_FILES_value=
108 m_Makefile->GetDefinition("GENERATED_QT_FILES");
109 std::string moc_list("");
110 if (GENERATED_QT_FILES_value!=0)
112 moc_list=moc_list+GENERATED_QT_FILES_value;
115 for(size_t classNum = 0; classNum < lastClass; classNum++)
117 // Add output to build list
118 m_Makefile->AddSource(m_WrapClasses[classNum]);
120 // set up moc command
121 std::string res = m_Makefile->GetCurrentOutputDirectory();
122 res += "/";
123 res += m_WrapClasses[classNum].GetSourceName() + ".cxx";
125 moc_list = moc_list + " " + res;
127 std::vector<std::string> args;
128 args.push_back("-o");
129 args.push_back(res);
130 args.push_back(m_WrapHeaders[classNum]);
132 m_Makefile->AddCustomCommand(m_WrapHeaders[classNum].c_str(),
133 moc_exe.c_str(), args, depends,
134 res.c_str(), m_LibraryName.c_str());
138 m_Makefile->AddDefinition("GENERATED_QT_FILES",moc_list.c_str());