ENH: remove INCLUDE_EXTERNAL_MSPROJECT name hack, and use target properties instead, fix VXExternalInclude test for VS10

This commit is contained in:
Bill Hoffman 2009-07-14 14:16:46 -04:00
parent b23b1800a5
commit 3d1c12b802
15 changed files with 78 additions and 140 deletions

View File

@ -247,14 +247,14 @@ void cmGlobalVisualStudio6Generator
}
}
// Write the project into the DSW file
if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
cmTarget* target = &l->second;
const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
if(expath)
{
cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
const cmCustomCommandLines& cmds = cc.GetCommandLines();
std::string project = cmds[0][0];
std::string location = cmds[0][1];
std::string project = target->GetName();
std::string location = expath;
this->WriteExternalProject(fout, project.c_str(),
location.c_str(), cc.GetDepends());
location.c_str(), target->GetUtilities());
}
else
{
@ -451,7 +451,7 @@ void cmGlobalVisualStudio6Generator::WriteProject(std::ostream& fout,
void cmGlobalVisualStudio6Generator::WriteExternalProject(std::ostream& fout,
const char* name,
const char* location,
const std::vector<std::string>& dependencies)
const std::set<cmStdString>& dependencies)
{
fout << "#########################################################"
"######################\n\n";
@ -462,7 +462,7 @@ void cmGlobalVisualStudio6Generator::WriteExternalProject(std::ostream& fout,
fout << "{{{\n";
std::vector<std::string>::const_iterator i, end;
std::set<cmStdString>::const_iterator i, end;
// write dependencies.
i = dependencies.begin();
end = dependencies.end();

View File

@ -96,7 +96,7 @@ private:
const char* name, const char* path, cmTarget &t);
void WriteExternalProject(std::ostream& fout,
const char* name, const char* path,
const std::vector<std::string>& dependencies);
const std::set<cmStdString>& dependencies);
void WriteDSWFooter(std::ostream& fout);
};

View File

