STYLE: Fix line-too-long
[cmake.git] / Source / cmQTWrapCPPCommand.cxx
blobf34e360cefb5bca6c2f59ba56a3a1842b4767910
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: cmQTWrapCPPCommand.cxx,v $
5 Language: C++
6 Date: $Date: 2008-01-23 15:27:59 $
7 Version: $Revision: 1.27 $
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 "cmQTWrapCPPCommand.h"
19 // cmQTWrapCPPCommand
20 bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& argsIn,
21 cmExecutionStatus &)
23 if(argsIn.size() < 3 )
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, 2);
33 // Get the moc executable to run in the custom command.
34 const char* moc_exe =
35 this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
37 // Get the variable holding the list of sources.
38 std::string const& sourceList = args[1];
39 std::string sourceListValue =
40 this->Makefile->GetSafeDefinition(sourceList.c_str());
42 // Create a rule for all sources listed.
43 for(std::vector<std::string>::iterator j = (args.begin() + 2);
44 j != args.end(); ++j)
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 file to generate.
51 std::string srcName =
52 cmSystemTools::GetFilenameWithoutLastExtension(*j);
53 std::string newName = this->Makefile->GetCurrentOutputDirectory();
54 newName += "/moc_";
55 newName += srcName;
56 newName += ".cxx";
57 cmSourceFile* sf =
58 this->Makefile->GetOrCreateSource(newName.c_str(), true);
59 if (curr)
61 sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT"));
64 // Compute the name of the header from which to generate the file.
65 std::string hname;
66 if(cmSystemTools::FileIsFullPath(j->c_str()))
68 hname = *j;
70 else
72 if(curr && curr->GetPropertyAsBool("GENERATED"))
74 hname = this->Makefile->GetCurrentOutputDirectory();
76 else
78 hname = this->Makefile->GetCurrentDirectory();
80 hname += "/";
81 hname += *j;
84 // Append the generated source file to the list.
85 if(!sourceListValue.empty())
87 sourceListValue += ";";
89 sourceListValue += newName;
91 // Create the custom command to generate the file.
92 cmCustomCommandLine commandLine;
93 commandLine.push_back(moc_exe);
94 commandLine.push_back("-o");
95 commandLine.push_back(newName);
96 commandLine.push_back(hname);
98 cmCustomCommandLines commandLines;
99 commandLines.push_back(commandLine);
101 std::vector<std::string> depends;
102 depends.push_back(moc_exe);
103 depends.push_back(hname);
105 const char* no_main_dependency = 0;
106 const char* no_working_dir = 0;
107 this->Makefile->AddCustomCommandToOutput(newName.c_str(),
108 depends,
109 no_main_dependency,
110 commandLines,
111 "Qt Wrapped File",
112 no_working_dir);
116 // Store the final list of source files.
117 this->Makefile->AddDefinition(sourceList.c_str(),
118 sourceListValue.c_str());
119 return true;