~ubuntu-branches/ubuntu/intrepid/cmake/intrepid-backports

« back to all changes in this revision

Viewing changes to Source/cmQTWrapUICommand.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Maitland Bottoms
  • Date: 2002-02-14 18:36:25 UTC
  • Revision ID: james.westby@ubuntu.com-20020214183625-8m44isdas2k4l0f7
Tags: upstream-1.2
ImportĀ upstreamĀ versionĀ 1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Insight Segmentation & Registration Toolkit
 
4
  Module:    $RCSfile: cmQTWrapUICommand.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2001/11/21 13:46:59 $
 
7
  Version:   $Revision: 1.3 $
 
8
  Author:    Franck Bettinger.
 
9
 
 
10
Copyright (c) 2001 Insight Consortium
 
11
All rights reserved.
 
12
 
 
13
Redistribution and use in source and binary forms, with or without
 
14
modification, are permitted provided that the following conditions are met:
 
15
 
 
16
 * Redistributions of source code must retain the above copyright notice,
 
17
   this list of conditions and the following disclaimer.
 
18
 
 
19
 * Redistributions in binary form must reproduce the above copyright notice,
 
20
   this list of conditions and the following disclaimer in the documentation
 
21
   and/or other materials provided with the distribution.
 
22
 
 
23
 * The name of the Insight Consortium, nor the names of any consortium members,
 
24
   nor of any contributors, may be used to endorse or promote products derived
 
25
   from this software without specific prior written permission.
 
26
 
 
27
  * Modified source versions must be plainly marked as such, and must not be
 
28
    misrepresented as being the original software.
 
29
 
 
30
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
 
31
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
32
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
33
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
 
34
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
35
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
36
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
37
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
38
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
39
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
40
 
 
41
=========================================================================*/
 
42
#include "cmQTWrapUICommand.h"
 
43
 
 
44
// cmQTWrapUICommand
 
45
bool cmQTWrapUICommand::InitialPass(std::vector<std::string> const& args)
 
46
{
 
47
  if(args.size() < 4 )
 
48
    {
 
49
    this->SetError("called with incorrect number of arguments");
 
50
    return false;
 
51
    }
 
52
 
 
53
  // Now check and see if the value has been stored in the cache
 
54
  // already, if so use that value and don't look for the program
 
55
  const char* QT_WRAP_UI_value = m_Makefile->GetDefinition("QT_WRAP_UI");
 
56
  if (QT_WRAP_UI_value==0)
 
57
    {
 
58
    this->SetError("called with QT_WRAP_UI undefined");
 
59
    return false;
 
60
    }
 
61
  
 
62
  if(cmSystemTools::IsOff(QT_WRAP_UI_value))
 
63
    {
 
64
    this->SetError("called with QT_WRAP_UI off : ");
 
65
    return false;
 
66
    }
 
67
 
 
68
  // what is the current source dir
 
69
  std::string cdir = m_Makefile->GetCurrentDirectory();
 
70
 
 
71
  // keep the library name
 
72
  m_LibraryName = args[0];
 
73
  m_HeaderList = args[1];
 
74
  m_SourceList = args[2];
 
75
 
 
76
  // get the list of classes for this library
 
77
  cmMakefile::SourceMap &Classes = m_Makefile->GetSources();
 
78
 
 
79
 
 
80
  for(std::vector<std::string>::const_iterator j = (args.begin() + 3);
 
81
      j != args.end(); ++j)
 
82
    {  
 
83
    cmMakefile::SourceMap::iterator l = Classes.find(*j);
 
84
    if (l == Classes.end())
 
85
      {
 
86
      this->SetError("bad source list passed to QTWrapUICommand");
 
87
      return false;
 
88
      }
 
89
    for(std::vector<cmSourceFile>::iterator i = l->second.begin(); 
 
90
        i != l->second.end(); i++)
 
91
      {
 
92
      cmSourceFile &curr = *i;
 
93
      // if we should wrap the class
 
94
      if (!curr.GetWrapExclude())
 
95
        {
 
96
        cmSourceFile header_file;
 
97
        cmSourceFile source_file;
 
98
        cmSourceFile moc_file;
 
99
        header_file.SetName(curr.GetSourceName().c_str(), 
 
100
                    m_Makefile->GetCurrentOutputDirectory(),
 
101
                     "h",false);
 
102
        source_file.SetName(curr.GetSourceName().c_str(), 
 
103
                    m_Makefile->GetCurrentOutputDirectory(),
 
104
                     "cxx",false);
 
105
        std::string moc_source_name("moc_");
 
106
        moc_source_name = moc_source_name + curr.GetSourceName().c_str();
 
107
        moc_file.SetName(moc_source_name.c_str(), 
 
108
                    m_Makefile->GetCurrentOutputDirectory(),
 
109
                     "cxx",false);
 
110
        std::string origname = cdir + "/" + curr.GetSourceName() + "." +
 
111
            curr.GetSourceExtension();
 
112
        std::string hname = header_file.GetFullPath();
 
113
        m_WrapUserInterface.push_back(origname);
 
114
        // add starting depends
 
115
        moc_file.GetDepends().push_back(hname);
 
116
        source_file.GetDepends().push_back(hname);
 
117
        source_file.GetDepends().push_back(origname);
 
118
        header_file.GetDepends().push_back(origname);
 
119
        m_WrapHeadersClasses.push_back(header_file);
 
120
        m_WrapSourcesClasses.push_back(source_file);
 
121
        m_WrapMocClasses.push_back(moc_file);
 
122
        m_Makefile->AddSource(header_file,
 
123
            m_HeaderList.c_str());
 
124
        m_Makefile->AddSource(source_file,
 
125
            m_SourceList.c_str());
 
126
        m_Makefile->AddSource(moc_file,
 
127
            m_SourceList.c_str());
 
128
        }
 
129
      }
 
130
    }
 
131
  
 
132
  return true;
 
133
}
 