@ -254,7 +254,7 @@ void cmGlobalVisualStudio71Generator
::WriteExternalProject(std::ostream& fout,
const char* name,
const char* location,
const std::vector<std::string>& depends)
const std::set<cmStdString>& depends)
{
fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""
<< name << "\", \""
@ -267,7 +267,7 @@ void cmGlobalVisualStudio71Generator
if(!depends.empty())
{
fout << "\tProjectSection(ProjectDependencies) = postProject\n";
std::vector<std::string>::const_iterator it;
std::set<cmStdString>::const_iterator it;
for(it = depends.begin(); it != depends.end(); ++it)
{
if(it->size() > 0)

View File

@ -72,7 +72,7 @@ protected:
virtual void WriteExternalProject(std::ostream& fout,
const char* name,
const char* path,
const std::vector<std::string>& depends);
const std::set<cmStdString>& depends);
virtual void WriteSLNFooter(std::ostream& fout);
virtual void WriteSLNHeader(std::ostream& fout);

View File

@ -250,12 +250,10 @@ void cmGlobalVisualStudio7Generator::WriteTargetConfigurations(
projectTargets.begin(); tt != projectTargets.end(); ++tt)
{
cmTarget* target = *tt;
if (strncmp(target->GetName(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
if(expath)
{
cmCustomCommand cc = target->GetPostBuildCommands()[0];
const cmCustomCommandLines& cmds = cc.GetCommandLines();
std::string project = cmds[0][0];
this->WriteProjectConfigurations(fout, project.c_str(),
this->WriteProjectConfigurations(fout, target->GetName(),
true);
}
else
@ -286,14 +284,13 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution(
{
cmTarget* target = *tt;
// handle external vc project files
if (strncmp(target->GetName(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
{
cmCustomCommand cc = target->GetPostBuildCommands()[0];
const cmCustomCommandLines& cmds = cc.GetCommandLines();
std::string project = cmds[0][0];
std::string location = cmds[0][1];
const char* expath = target->GetProperty("EXTERNAL_MSPROJECT");
if(expath)
{
std::string project = target->GetName();
std::string location = expath;
this->WriteExternalProject(fout, project.c_str(),
location.c_str(), cc.GetDepends());
location.c_str(), target->GetUtilities());
}
else
{
@ -340,45 +337,18 @@ void cmGlobalVisualStudio7Generator::WriteTargetDepends(
projectTargets.begin(); tt != projectTargets.end(); ++tt)
{
cmTarget* target = *tt;
cmMakefile* mf = target->GetMakefile();
if (strncmp(target->GetName(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
{
cmCustomCommand cc = target->GetPostBuildCommands()[0];
const cmCustomCommandLines& cmds = cc.GetCommandLines();
std::string name = cmds[0][0];
std::vector<std::string> depends = cc.GetDepends();
std::vector<std::string>::iterator iter;
int depcount = 0;
for(iter = depends.begin(); iter != depends.end(); ++iter)
{
std::string guid = this->GetGUID(iter->c_str());
if(guid.size() == 0)
{
std::string m = "Target: ";
m += target->GetName();
m += " depends on unknown target: ";
m += iter->c_str();
cmSystemTools::Error(m.c_str());
}
fout << "\t\t{" << this->GetGUID(name.c_str())
<< "}." << depcount << " = {" << guid.c_str() << "}\n";
depcount++;
}
}
else
{
const char *vcprojName =
target->GetProperty("GENERATOR_FILE_NAME");
if (vcprojName)
{
std::string dir = mf->GetStartDirectory();
this->WriteProjectDepends(fout, vcprojName,
dir.c_str(), *target);
}
cmMakefile* mf = target->GetMakefile();
const char *vcprojName =
target->GetProperty("GENERATOR_FILE_NAME");
if (vcprojName)
{
std::string dir = mf->GetStartDirectory();
this->WriteProjectDepends(fout, vcprojName,
dir.c_str(), *target);
}
}
}
// Write a SLN file to the stream
void cmGlobalVisualStudio7Generator
::WriteSLNFile(std::ostream& fout,
@ -562,7 +532,7 @@ void cmGlobalVisualStudio7Generator
void cmGlobalVisualStudio7Generator::WriteExternalProject(std::ostream& fout,
const char* name,
const char* location,
const std::vector<std::string>&)
const std::set<cmStdString>&)
{
std::string d = cmSystemTools::ConvertToOutputPath(location);
fout << "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \""

View File

@ -142,7 +142,7 @@ protected:
virtual void WriteExternalProject(std::ostream& fout,
const char* name,
const char* path,
const std::vector<std::string>&
const std::set<cmStdString>&
dependencies);
std::string ConvertToSolutionPath(const char* path);

View File

@ -376,19 +376,6 @@ const char*
cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target,
const char* name)
{
// Handle the external MS project special case.
if(strncmp(name, "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
{
// Note from Ken:
// kind of weird removing the first 27 letters. my
// recommendatsions: use cmCustomCommand::GetCommand() to get the
// project name or get rid of the target name starting with
// "INCLUDE_EXTERNAL_MSPROJECT_" and use another indicator/flag
// somewhere. These external project names shouldn't conflict
// with cmake target names anyways.
return name+27;
}
// Possibly depend on an intermediate utility target to avoid
// linking.
if(target.GetType() == cmTarget::STATIC_LIBRARY ||

View File

@ -66,11 +66,11 @@ public:
// return true if target is fortran only
bool TargetIsFortranOnly(cmTarget& t);
const char* GetUtilityForTarget(cmTarget& target, const char*);
protected:
virtual void CreateGUID(const char*) {}
void FixUtilityDepends();
const char* GetUtilityForTarget(cmTarget& target, const char*);
// Does this VS version link targets to each other if there are
// dependencies in the SLN file? This was done for VS versions

View File

@ -30,37 +30,18 @@ bool cmIncludeExternalMSProjectCommand
#ifdef _WIN32
if(this->Makefile->GetDefinition("WIN32"))
{
std::string location = args[1];
std::vector<std::string> depends;
if (args.size() > 2)
{
for (unsigned int i=2; i<args.size(); ++i)
{
depends.push_back(args[i]);
}
}
// Hack together a utility target storing enough information
// to reproduce the target inclusion.
std::string utility_name("INCLUDE_EXTERNAL_MSPROJECT");
utility_name += "_";
utility_name += args[0];
std::string path = args[1];
cmSystemTools::ConvertToUnixSlashes(path);
// Create a target instance for this utility.
cmTarget* target=this->Makefile->AddNewTarget(cmTarget::UTILITY,
utility_name.c_str());
args[0].c_str());
target->SetProperty("EXTERNAL_MSPROJECT", path.c_str());
target->SetProperty("EXCLUDE_FROM_ALL","FALSE");
std::vector<std::string> no_outputs;
cmCustomCommandLines commandLines;
cmCustomCommandLine commandLine;
commandLine.push_back(args[0]);
commandLine.push_back(path);
commandLines.push_back(commandLine);
cmCustomCommand cc(no_outputs, depends, commandLines, 0, 0);
target->GetPostBuildCommands().push_back(cc);
for (unsigned int i=2; i<args.size(); ++i)
{
target->AddUtility(args[i].c_str());
}
}
#endif
return true;

View File

@ -193,17 +193,12 @@ void cmLocalGenerator::TraceDependencies()
cmTargets& targets = this->Makefile->GetTargets();
for(cmTargets::iterator t = targets.begin(); t != targets.end(); ++t)
{
// INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
// so don't build a projectfile for it
if (strncmp(t->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
const char* projectFilename = 0;
if (this->IsMakefileGenerator == false) // only use of this variable
{
const char* projectFilename = 0;
if (this->IsMakefileGenerator == false) // only use of this variable
{
projectFilename = t->second.GetName();
}
t->second.TraceDependencies(projectFilename);
projectFilename = t->second.GetName();
}
t->second.TraceDependencies(projectFilename);
}
}

View File

@ -31,7 +31,7 @@ class cmVS10XMLParser : public cmXMLParser
{
if(this->DoGUID )
{
this->GUID.assign(data, length);
this->GUID.assign(data+1, length-2);
this->DoGUID = false;
}
}
@ -112,7 +112,6 @@ void cmLocalVisualStudio10Generator
::ReadAndStoreExternalGUID(const char* name,
const char* path)
{
cmVS10XMLParser parser;
parser.ParseFile(path);
std::string guidStoreName = name;

View File

@ -200,7 +200,9 @@ void cmLocalVisualStudio6Generator::OutputDSPFile()
}
// INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
// so don't build a projectfile for it
if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
const char* path =
l->second.GetProperty("EXTERNAL_MSPROJECT");
if(!path)
{
// check to see if the dsp is going into a sub-directory
std::string::size_type pos = l->first.rfind('/');

View File

@ -159,7 +159,7 @@ void cmLocalVisualStudio7Generator::WriteProjectFiles()
{
// INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
// so don't build a projectfile for it
if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) != 0)
if(!l->second.GetProperty("EXTERNAL_MSPROJECT"))
{
this->CreateSingleVCProj(l->first.c_str(),l->second);
}
@ -1976,13 +1976,11 @@ void cmLocalVisualStudio7Generator::ConfigureFinalPass()
static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++)
{
if (strncmp(l->first.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
const char* path = l->second.GetProperty("EXTERNAL_MSPROJECT");
if(path)
{
cmCustomCommand cc = l->second.GetPostBuildCommands()[0];
const cmCustomCommandLines& cmds = cc.GetCommandLines();
std::string project_name = cmds[0][0];
this->ReadAndStoreExternalGUID(project_name.c_str(),
cmds[0][1].c_str());
this->ReadAndStoreExternalGUID(
l->second.GetName(), path);
}
else
{

View File

@ -38,20 +38,9 @@ cmVisualStudio10TargetGenerator(cmTarget* target,
this->LocalGenerator =
(cmLocalVisualStudio7Generator*)
this->Makefile->GetLocalGenerator();
const char* name = this->Target->GetName();
if (strncmp(name, "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
{
cmCustomCommand cc = this->Target->GetPostBuildCommands()[0];
const cmCustomCommandLines& cmds = cc.GetCommandLines();
this->Name = cmds[0][0];
this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
}
else
{
this->Name = name;
this->GlobalGenerator->CreateGUID(this->Name.c_str());
this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
}
this->Name = this->Target->GetName();
this->GlobalGenerator->CreateGUID(this->Name.c_str());
this->GUID = this->GlobalGenerator->GetGUID(this->Name.c_str());
this->Platform = "|Win32";
this->ComputeObjectNames();
this->BuildFileStream = 0;
@ -114,7 +103,12 @@ void cmVisualStudio10TargetGenerator::WriteString(const char* line,
void cmVisualStudio10TargetGenerator::Generate()
{
{
// do not generate external ms projects
if(this->Target->GetProperty("EXTERNAL_MSPROJECT"))
{
return;
}
// Tell the global generator the name of the project file
this->Target->SetProperty("GENERATOR_FILE_NAME",this->Name.c_str());
this->Target->SetProperty("GENERATOR_FILE_NAME_EXT",
@ -1227,6 +1221,11 @@ void cmVisualStudio10TargetGenerator::WriteEvent(
void cmVisualStudio10TargetGenerator::WriteProjectReferences()
{
// for static libs do not list references
if (this->Target->GetType() == cmTarget::STATIC_LIBRARY)
{
return;
}
cmGlobalGenerator::TargetDependSet& depends
= this->GlobalGenerator->GetTargetDirectDepends(*this->Target);
this->WriteString("<ItemGroup>\n", 1);
@ -1238,12 +1237,10 @@ void cmVisualStudio10TargetGenerator::WriteProjectReferences()
cmMakefile* mf = dt->GetMakefile();
std::string name = dt->GetName();
std::string path;
if (strncmp(name.c_str(), "INCLUDE_EXTERNAL_MSPROJECT", 26) == 0)
const char* p = dt->GetProperty("EXTERNAL_MSPROJECT");
if(p)
{
cmCustomCommand cc = dt->GetPostBuildCommands()[0];
const cmCustomCommandLines& cmds = cc.GetCommandLines();
path = cmds[0][1];
name = cmds[0][0].c_str();
path = p;
}
else
{

View File

@ -40,4 +40,13 @@ ADD_EXECUTABLE(VSExternalInclude ${SOURCES})
# target depends on lib2
ADD_DEPENDENCIES(VSExternalInclude lib2)
# VS 10 vcxproj files have depends in them
# Since lib1 and lib2 do not depend on each other
# then the vcxproj files do not depend on each other
# and the sln file can no longer be the only source
# of that depend. So, for VS 10 make the executable
# depend on lib1 and lib2
IF(MSVC10)
ADD_DEPENDENCIES(VSExternalInclude lib1)
ENDIF()