CMake/Source/cmQTWrapCPPCommand.cxx
Brad King 35936433e1 ENH: Merging changes from branch CMake-SourceFile2-b between tags
CMake-SourceFile2-bp and CMake-SourceFile2-b-mp1 to trunk.  This
commit is surrounded by tags CMake-SourceFile2-b-mp1-pre and
CMake-SourceFile2-b-mp1-post on the trunk.

The changes re-implement cmSourceFile and the use of it to allow
instances to be created much earlier.  The use of cmSourceFileLocation
allows locating a source file referenced by a user to be much simpler
and more robust.  The two SetName methods are no longer needed so some
duplicate code has been removed.  The strange "SourceName" stuff is
gone.  Code that created cmSourceFile instances on the stack and then
sent them to cmMakefile::AddSource has been simplified and converted
to getting cmSourceFile instances from cmMakefile.  The CPluginAPI has
preserved the old API through a compatibility interface.

Source lists are gone.  Targets now get real instances of cmSourceFile
right away instead of storing a list of strings until the final pass.

TraceVSDependencies has been re-written to avoid the use of
SourceName.  It is now called TraceDependencies since it is not just
for VS.  It is now implemented with a helper object which makes the
code simpler.
2007-06-18 11:59:23 -04:00

120 lines
3.9 KiB
C++

/*=========================================================================
Program: CMake - Cross-Platform Makefile Generator
Module: $RCSfile$
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "cmQTWrapCPPCommand.h"
// cmQTWrapCPPCommand
bool cmQTWrapCPPCommand::InitialPass(std::vector<std::string> const& argsIn)
{
if(argsIn.size() < 3 )
{
this->SetError("called with incorrect number of arguments");
return false;
}
// This command supports source list inputs for compatibility.
std::vector<std::string> args;
this->Makefile->ExpandSourceListArguments(argsIn, args, 2);
// Get the moc executable to run in the custom command.
const char* moc_exe =
this->Makefile->GetRequiredDefinition("QT_MOC_EXECUTABLE");
// Get the variable holding the list of sources.
std::string const& sourceList = args[1];
std::string sourceListValue =
this->Makefile->GetSafeDefinition(sourceList.c_str());
// Create a rule for all sources listed.
for(std::vector<std::string>::iterator j = (args.begin() + 2);
j != args.end(); ++j)
{
cmSourceFile *curr = this->Makefile->GetSource(j->c_str());
// if we should wrap the class
if(!(curr && curr->GetPropertyAsBool("WRAP_EXCLUDE")))
{
// Compute the name of the file to generate.
std::string srcName =
cmSystemTools::GetFilenameWithoutLastExtension(*j);
std::string newName = this->Makefile->GetCurrentOutputDirectory();
newName += "/moc_";
newName += srcName;
newName += ".cxx";
cmSourceFile* sf =
this->Makefile->GetOrCreateSource(newName.c_str(), true);
if (curr)
{
sf->SetProperty("ABSTRACT", curr->GetProperty("ABSTRACT"));
}
// Compute the name of the header from which to generate the file.
std::string hname;
if(cmSystemTools::FileIsFullPath(j->c_str()))
{
hname = *j;
}
else
{
if(curr && curr->GetPropertyAsBool("GENERATED"))
{
hname = this->Makefile->GetCurrentOutputDirectory();
}
else
{
hname = this->Makefile->GetCurrentDirectory();
}
hname += "/";
hname += *j;
}
// Append the generated source file to the list.
if(!sourceListValue.empty())
{
sourceListValue += ";";
}
sourceListValue += newName;
// Create the custom command to generate the file.
cmCustomCommandLine commandLine;
commandLine.push_back(moc_exe);
commandLine.push_back("-o");
commandLine.push_back(newName);
commandLine.push_back(hname);
cmCustomCommandLines commandLines;
commandLines.push_back(commandLine);
std::vector<std::string> depends;
depends.push_back(moc_exe);
depends.push_back(hname);
const char* no_main_dependency = 0;
const char* no_working_dir = 0;
this->Makefile->AddCustomCommandToOutput(newName.c_str(),
depends,
no_main_dependency,
commandLines,
"QT Wrapped File",
no_working_dir);
}
}
// Store the final list of source files.
this->Makefile->AddDefinition(sourceList.c_str(),
sourceListValue.c_str());
return true;
}