FIX: apply patch from bug# 1965

This commit is contained in:
Bill Hoffman 2005-07-13 11:21:30 -04:00
parent 1e72091e86
commit aa47caab2d
9 changed files with 940 additions and 628 deletions

View File

@ -316,12 +316,22 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
sg != sourceGroups.end(); ++sg)
{
this->WriteGroup(&(*sg), target, fout, libName);
}
// Write the DSP file's footer.
this->WriteDSPFooter(fout);
}
void cmLocalVisualStudio6Generator::WriteGroup(const cmSourceGroup *sg, cmTarget target, std::ostream &fout, const char *libName)
{
const std::vector<const cmSourceFile *> &sourceFiles =
sg->GetSourceFiles();
// If the group is empty, don't write it at all.
if(sourceFiles.empty())
{
continue;
return;
}
// If the group has a name, write the header.
@ -411,15 +421,22 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout,
}
}
std::vector<cmSourceGroup> children = sg->GetGroupChildren();
for(unsigned int i=0;i<children.size();++i)
{
this->WriteGroup(&children[i], target, fout, libName);
}
// If the group has a name, write the footer.
if(name != "")
{
this->WriteDSPEndGroup(fout);
}
}
// Write the DSP file's footer.
this->WriteDSPFooter(fout);
}
@ -763,9 +780,11 @@ void cmLocalVisualStudio6Generator
libPath = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
}
std::string exePath = "";
std::string exePathDebug = "";
if (m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH"))
{
exePath = m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH");
}
if(libPath.size())
{
@ -952,13 +971,37 @@ void cmLocalVisualStudio6Generator
extraLinkOptions =
m_Makefile->GetRequiredDefinition("CMAKE_EXE_LINKER_FLAGS");
// if the executable has an output name then add the appropriate flag
if (target.GetProperty("OUTPUT_NAME"))
{
std::string outputname = target.GetProperty("OUTPUT_NAME");
libMultiLineOptions += "# ADD LINK32 /out:";
libMultiLineOptions += target.GetProperty("OUTPUT_NAME");
libMultiLineOptions += outputname;
libMultiLineOptions += " \n";
}
else
{
libMultiLineOptions += "# ADD LINK32 /out:\"";
if(exePath != "")
libMultiLineOptions += exePath + "/" + libName + ".exe";
else
libMultiLineOptions += std::string(libName) + ".exe";
libMultiLineOptions += "\"\n";
libMultiLineOptionsForDebug += "# ADD LINK32 /out:\"";
if(exePath != "")
libMultiLineOptionsForDebug += exePath + "/" + libName + "D.exe";
else
libMultiLineOptionsForDebug += std::string(libName) + "D.exe";
libMultiLineOptionsForDebug += "\"\n";
}
}
if(target.GetType() == cmTarget::SHARED_LIBRARY)
{
@ -1087,9 +1130,28 @@ void cmLocalVisualStudio6Generator
cmSystemTools::ReplaceString(line, "LIBRARY_OUTPUT_PATH",
removeQuotes(
this->ConvertToOptionallyRelativeOutputPath(libPath.c_str())).c_str());
if (!m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH_OVERRIDE") || exePath == "")
{
cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATH",
removeQuotes(
this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
} else
{
cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATHRelease",
removeQuotes(
this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATHDebug",
removeQuotes(
this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATHMinSizeRel",
removeQuotes(
this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
cmSystemTools::ReplaceString(line, "EXECUTABLE_OUTPUT_PATHRelWithDebInfo",
removeQuotes(
this->ConvertToOptionallyRelativeOutputPath(exePath.c_str())).c_str());
}
cmSystemTools::ReplaceString(line,
"EXTRA_DEFINES",
m_Makefile->GetDefineFlags());

View File

@ -90,7 +90,8 @@ private:
void AddUtilityCommandHack(cmTarget& target, int count,
std::vector<std::string>& depends,
const cmCustomCommandLines& commandLines);
void WriteGroup(const cmSourceGroup *sg, cmTarget target,
std::ostream &fout, const char *libName);
std::string CreateTargetRules(cmTarget &target,
const char *libName);
std::string m_IncludeOptions;

View File

@ -724,7 +724,10 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
this->OutputLibraries(fout, configName, libName, target);
fout << "\"\n";
temp = m_ExecutableOutputPath;
if (!m_Makefile->GetDefinition("EXECUTABLE_OUTPUT_PATH_OVERRIDE"))
temp += configName;
temp += "/";
// do we have a different executable name?
@ -736,6 +739,9 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
{
temp += libName;
}
temp += debugPostfix;
temp += ".exe";
fout << "\t\t\t\tOutputFile=\"" << this->ConvertToXMLOutputPathSingle(temp.c_str()) << "\"\n";
for(std::map<cmStdString, cmStdString>::iterator i = flagMap.begin();
@ -988,15 +994,28 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
// Loop through every source group.
for(std::vector<cmSourceGroup>::const_iterator sg = sourceGroups.begin();
sg != sourceGroups.end(); ++sg)
for(unsigned int i = 0; i < sourceGroups.size(); ++i)
{
cmSourceGroup sg = sourceGroups[i];
this->WriteGroup(&sg, target, fout, libName, configs);
}
//}
fout << "\t</Files>\n";
// Write the VCProj file's footer.
this->WriteVCProjFooter(fout);
}
void cmLocalVisualStudio7Generator::WriteGroup(const cmSourceGroup *sg, cmTarget target, std::ostream &fout, const char *libName, std::vector<std::string> *configs)
{
const std::vector<const cmSourceFile *> &sourceFiles =
sg->GetSourceFiles();
// If the group is empty, don't write it at all.
if(sourceFiles.empty())
{
continue;
return;
}
// If the group has a name, write the header.
@ -1105,19 +1124,20 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout,
}
}
std::vector<cmSourceGroup> children = sg->GetGroupChildren();
for(unsigned int i=0;i<children.size();++i)
{
this->WriteGroup(&children[i], target, fout, libName, configs);
}
// If the group has a name, write the footer.
if(name != "")
{
this->WriteVCProjEndGroup(fout);
}
}
fout << "\t</Files>\n";
// Write the VCProj file's footer.
this->WriteVCProjFooter(fout);
}
void cmLocalVisualStudio7Generator::
WriteCustomRule(std::ostream& fout,
const char* source,

View File

@ -111,6 +111,8 @@ private:
const char* output,
const char* extraFlags);
void WriteGroup(const cmSourceGroup *sg, cmTarget target, std::ostream &fout, const char *libName, std::vector<std::string> *configs);
std::vector<std::string> m_CreatedProjectNames;
std::string m_LibraryOutputPath;
std::string m_ExecutableOutputPath;

View File

@ -418,7 +418,7 @@ void cmMakefile::AddCommand(cmCommand* wg)
this->GetCMakeInstance()->AddCommand(wg);
}
// Set the make file
// Set the make file
void cmMakefile::SetLocalGenerator(cmLocalGenerator* lg)
{
m_LocalGenerator = lg;
@ -439,7 +439,7 @@ void cmMakefile::FinalPass()
}
// Generate the output file
// Generate the output file
void cmMakefile::ConfigureFinalPass()
{
this->FinalPass();
@ -1181,17 +1181,29 @@ cmSourceGroup* cmMakefile::GetSourceGroup(const char* name)
{
return &(*sg);
}
else
{
cmSourceGroup *target = sg->lookupChild(name);
if(target)
{
return target;
}
}
}
return 0;
}
void cmMakefile::AddSourceGroup(const char* name, const char* regex)
void cmMakefile::AddSourceGroup(const char* name, const char* regex, const char *parent)
{
// First see if the group exists. If so, replace its regular expression.
for(std::vector<cmSourceGroup>::iterator sg = m_SourceGroups.begin();
sg != m_SourceGroups.end(); ++sg)
for(unsigned int i=0;i<m_SourceGroups.size();++i)
{
cmSourceGroup *sg = &m_SourceGroups[i];
std::string sgName = sg->GetName();
if(!parent)
{
if(sgName == name)
{
if ( regex )
@ -1203,6 +1215,52 @@ void cmMakefile::AddSourceGroup(const char* name, const char* regex)
return;
}
}
else
{
if(sgName == parent)
{
cmSourceGroup *localtarget = sg->lookupChild(name);
if(localtarget)
{
if ( regex )
{
// We only want to set the regular expression. If there are already
// source files in the group, we don't want to remove them.
localtarget->SetGroupRegex(regex);
}
}
else
{
sg->AddChild(cmSourceGroup(name, regex));
}
return;
}
else
{
cmSourceGroup *localtarget = sg->lookupChild(parent);
if(localtarget)
{
cmSourceGroup *addtarget = localtarget->lookupChild(name);
if(addtarget)
{
if ( regex )
{
// We only want to set the regular expression. If there are already
// source files in the group, we don't want to remove them.
addtarget->SetGroupRegex(regex);
}
}
else
{
localtarget->AddChild(cmSourceGroup(name, regex));
}
return;
}
}
}
}
// The group doesn't exist. Add it.
m_SourceGroups.push_back(cmSourceGroup(name, regex));
@ -1651,9 +1709,10 @@ cmMakefile::FindSourceGroup(const char* source,
for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
sg != groups.rend(); ++sg)
{
if(sg->MatchesFiles(source))
cmSourceGroup *result = sg->MatchChildrenFiles(source);
if(result)
{
return *sg;
return *result;
}
}
@ -1661,12 +1720,14 @@ cmMakefile::FindSourceGroup(const char* source,
for(std::vector<cmSourceGroup>::reverse_iterator sg = groups.rbegin();
sg != groups.rend(); ++sg)
{
if(sg->MatchesRegex(source))
cmSourceGroup *result = sg->MatchChildrenRegex(source);
if(result)
{
return *sg;
return *result;
}
}
// Shouldn't get here, but just in case, return the default group.
return groups.front();
}

View File

@ -280,7 +280,7 @@ public:
/**
* Add a source group for consideration when adding a new source.
*/
void AddSourceGroup(const char* name, const char* regex=0);
void AddSourceGroup(const char* name, const char* regex=0, const char* parent=0);
/**
* Add an auxiliary directory to the build.

View File

@ -81,3 +81,88 @@ std::vector<const cmSourceFile*>& cmSourceGroup::GetSourceFiles()
{
return m_SourceFiles;
}
//----------------------------------------------------------------------------
void cmSourceGroup::AddChild(cmSourceGroup child)
{
m_GroupChildren.push_back(child);
}
//----------------------------------------------------------------------------
cmSourceGroup *cmSourceGroup::lookupChild(const char* name)
{
// initializing iterators
std::vector<cmSourceGroup>::iterator iter = m_GroupChildren.begin();
std::vector<cmSourceGroup>::iterator end = m_GroupChildren.end();
// st
for(;iter!=end; ++iter)
{
std::string sgName = iter->GetName();
// look if descenened is the one were looking for
if(sgName == name)
{
return &(*iter); // if it so return it
}
// if the descendend isn't the one where looking for ask it's traverse
cmSourceGroup *result = iter->lookupChild(name);
// if one of it's descendeds is the one we're looking for return it
if(result)
{
return result;
}
}
// if no child with this name was found return NULL
return NULL;
}
cmSourceGroup *cmSourceGroup::MatchChildrenFiles(const char *name)
{
// initializing iterators
std::vector<cmSourceGroup>::iterator iter = m_GroupChildren.begin();
std::vector<cmSourceGroup>::iterator end = m_GroupChildren.end();
if(this->MatchesFiles(name))
{
return this;
}
for(;iter!=end;++iter)
{
cmSourceGroup *result = iter->MatchChildrenFiles(name);
if(result)
{
return result;
}
}
return 0;
}
cmSourceGroup *cmSourceGroup::MatchChildrenRegex(const char *name)
{
// initializing iterators
std::vector<cmSourceGroup>::iterator iter = m_GroupChildren.begin();
std::vector<cmSourceGroup>::iterator end = m_GroupChildren.end();
if(this->MatchesRegex(name))
{
return this;
}
for(;iter!=end; ++iter)
{
cmSourceGroup *result = iter->MatchChildrenRegex(name);
if(result)
{
return result;
}
}
return 0;
}
std::vector<cmSourceGroup> cmSourceGroup::GetGroupChildren() const
{
return m_GroupChildren;
}

View File

@ -48,6 +48,16 @@ public:
*/
void AddGroupFile(const char* name);
/**
* Add child to this sourcegroup
*/
void AddChild(cmSourceGroup child);
/**
* Looks up child and returns it
*/
cmSourceGroup *lookupChild(const char *name);
/**
* Get the name of this group.
*/
@ -63,6 +73,16 @@ public:
*/
bool MatchesFiles(const char* name);
/**
* Check if the given name matches this group's explicit file list in children.
*/
cmSourceGroup *MatchChildrenFiles(const char *name);
/**
* Check if the given name matches this group's regex in children.
*/
cmSourceGroup *MatchChildrenRegex(const char *name);
/**
* Assign the given source file to this group. Used only by
* generators.
@ -76,6 +96,7 @@ public:
const std::vector<const cmSourceFile*>& GetSourceFiles() const;
std::vector<const cmSourceFile*>& GetSourceFiles();
std::vector<cmSourceGroup> GetGroupChildren() const;
private:
/**
* The name of the source group.
@ -97,6 +118,8 @@ private:
* this group.
*/
std::vector<const cmSourceFile*> m_SourceFiles;
std::vector<cmSourceGroup> m_GroupChildren;
};
#endif

View File

@ -16,6 +16,50 @@
=========================================================================*/
#include "cmSourceGroupCommand.h"
inline std::vector<std::string> tokenize(const std::string& str,
const std::string& sep,
bool skipEmptyTokens)
{
std::vector<std::string> tokens;
std::string::size_type tokstart,tokend;
if (skipEmptyTokens)
{
tokend=0;
}
else
{
tokend=std::string::npos;
}
do
{
if (skipEmptyTokens)
{
tokstart=str.find_first_not_of(sep,tokend);
}
else
{
tokstart=tokend+1;
}
if (tokstart==std::string::npos)
{
break; // no more tokens
}
tokend=str.find_first_of(sep,tokstart);
if (tokend==std::string::npos)
{
tokens.push_back(str.substr(tokstart));
}
else
{
tokens.push_back(str.substr(tokstart,tokend-tokstart));
}
} while (tokend!=std::string::npos);
return tokens;
}
// cmSourceGroupCommand
bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args)
{
@ -25,12 +69,26 @@ bool cmSourceGroupCommand::InitialPass(std::vector<std::string> const& args)
return false;
}
// Get the source group with the given name.
cmSourceGroup* sg = m_Makefile->GetSourceGroup(args[0].c_str());
std::string delimiter = "\\";
if(m_Makefile->GetDefinition("SOURCE_GROUP_DELIMITER"))
delimiter = m_Makefile->GetDefinition("SOURCE_GROUP_DELIMITER");
std::vector<std::string> folders = tokenize(args[0], delimiter, true);
const char *parent = NULL;
cmSourceGroup* sg = NULL;
for(unsigned int i=0;i<folders.size();++i)
{
sg = m_Makefile->GetSourceGroup(folders[i].c_str());
if(!sg)
{
m_Makefile->AddSourceGroup(args[0].c_str(), 0);
sg = m_Makefile->GetSourceGroup(args[0].c_str());
m_Makefile->AddSourceGroup(folders[i].c_str(), 0, parent);
}
sg = m_Makefile->GetSourceGroup(folders[i].c_str());
parent = folders[i].c_str();
}
// If only two arguments are given, the pre-1.8 version of the