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 // 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]; std::string project = target->GetName();
const cmCustomCommandLines& cmds = cc.GetCommandLines(); std::string location = expath;
std::string project = cmds[0][0];
std::string location = cmds[0][1];
this->WriteExternalProject(fout, project.c_str(), this->WriteExternalProject(fout, project.c_str(),
location.c_str(), cc.GetDepends()); location.c_str(), target->GetUtilities());
} }
else else
{ {
@ -451,7 +451,7 @@ void cmGlobalVisualStudio6Generator::WriteProject(std::ostream& fout,
void cmGlobalVisualStudio6Generator::WriteExternalProject(std::ostream& fout, void cmGlobalVisualStudio6Generator::WriteExternalProject(std::ostream& fout,
const char* name, const char* name,
const char* location, const char* location,
const std::vector<std::string>& dependencies) const std::set<cmStdString>& dependencies)
{ {
fout << "#########################################################" fout << "#########################################################"
"######################\n\n"; "######################\n\n";
@ -462,7 +462,7 @@ void cmGlobalVisualStudio6Generator::WriteExternalProject(std::ostream& fout,
fout << "{{{\n"; fout << "{{{\n";
std::vector<std::string>::const_iterator i, end; std::set<cmStdString>::const_iterator i, end;
// write dependencies. // write dependencies.
i = dependencies.begin(); i = dependencies.begin();
end = dependencies.end(); end = dependencies.end();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -376,19 +376,6 @@ const char*
cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target, cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target,
const char* name) 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 // Possibly depend on an intermediate utility target to avoid
// linking. // linking.
if(target.GetType() == cmTarget::STATIC_LIBRARY || if(target.GetType() == cmTarget::STATIC_LIBRARY ||

View File

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

View File

@ -30,37 +30,18 @@ bool cmIncludeExternalMSProjectCommand
#ifdef _WIN32 #ifdef _WIN32
if(this->Makefile->GetDefinition("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]; std::string path = args[1];
cmSystemTools::ConvertToUnixSlashes(path); cmSystemTools::ConvertToUnixSlashes(path);
// Create a target instance for this utility. // Create a target instance for this utility.
cmTarget* target=this->Makefile->AddNewTarget(cmTarget::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"); target->SetProperty("EXCLUDE_FROM_ALL","FALSE");
std::vector<std::string> no_outputs; for (unsigned int i=2; i<args.size(); ++i)
cmCustomCommandLines commandLines; {
cmCustomCommandLine commandLine; target->AddUtility(args[i].c_str());
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);
} }
#endif #endif
return true; return true;

View File

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

View File

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

View File

@ -200,7 +200,9 @@ void cmLocalVisualStudio6Generator::OutputDSPFile()
} }
// INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
// so don't build a projectfile for it // 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 // check to see if the dsp is going into a sub-directory
std::string::size_type pos = l->first.rfind('/'); 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 // INCLUDE_EXTERNAL_MSPROJECT command only affects the workspace
// so don't build a projectfile for it // 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); this->CreateSingleVCProj(l->first.c_str(),l->second);
} }
@ -1976,13 +1976,11 @@ void cmLocalVisualStudio7Generator::ConfigureFinalPass()
static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator); static_cast<cmGlobalVisualStudio7Generator *>(this->GlobalGenerator);
for(cmTargets::iterator l = tgts.begin(); l != tgts.end(); l++) 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]; this->ReadAndStoreExternalGUID(
const cmCustomCommandLines& cmds = cc.GetCommandLines(); l->second.GetName(), path);
std::string project_name = cmds[0][0];
this->ReadAndStoreExternalGUID(project_name.c_str(),
cmds[0][1].c_str());
} }
else else
{ {

View File

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

View File

@ -40,4 +40,13 @@ ADD_EXECUTABLE(VSExternalInclude ${SOURCES})
# target depends on lib2 # target depends on lib2
ADD_DEPENDENCIES(VSExternalInclude 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()