Simplify cmVisualStudio10TargetGenerator source classification

Combine WriteCLSources and WriteObjSources into a single method.  Use
the cmGeneratorTarget source classification to simplify tool selection
for each source file.  Extend the classification to handle .idl files.
This commit is contained in:
Brad King 2012-03-19 11:25:21 -04:00
parent 93d5509b5b
commit 328c0f65c2
4 changed files with 68 additions and 90 deletions

View File

@ -37,6 +37,7 @@ void cmGeneratorTarget::ClassifySources()
si != sources.end(); ++si) si != sources.end(); ++si)
{ {
cmSourceFile* sf = *si; cmSourceFile* sf = *si;
std::string ext = cmSystemTools::LowerCase(sf->GetExtension());
cmTarget::SourceFileFlags tsFlags = cmTarget::SourceFileFlags tsFlags =
this->Target->GetTargetSourceFileFlags(sf); this->Target->GetTargetSourceFileFlags(sf);
if(sf->GetCustomCommand()) if(sf->GetCustomCommand())
@ -57,16 +58,22 @@ void cmGeneratorTarget::ClassifySources()
this->ExternalObjects.push_back(sf); this->ExternalObjects.push_back(sf);
if(isObjLib) { badObjLib.push_back(sf); } if(isObjLib) { badObjLib.push_back(sf); }
} }
else if(cmSystemTools::LowerCase(sf->GetExtension()) == "def") else if(ext == "def")
{ {
this->ModuleDefinitionFile = sf->GetFullPath(); this->ModuleDefinitionFile = sf->GetFullPath();
if(isObjLib) { badObjLib.push_back(sf); } if(isObjLib) { badObjLib.push_back(sf); }
} }
else if(ext == "idl")
{
this->IDLSources.push_back(sf);
if(isObjLib) { badObjLib.push_back(sf); }
}
else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str())) else if(this->GlobalGenerator->IgnoreFile(sf->GetExtension().c_str()))
{ {
// We only get here if a source file is not an external object // We only get here if a source file is not an external object
// and has an extension that is listed as an ignored file type. // and has an extension that is listed as an ignored file type.
// No message or diagnosis should be given. // No message or diagnosis should be given.
this->ExtraSources.push_back(sf);
} }
else if(sf->GetLanguage()) else if(sf->GetLanguage())
{ {
@ -75,7 +82,7 @@ void cmGeneratorTarget::ClassifySources()
else else
{ {
this->ExtraSources.push_back(sf); this->ExtraSources.push_back(sf);
if(isObjLib && cmSystemTools::LowerCase(sf->GetExtension()) != "txt") if(isObjLib && ext != "txt")
{ {
badObjLib.push_back(sf); badObjLib.push_back(sf);
} }

View File

@ -38,6 +38,7 @@ public:
std::vector<cmSourceFile*> ObjectSources; std::vector<cmSourceFile*> ObjectSources;
std::vector<cmSourceFile*> ExternalObjects; std::vector<cmSourceFile*> ExternalObjects;
std::vector<cmSourceFile*> OSXContent; std::vector<cmSourceFile*> OSXContent;
std::vector<cmSourceFile*> IDLSources;
std::string ModuleDefinitionFile; std::string ModuleDefinitionFile;
std::map<cmSourceFile const*, std::string> Objects; std::map<cmSourceFile const*, std::string> Objects;

View File

@ -253,8 +253,7 @@ void cmVisualStudio10TargetGenerator::Generate()
this->WritePathAndIncrementalLinkOptions(); this->WritePathAndIncrementalLinkOptions();
this->WriteItemDefinitionGroups(); this->WriteItemDefinitionGroups();
this->WriteCustomCommands(); this->WriteCustomCommands();
this->WriteObjSources(); this->WriteAllSources();
this->WriteCLSources();
this->WriteDotNetReferences(); this->WriteDotNetReferences();
this->WriteWinRTReferences(); this->WriteWinRTReferences();
this->WriteProjectReferences(); this->WriteProjectReferences();
@ -795,107 +794,56 @@ WriteGroupSources(const char* name,
this->WriteString("</ItemGroup>\n", 1); this->WriteString("</ItemGroup>\n", 1);
} }
void cmVisualStudio10TargetGenerator::WriteObjSources() void cmVisualStudio10TargetGenerator::WriteSource(
const char* tool, cmSourceFile* sf, bool end)
{ {
if(this->Target->GetType() > cmTarget::MODULE_LIBRARY) std::string sourceFile = sf->GetFullPath();
// do not use a relative path here because it means that you
// can not use as long a path to the file.
this->ConvertToWindowsSlash(sourceFile);
this->WriteString("<", 2);
(*this->BuildFileStream ) << tool <<
" Include=\"" << sourceFile << (end? "\" />\n" : "\" ");
}
void cmVisualStudio10TargetGenerator::WriteSources(
const char* tool, std::vector<cmSourceFile*> const& sources)
{
for(std::vector<cmSourceFile*>::const_iterator
si = sources.begin(); si != sources.end(); ++si)
{ {
return; this->WriteSource(tool, *si);
}
bool first = true;
std::vector<cmSourceFile*>const & sources = this->Target->GetSourceFiles();
for(std::vector<cmSourceFile*>::const_iterator source = sources.begin();
source != sources.end(); ++source)
{
std::string ext =
cmSystemTools::LowerCase((*source)->GetExtension());
if(ext == "obj" || ext == "o")
{
if(first)
{
this->WriteString("<ItemGroup>\n", 1);
first = false;
}
// If an object file is generated, then vs10
// will use it in the build, and we have to list
// it as None instead of Object
if((*source)->GetPropertyAsBool("GENERATED"))
{
this->WriteString("<None Include=\"", 2);
}
// If it is not a generated object then we have
// to use the Object type
else
{
this->WriteString("<Object Include=\"", 2);
}
(*this->BuildFileStream ) << (*source)->GetFullPath() << "\" />\n";
}
}
if(!first)
{
this->WriteString("</ItemGroup>\n", 1);
} }
} }
void cmVisualStudio10TargetGenerator::WriteAllSources()
void cmVisualStudio10TargetGenerator::WriteCLSources()
{ {
if(this->Target->GetType() > cmTarget::UTILITY) if(this->Target->GetType() > cmTarget::UTILITY)
{ {
return; return;
} }
this->WriteString("<ItemGroup>\n", 1); this->WriteString("<ItemGroup>\n", 1);
std::vector<cmSourceFile*>const& sources = this->Target->GetSourceFiles();
for(std::vector<cmSourceFile*>::const_iterator source = sources.begin(); this->WriteSources("ClInclude", this->GeneratorTarget->HeaderSources);
source != sources.end(); ++source) this->WriteSources("Midl", this->GeneratorTarget->IDLSources);
for(std::vector<cmSourceFile*>::const_iterator
si = this->GeneratorTarget->ObjectSources.begin();
si != this->GeneratorTarget->ObjectSources.end(); ++si)
{ {
std::string ext = cmSystemTools::LowerCase((*source)->GetExtension()); const char* lang = (*si)->GetLanguage();
if((*source)->GetCustomCommand() || ext == "o" || ext == "obj") bool cl = strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0;
{ bool rc = strcmp(lang, "RC") == 0;
continue; const char* tool = cl? "ClCompile" : (rc? "ResourceCompile" : "None");
} this->WriteSource(tool, *si, false);
// If it is not a custom command and it is not a pre-built obj file,
// then add it as a source (c/c++/header/rc/idl) file
bool header = (*source)->GetPropertyAsBool("HEADER_FILE_ONLY")
|| this->GlobalGenerator->IgnoreFile(ext.c_str());
const char* lang = (*source)->GetLanguage();
bool cl = lang && (strcmp(lang, "C") == 0 || strcmp(lang, "CXX") ==0);
bool rc = lang && (strcmp(lang, "RC") == 0);
bool idl = ext == "idl";
std::string sourceFile = (*source)->GetFullPath();
// do not use a relative path here because it means that you
// can not use as long a path to the file.
this->ConvertToWindowsSlash(sourceFile);
// output the source file
if(header)
{
this->WriteString("<ClInclude Include=\"", 2);
}
else if(cl)
{
this->WriteString("<ClCompile Include=\"", 2);
}
else if(rc)
{
this->WriteString("<ResourceCompile Include=\"", 2);
}
else if(idl)
{
this->WriteString("<Midl Include=\"", 2);
}
else
{
this->WriteString("<None Include=\"", 2);
}
(*this->BuildFileStream ) << sourceFile << "\"";
// ouput any flags specific to this source file // ouput any flags specific to this source file
if(!header && cl && this->OutputSourceSpecificFlags(*source)) if(cl && this->OutputSourceSpecificFlags(*si))
{ {
// if the source file has specific flags the tag // if the source file has specific flags the tag
// is ended on a new line // is ended on a new line
this->WriteString("</ClCompile>\n", 2); this->WriteString("</ClCompile>\n", 2);
} }
else if(!header && rc && this->OutputSourceSpecificFlags(*source)) else if(rc && this->OutputSourceSpecificFlags(*si))
{ {
this->WriteString("</ResourceCompile>\n", 2); this->WriteString("</ResourceCompile>\n", 2);
} }
@ -905,6 +853,27 @@ void cmVisualStudio10TargetGenerator::WriteCLSources()
} }
} }
for(std::vector<cmSourceFile*>::const_iterator
si = this->GeneratorTarget->ExternalObjects.begin();
si != this->GeneratorTarget->ExternalObjects.end(); ++si)
{
// If an object file is generated, then vs10
// will use it in the build, and we have to list
// it as None instead of Object
if((*si)->GetPropertyAsBool("GENERATED"))
{
this->WriteSource("None", *si);
}
// If it is not a generated object then we have
// to use the Object type
else
{
this->WriteSource("Object", *si);
}
}
this->WriteSources("None", this->GeneratorTarget->ExtraSources);
// Add object library contents as external objects. // Add object library contents as external objects.
std::vector<std::string> objs; std::vector<std::string> objs;
this->GeneratorTarget->UseObjectLibraries(objs); this->GeneratorTarget->UseObjectLibraries(objs);

View File

@ -47,10 +47,11 @@ private:
void WriteString(const char* line, int indentLevel); void WriteString(const char* line, int indentLevel);
void WriteProjectConfigurations(); void WriteProjectConfigurations();
void WriteProjectConfigurationValues(); void WriteProjectConfigurationValues();
void WriteCLSources(); void WriteSource(const char* tool, cmSourceFile* sf, bool end = true);
void WriteSources(const char* tool, std::vector<cmSourceFile*> const&);
void WriteAllSources();
void WriteDotNetReferences(); void WriteDotNetReferences();
void WriteWinRTReferences(); void WriteWinRTReferences();
void WriteObjSources();
void WritePathAndIncrementalLinkOptions(); void WritePathAndIncrementalLinkOptions();
void WriteItemDefinitionGroups(); void WriteItemDefinitionGroups();
bool ComputeClOptions(); bool ComputeClOptions();