Avoid duplicate ZERO_CHECK in VS solutions

The commit "Avoid non-root copies of root-only targets" moved the check
for root-only targets into cmGlobalGenerator::GetTargetSets to avoid
adding multiple ALL_BUILD targets to the "original" target set.  This
approach did not work for ZERO_CHECK targets though because those are
pulled in by dependency analysis.

Instead we eliminate duplicate ZERO_CHECK targets altogether and refer
to a single one from all solution files.  This cleans up VS 10 project
file references to ZERO_CHECK targets anyway.
This commit is contained in:
Brad King 2009-10-19 10:47:34 -04:00
parent 180a681b53
commit 7766473d3e
4 changed files with 112 additions and 127 deletions

View File

@ -615,13 +615,6 @@ cmGlobalVisualStudio7Generator
}
}
//----------------------------------------------------------------------------
bool cmGlobalVisualStudio7Generator::IsRootOnlyTarget(cmTarget* target)
{
return (this->cmGlobalVisualStudioGenerator::IsRootOnlyTarget(target) ||
strcmp(target->GetName(), CMAKE_CHECK_BUILD_SYSTEM_TARGET) == 0);
}
bool cmGlobalVisualStudio7Generator::IsPartOfDefaultBuild(const char* project,
cmTarget* target)
{

View File

@ -133,7 +133,6 @@ protected:
std::string ConvertToSolutionPath(const char* path);
virtual bool IsRootOnlyTarget(cmTarget* target);
bool IsPartOfDefaultBuild(const char* project,
cmTarget* target);
std::vector<std::string> Configurations;

View File

@ -110,133 +110,124 @@ std::string cmGlobalVisualStudio8Generator::GetUserMacrosRegKeyBase()
}
//----------------------------------------------------------------------------
void cmGlobalVisualStudio8Generator::Generate()
void cmGlobalVisualStudio8Generator::AddCheckTarget()
{
// Add a special target on which all other targets depend that
// checks the build system and optionally re-runs CMake.
const char* no_working_directory = 0;
std::vector<std::string> no_depends;
std::map<cmStdString, std::vector<cmLocalGenerator*> >::iterator it;
for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it)
std::vector<cmLocalGenerator*> const& generators = this->LocalGenerators;
cmLocalVisualStudio7Generator* lg =
static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
cmMakefile* mf = lg->GetMakefile();
// Skip the target if no regeneration is to be done.
if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION"))
{
std::vector<cmLocalGenerator*>& generators = it->second;
if(!generators.empty())
{
// Add the build-system check target to the first local
// generator of this project.
cmLocalVisualStudio7Generator* lg =
static_cast<cmLocalVisualStudio7Generator*>(generators[0]);
cmMakefile* mf = lg->GetMakefile();
// Skip the target if no regeneration is to be done.
if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION"))
{
continue;
}
std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
cmCustomCommandLines noCommandLines;
mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
no_working_directory, no_depends,
noCommandLines);
cmTarget* tgt = mf->FindTarget(CMAKE_CHECK_BUILD_SYSTEM_TARGET);
if(!tgt)
{
cmSystemTools::Error("Error adding target "
CMAKE_CHECK_BUILD_SYSTEM_TARGET);
continue;
}
// Create a list of all stamp files for this project.
std::vector<std::string> stamps;
std::string stampList = cmake::GetCMakeFilesDirectoryPostSlash();
stampList += "generate.stamp.list";
{
std::string stampListFile =
generators[0]->GetMakefile()->GetCurrentOutputDirectory();
stampListFile += "/";
stampListFile += stampList;
std::string stampFile;
cmGeneratedFileStream fout(stampListFile.c_str());
for(std::vector<cmLocalGenerator*>::const_iterator
gi = generators.begin(); gi != generators.end(); ++gi)
{
stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory();
stampFile += "/";
stampFile += cmake::GetCMakeFilesDirectoryPostSlash();
stampFile += "generate.stamp";
stampFile = generators[0]->Convert(stampFile.c_str(),
cmLocalGenerator::START_OUTPUT);
fout << stampFile << "\n";
stamps.push_back(stampFile);
}
}
// Add a custom rule to re-run CMake if any input files changed.
{
// Collect the input files used to generate all targets in this
// project.
std::vector<std::string> listFiles;
for(unsigned int j = 0; j < generators.size(); ++j)
{
cmMakefile* lmf = generators[j]->GetMakefile();
listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
lmf->GetListFiles().end());
}
// Sort the list of input files and remove duplicates.
std::sort(listFiles.begin(), listFiles.end(),
std::less<std::string>());
std::vector<std::string>::iterator new_end =
std::unique(listFiles.begin(), listFiles.end());
listFiles.erase(new_end, listFiles.end());
// Create a rule to re-run CMake.
std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
stampName += "generate.stamp";
const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND");
cmCustomCommandLine commandLine;
commandLine.push_back(dsprule);
std::string argH = "-H";
argH += lg->Convert(mf->GetHomeDirectory(),
cmLocalGenerator::START_OUTPUT,
cmLocalGenerator::UNCHANGED, true);
commandLine.push_back(argH);
std::string argB = "-B";
argB += lg->Convert(mf->GetHomeOutputDirectory(),
cmLocalGenerator::START_OUTPUT,
cmLocalGenerator::UNCHANGED, true);
commandLine.push_back(argB);
commandLine.push_back("--check-stamp-list");
commandLine.push_back(stampList.c_str());
commandLine.push_back("--vs-solution-file");
commandLine.push_back("\"$(SolutionPath)\"");
cmCustomCommandLines commandLines;
commandLines.push_back(commandLine);
// Add the rule. Note that we cannot use the CMakeLists.txt
// file as the main dependency because it would get
// overwritten by the CreateVCProjBuildRule.
// (this could be avoided with per-target source files)
const char* no_main_dependency = 0;
const char* no_working_directory = 0;
mf->AddCustomCommandToOutput(
stamps, listFiles,
no_main_dependency, commandLines, "Checking Build System",
no_working_directory, true);
std::string ruleName = stamps[0];
ruleName += ".rule";
if(cmSourceFile* file = mf->GetSource(ruleName.c_str()))
{
tgt->AddSourceFile(file);
}
else
{
cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
}
}
}
return;
}
std::string cmake_command = mf->GetRequiredDefinition("CMAKE_COMMAND");
cmCustomCommandLines noCommandLines;
cmTarget* tgt =
mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false,
no_working_directory, no_depends,
noCommandLines);
// Create a list of all stamp files for this project.
std::vector<std::string> stamps;
std::string stampList = cmake::GetCMakeFilesDirectoryPostSlash();
stampList += "generate.stamp.list";
{
std::string stampListFile =
generators[0]->GetMakefile()->GetCurrentOutputDirectory();
stampListFile += "/";
stampListFile += stampList;
std::string stampFile;
cmGeneratedFileStream fout(stampListFile.c_str());
for(std::vector<cmLocalGenerator*>::const_iterator
gi = generators.begin(); gi != generators.end(); ++gi)
{
stampFile = (*gi)->GetMakefile()->GetCurrentOutputDirectory();
stampFile += "/";
stampFile += cmake::GetCMakeFilesDirectoryPostSlash();
stampFile += "generate.stamp";
stampFile = generators[0]->Convert(stampFile.c_str(),
cmLocalGenerator::START_OUTPUT);
fout << stampFile << "\n";
stamps.push_back(stampFile);
}
}
// Add a custom rule to re-run CMake if any input files changed.
{
// Collect the input files used to generate all targets in this
// project.
std::vector<std::string> listFiles;
for(unsigned int j = 0; j < generators.size(); ++j)
{
cmMakefile* lmf = generators[j]->GetMakefile();
listFiles.insert(listFiles.end(), lmf->GetListFiles().begin(),
lmf->GetListFiles().end());
}
// Sort the list of input files and remove duplicates.
std::sort(listFiles.begin(), listFiles.end(),
std::less<std::string>());
std::vector<std::string>::iterator new_end =
std::unique(listFiles.begin(), listFiles.end());
listFiles.erase(new_end, listFiles.end());
// Create a rule to re-run CMake.
std::string stampName = cmake::GetCMakeFilesDirectoryPostSlash();
stampName += "generate.stamp";
const char* dsprule = mf->GetRequiredDefinition("CMAKE_COMMAND");
cmCustomCommandLine commandLine;
commandLine.push_back(dsprule);
std::string argH = "-H";
argH += lg->Convert(mf->GetHomeDirectory(),
cmLocalGenerator::START_OUTPUT,
cmLocalGenerator::UNCHANGED, true);
commandLine.push_back(argH);
std::string argB = "-B";
argB += lg->Convert(mf->GetHomeOutputDirectory(),
cmLocalGenerator::START_OUTPUT,
cmLocalGenerator::UNCHANGED, true);
commandLine.push_back(argB);
commandLine.push_back("--check-stamp-list");
commandLine.push_back(stampList.c_str());
commandLine.push_back("--vs-solution-file");
commandLine.push_back("\"$(SolutionPath)\"");
cmCustomCommandLines commandLines;
commandLines.push_back(commandLine);
// Add the rule. Note that we cannot use the CMakeLists.txt
// file as the main dependency because it would get
// overwritten by the CreateVCProjBuildRule.
// (this could be avoided with per-target source files)
const char* no_main_dependency = 0;
const char* no_working_directory = 0;
mf->AddCustomCommandToOutput(
stamps, listFiles,
no_main_dependency, commandLines, "Checking Build System",
no_working_directory, true);
std::string ruleName = stamps[0];
ruleName += ".rule";
if(cmSourceFile* file = mf->GetSource(ruleName.c_str()))
{
tgt->AddSourceFile(file);
}
else
{
cmSystemTools::Error("Error adding rule for ", stamps[0].c_str());
}
}
}
//----------------------------------------------------------------------------
void cmGlobalVisualStudio8Generator::Generate()
{
this->AddCheckTarget();
// All targets depend on the build-system check target.
for(std::map<cmStdString,cmTarget *>::const_iterator
ti = this->TotalTargets.begin();

View File

@ -63,6 +63,8 @@ protected:
virtual bool VSLinksDependencies() const { return false; }
void AddCheckTarget();
static cmIDEFlagTable const* GetExtraFlagTableVS8();
virtual void AddPlatformDefinitions(cmMakefile* mf);
virtual void WriteSLNHeader(std::ostream& fout);