packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmQTWrapCPPCommand.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 "cmQTWrapCPPCommand.h"
13
14 // cmQTWrapCPPCommand
15 bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& argsIn,
16                                      cmExecutionStatus &)
17 {
18   if(argsIn.size() < 3 )
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, 2);
27
28   // Get the moc executable to run in the custom command.
29   const char* moc_exe =
30     this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
31
32   // Get the variable holding the list of sources.
33   std::string const& sourceList = args[1];
34   std::string sourceListValue =
35     this->Makefile->GetSafeDefinition(sourceList.c_str());
36
37   // Create a rule for all sources listed.
38   for(std::vector<std::string>::iterator j = (args.begin() + 2);
39       j != args.end(); ++j)
40     {
41     cmSourceFile *curr = this->Makefile->GetSource(j->c_str());
42     // if we should wrap the class
43     if(!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE")))
44       {
45       // Compute the name of the file to generate.
46       std::string srcName =
47         cmSystemTools::GetFilenameWithoutLastExtension(*j);
48       std::string newName = this->Makefile->GetCurrentOutputDirectory();
49       newName += "/moc_";
50       newName += srcName;
51       newName += ".cxx";
52       cmSourceFile* sf =
53         this->Makefile->GetOrCreateSource(newName.c_str(), true);
54       if (curr)
55         {
56         sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT"));
57         }
58
59       // Compute the name of the header from which to generate the file.
60       std::string hname;
61       if(cmSystemTools::FileIsFullPath(j->c_str()))
62         {
63         hname = *j;
64         }
65       else
66         {
67         if(curr && curr->GetPropertyAsBool("GENERATED"))
68           {
69           hname = this->Makefile->GetCurrentOutputDirectory();
70           }
71         else
72           {
73           hname = this->Makefile->GetCurrentDirectory();
74           }
75         hname += "/";
76         hname += *j;
77         }
78
79       // Append the generated source file to the list.
80       if(!sourceListValue.empty())
81         {
82         sourceListValue += ";";
83         }
84       sourceListValue += newName;
85
86       // Create the custom command to generate the file.
87       cmCustomCommandLine commandLine;
88       commandLine.push_back(moc_exe);
89       commandLine.push_back("-o");
90       commandLine.push_back(newName);
91       commandLine.push_back(hname);
92
93       cmCustomCommandLines commandLines;
94       commandLines.push_back(commandLine);
95
96       std::vector<std::string> depends;
97       depends.push_back(moc_exe);
98       depends.push_back(hname);
99
100       const char* no_main_dependency = 0;
101       const char* no_working_dir = 0;
102       this->Makefile->AddCustomCommandToOutput(newName.c_str(),
103                                                depends,
104                                                no_main_dependency,
105                                                commandLines,
106                                                "Qt Wrapped File",
107                                                no_working_dir);
108       }
109     }
110
111   // Store the final list of source files.
112   this->Makefile->AddDefinition(sourceList.c_str(),
113                                 sourceListValue.c_str());
114   return true;
115 }