From 7766473d3eb71937a7fa783fb5a29ae1f6fb6a47 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 19 Oct 2009 10:47:34 -0400 Subject: 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. --- Source/cmGlobalVisualStudio7Generator.cxx | 7 - Source/cmGlobalVisualStudio7Generator.h | 1 - Source/cmGlobalVisualStudio8Generator.cxx | 219 ++++++++++++++---------------- Source/cmGlobalVisualStudio8Generator.h | 2 + 4 files changed, 107 insertions(+), 122 deletions(-) diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index dbe9aed..ea9065e 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -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) { diff --git a/Source/cmGlobalVisualStudio7Generator.h b/Source/cmGlobalVisualStudio7Generator.h index 73302bc..363489e 100644 --- a/Source/cmGlobalVisualStudio7Generator.h +++ b/Source/cmGlobalVisualStudio7Generator.h @@ -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 Configurations; diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 1084fa9..e8b8782 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -110,132 +110,123 @@ 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 no_depends; - std::map >::iterator it; - for(it = this->ProjectMap.begin(); it!= this->ProjectMap.end(); ++it) - { - std::vector& generators = it->second; - if(!generators.empty()) - { - // Add the build-system check target to the first local - // generator of this project. - cmLocalVisualStudio7Generator* lg = - static_cast(generators[0]); - cmMakefile* mf = lg->GetMakefile(); + std::vector const& generators = this->LocalGenerators; + cmLocalVisualStudio7Generator* lg = + static_cast(generators[0]); + cmMakefile* mf = lg->GetMakefile(); - // Skip the target if no regeneration is to be done. - if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION")) - { - continue; - } + // Skip the target if no regeneration is to be done. + if(mf->IsOn("CMAKE_SUPPRESS_REGENERATION")) + { + return; + } - 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; - } + 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 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::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); - } - } + // Create a list of all stamp files for this project. + std::vector 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::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 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::vector::iterator new_end = - std::unique(listFiles.begin(), listFiles.end()); - listFiles.erase(new_end, listFiles.end()); + // 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 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::vector::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); + // 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()); - } - } - } + // 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::const_iterator diff --git a/Source/cmGlobalVisualStudio8Generator.h b/Source/cmGlobalVisualStudio8Generator.h index 4313b58..55e2880 100644 --- a/Source/cmGlobalVisualStudio8Generator.h +++ b/Source/cmGlobalVisualStudio8Generator.h @@ -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); -- cgit v0.12