134
 
 
135
void cmQTWrapUICommand::FinalPass() 
 
136
{
 
137
 
 
138
  // first we add the rules for all the .ui to .h and .cxx files
 
139
  int lastHeadersClass = m_WrapHeadersClasses.size();
 
140
  std::vector<std::string> depends;
 
141
  std::string uic_exe = "${QT_UIC_EXE}";
 
142
  std::string moc_exe = "${QT_MOC_EXE}";
 
143
 
 
144
 
 
145
  // wrap all the .h files
 
146
  depends.push_back(uic_exe);
 
147
 
 
148
  const char * GENERATED_QT_FILES_value=
 
149
      m_Makefile->GetDefinition("GENERATED_QT_FILES");
 
150
  std::string ui_list("");
 
151
  if (GENERATED_QT_FILES_value!=0)
 
152
    {
 
153
    ui_list=ui_list+GENERATED_QT_FILES_value;
 
154
    } 
 
155
 
 
156
  for(int classNum = 0; classNum < lastHeadersClass; classNum++)
 
157
    {
 
158
    // set up .ui to .h and .cxx command
 
159
 
 
160
    std::string hres = m_Makefile->GetCurrentOutputDirectory();
 
161
    hres += "/";
 
162
    hres += m_WrapHeadersClasses[classNum].GetSourceName() + "." +
 
163
        m_WrapHeadersClasses[classNum].GetSourceExtension();
 
164
 
 
165
    std::string cxxres = m_Makefile->GetCurrentOutputDirectory();
 
166
    cxxres += "/";
 
167
    cxxres += m_WrapSourcesClasses[classNum].GetSourceName() + "." +
 
168
        m_WrapSourcesClasses[classNum].GetSourceExtension();
 
169
 
 
170
    std::string mocres = m_Makefile->GetCurrentOutputDirectory();
 
171
    mocres += "/";
 
172
    mocres += m_WrapMocClasses[classNum].GetSourceName() + "." +
 
173
        m_WrapMocClasses[classNum].GetSourceExtension();
 
174
 
 
175
    ui_list = ui_list + " " + hres + " " + cxxres + " " + mocres;
 
176
    
 
177
    std::vector<std::string> hargs;
 
178
    hargs.push_back("-o");
 
179
    hargs.push_back(hres);
 
180
    hargs.push_back(m_WrapUserInterface[classNum]);
 
181
 
 
182
    std::vector<std::string> cxxargs;
 
183
    cxxargs.push_back("-impl");
 
184
    cxxargs.push_back(hres);
 
185
    cxxargs.push_back("-o");
 
186
    cxxargs.push_back(cxxres);
 
187
    cxxargs.push_back(m_WrapUserInterface[classNum]);
 
188
 
 
189
    std::vector<std::string> mocargs;
 
190
    mocargs.push_back("-o");
 
191
    mocargs.push_back(mocres);
 
192
    mocargs.push_back(hres);
 
193
 
 
194
    m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
 
195
                                 uic_exe.c_str(), hargs, depends, 
 
196
                                 hres.c_str(), m_LibraryName.c_str());
 
197
 
 
198
    depends.push_back(hres);
 
199
 
 
200
    m_Makefile->AddCustomCommand(m_WrapUserInterface[classNum].c_str(),
 
201
                                 uic_exe.c_str(), cxxargs, depends, 
 
202
                                 cxxres.c_str(), m_LibraryName.c_str());
 
203
 
 
204
    depends.clear();
 
205
    depends.push_back(moc_exe);
 
206
 
 
207
    m_Makefile->AddCustomCommand(hres.c_str(),
 
208
                                 moc_exe.c_str(), mocargs, depends, 
 
209
                                 mocres.c_str(), m_LibraryName.c_str());
 
210
 
 
211
    }
 
212
 
 
213
  m_Makefile->AddDefinition("GENERATED_QT_FILES",ui_list.c_str());
 
214
 
 
215
}
 
216
 
 
217
 
 
218