summaryrefslogtreecommitdiffstats
path: root/Source/cmVisualStudio10TargetGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2012-03-19 15:25:21 (GMT)
committerBrad King <brad.king@kitware.com>2012-03-19 21:13:41 (GMT)
commit328c0f65c2a273c6adcdb11f96ee057d80014de2 (patch)
treef96b61b78fe9e94331ebba7c5433fabdbcff9244 /Source/cmVisualStudio10TargetGenerator.cxx
parent93d5509b5b1c208f3ed28daf35f9384ab6918441 (diff)
downloadCMake-328c0f65c2a273c6adcdb11f96ee057d80014de2.zip
CMake-328c0f65c2a273c6adcdb11f96ee057d80014de2.tar.gz
CMake-328c0f65c2a273c6adcdb11f96ee057d80014de2.tar.bz2
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.
Diffstat (limited to 'Source/cmVisualStudio10TargetGenerator.cxx')
-rw-r--r--Source/cmVisualStudio10TargetGenerator.cxx143
1 files changed, 56 insertions, 87 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx
index 054b86b..88ad178 100644
--- a/Source/cmVisualStudio10TargetGenerator.cxx
+++ b/Source/cmVisualStudio10TargetGenerator.cxx
@@ -253,8 +253,7 @@ void cmVisualStudio10TargetGenerator::Generate()
this->WritePathAndIncrementalLinkOptions();
this->WriteItemDefinitionGroups();
this->WriteCustomCommands();
- this->WriteObjSources();
- this->WriteCLSources();
+ this->WriteAllSources();
this->WriteDotNetReferences();
this->WriteWinRTReferences();
this->WriteProjectReferences();
@@ -795,107 +794,56 @@ WriteGroupSources(const char* name,
this->WriteString("</ItemGroup>\n", 1);
}
-void cmVisualStudio10TargetGenerator::WriteObjSources()
-{
- if(this->Target->GetType() > cmTarget::MODULE_LIBRARY)
- {
- return;
- }
- 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)
+void cmVisualStudio10TargetGenerator::WriteSource(
+ const char* tool, cmSourceFile* sf, bool end)
+{
+ 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)
{
- this->WriteString("</ItemGroup>\n", 1);
+ this->WriteSource(tool, *si);
}
}
-
-void cmVisualStudio10TargetGenerator::WriteCLSources()
+void cmVisualStudio10TargetGenerator::WriteAllSources()
{
if(this->Target->GetType() > cmTarget::UTILITY)
{
return;
}
this->WriteString("<ItemGroup>\n", 1);
- 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((*source)->GetCustomCommand() || ext == "o" || ext == "obj")
- {
- continue;
- }
- // 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 << "\"";
+
+ this->WriteSources("ClInclude", this->GeneratorTarget->HeaderSources);
+ this->WriteSources("Midl", this->GeneratorTarget->IDLSources);
+
+ for(std::vector<cmSourceFile*>::const_iterator
+ si = this->GeneratorTarget->ObjectSources.begin();
+ si != this->GeneratorTarget->ObjectSources.end(); ++si)
+ {
+ const char* lang = (*si)->GetLanguage();
+ bool cl = strcmp(lang, "C") == 0 || strcmp(lang, "CXX") == 0;
+ bool rc = strcmp(lang, "RC") == 0;
+ const char* tool = cl? "ClCompile" : (rc? "ResourceCompile" : "None");
+ this->WriteSource(tool, *si, false);
// 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
// is ended on a new line
this->WriteString("</ClCompile>\n", 2);
}
- else if(!header && rc && this->OutputSourceSpecificFlags(*source))
+ else if(rc && this->OutputSourceSpecificFlags(*si))
{
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.
std::vector<std::string> objs;
this->GeneratorTarget->UseObjectLibraries(objs);