summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalVisualStudioGenerator.cxx
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2010-08-24 22:47:56 (GMT)
committerBrad King <brad.king@kitware.com>2010-08-24 22:47:56 (GMT)
commit79a88c35f886258a43ee6169d2d7b4f2e1eb0b95 (patch)
treec44185016a16e3fc10cc4c9dc8e6e874548adfcc /Source/cmGlobalVisualStudioGenerator.cxx
parent325bdb2a92bbbbe18ae2cbffc000bd6e0dd0367a (diff)
downloadCMake-79a88c35f886258a43ee6169d2d7b4f2e1eb0b95.zip
CMake-79a88c35f886258a43ee6169d2d7b4f2e1eb0b95.tar.gz
CMake-79a88c35f886258a43ee6169d2d7b4f2e1eb0b95.tar.bz2
Refactor VS <= 7.1 utility-depends workaround
Commit 438a7e2f (Fix utility dependencies for static libraries in VS generators, 2007-04-04) implemented utility-only dependencies between linkable targets by introducing an intermediate non-linkable target. We convert a dependency of the form foo -> bar to the form foo -> bar_UTILITY -> bar to prevent foo from including bar on its link line. Previously we added the extra "_UTILITY" targets explicitly among the project targets before dependency analysis was performed. Now we generate them separately at the last moment so that cmGlobalGenerator need not be aware of them.
Diffstat (limited to 'Source/cmGlobalVisualStudioGenerator.cxx')
-rw-r--r--Source/cmGlobalVisualStudioGenerator.cxx191
1 files changed, 27 insertions, 164 deletions
diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx
index 1007953..3493b1d 100644
--- a/Source/cmGlobalVisualStudioGenerator.cxx
+++ b/Source/cmGlobalVisualStudioGenerator.cxx
@@ -74,9 +74,6 @@ void cmGlobalVisualStudioGenerator::Generate()
}
}
- // Fix utility dependencies to avoid linking to libraries.
- this->FixUtilityDepends();
-
// Configure CMake Visual Studio macros, for this user on this version
// of Visual Studio.
this->ConfigureCMakeVisualStudioMacros();
@@ -225,134 +222,6 @@ std::string cmGlobalVisualStudioGenerator::GetUserMacrosRegKeyBase()
}
//----------------------------------------------------------------------------
-void cmGlobalVisualStudioGenerator::FixUtilityDepends()
-{
- // Skip for VS versions 8 and above.
- if(!this->VSLinksDependencies())
- {
- return;
- }
-
- // For VS versions before 8:
- //
- // When a target that links contains a project-level dependency on a
- // library target that library is automatically linked. In order to
- // allow utility-style project-level dependencies that do not
- // actually link we need to automatically insert an intermediate
- // custom target.
- //
- // Here we edit the utility dependencies of a target to add the
- // intermediate custom target when necessary.
- for(unsigned i = 0; i < this->LocalGenerators.size(); ++i)
- {
- cmTargets* targets =
- &(this->LocalGenerators[i]->GetMakefile()->GetTargets());
- for(cmTargets::iterator tarIt = targets->begin();
- tarIt != targets->end(); ++tarIt)
- {
- this->FixUtilityDependsForTarget(tarIt->second);
- }
- }
-}
-
-//----------------------------------------------------------------------------
-void
-cmGlobalVisualStudioGenerator::FixUtilityDependsForTarget(cmTarget& target)
-{
- // Only targets that link need to be fixed.
- if(target.GetType() != cmTarget::STATIC_LIBRARY &&
- target.GetType() != cmTarget::SHARED_LIBRARY &&
- target.GetType() != cmTarget::MODULE_LIBRARY &&
- target.GetType() != cmTarget::EXECUTABLE)
- {
- return;
- }
-
-#if 0
- // This feature makes a mess in SLN files for VS 7.1 and below. It
- // creates an extra target for every target that is "linked" by a
- // static library. Without this feature static libraries do not
- // wait until their "link" dependencies are built to build. This is
- // not a problem 99.9% of the time, and projects that do have the
- // problem can enable this work-around by using add_dependencies.
-
- // Static libraries cannot depend directly on the targets to which
- // they link because VS will copy those targets into the library
- // (for VS < 8). To work around the problem we copy the
- // dependencies to be utility dependencies so that the work-around
- // below is used.
- if(target.GetType() == cmTarget::STATIC_LIBRARY)
- {
- cmTarget::LinkLibraryVectorType const& libs = target.GetLinkLibraries();
- for(cmTarget::LinkLibraryVectorType::const_iterator i = libs.begin();
- i != libs.end(); ++i)
- {
- if(cmTarget* depTarget = this->FindTarget(0, i->first.c_str(), false))
- {
- target.AddUtility(depTarget->GetName());
- }
- }
- }
-#endif
-
- // Look at each utility dependency.
- for(std::set<cmStdString>::const_iterator ui =
- target.GetUtilities().begin();
- ui != target.GetUtilities().end(); ++ui)
- {
- if(cmTarget* depTarget = this->FindTarget(0, ui->c_str()))
- {
- if(depTarget->GetType() == cmTarget::STATIC_LIBRARY ||
- depTarget->GetType() == cmTarget::SHARED_LIBRARY ||
- depTarget->GetType() == cmTarget::MODULE_LIBRARY)
- {
- // This utility dependency will cause an attempt to link. If
- // the depender does not already link the dependee we need an
- // intermediate target.
- if(!this->CheckTargetLinks(target, ui->c_str()))
- {
- this->CreateUtilityDependTarget(*depTarget);
- }
- }
- }
- }
-}
-
-//----------------------------------------------------------------------------
-void
-cmGlobalVisualStudioGenerator::CreateUtilityDependTarget(cmTarget& target)
-{
- // This target is a library on which a utility dependency exists.
- // We need to create an intermediate custom target to hook up the
- // dependency without causing a link.
- const char* altName = target.GetProperty("ALTERNATIVE_DEPENDENCY_NAME");
- if(!altName)
- {
- // Create the intermediate utility target.
- std::string altNameStr = target.GetName();
- altNameStr += "_UTILITY";
- const std::vector<std::string> no_depends;
- cmCustomCommandLines no_commands;
- const char* no_working_dir = 0;
- const char* no_comment = 0;
- target.GetMakefile()->AddUtilityCommand(altNameStr.c_str(), true,
- no_working_dir, no_depends,
- no_commands, false, no_comment);
- target.SetProperty("ALTERNATIVE_DEPENDENCY_NAME", altNameStr.c_str());
-
- // Most targets have a GUID created in ConfigureFinalPass. Since
- // that has already been called, create one for this target now.
- this->CreateGUID(altNameStr.c_str());
-
- // The intermediate target should depend on the original target.
- if(cmTarget* alt = this->FindTarget(0, altNameStr.c_str()))
- {
- alt->AddUtility(target.GetName());
- }
- }
-}
-
-//----------------------------------------------------------------------------
bool cmGlobalVisualStudioGenerator::ComputeTargetDepends()
{
if(!this->cmGlobalGenerator::ComputeTargetDepends())
@@ -433,10 +302,28 @@ bool cmGlobalVisualStudioGenerator::CheckTargetLinks(cmTarget& target,
}
//----------------------------------------------------------------------------
-const char*
+std::string cmGlobalVisualStudioGenerator::GetUtilityDepend(cmTarget* target)
+{
+ UtilityDependsMap::iterator i = this->UtilityDepends.find(target);
+ if(i == this->UtilityDepends.end())
+ {
+ std::string name = this->WriteUtilityDepend(target);
+ UtilityDependsMap::value_type entry(target, name);
+ i = this->UtilityDepends.insert(entry).first;
+ }
+ return i->second;
+}
+
+//----------------------------------------------------------------------------
+std::string
cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target,
const char* name)
{
+ if(!this->VSLinksDependencies())
+ {
+ return name;
+ }
+
// Possibly depend on an intermediate utility target to avoid
// linking.
if(target.GetType() == cmTarget::STATIC_LIBRARY ||
@@ -444,19 +331,19 @@ cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target,
target.GetType() == cmTarget::MODULE_LIBRARY ||
target.GetType() == cmTarget::EXECUTABLE)
{
- // The depender is a target that links. Lookup the dependee to
- // see if it provides an alternative dependency name.
+ // The depender is a target that links.
if(cmTarget* depTarget = this->FindTarget(0, name))
{
- // Check for an alternative name created by FixUtilityDepends.
- if(const char* altName =
- depTarget->GetProperty("ALTERNATIVE_DEPENDENCY_NAME"))
+ if(depTarget->GetType() == cmTarget::STATIC_LIBRARY ||
+ depTarget->GetType() == cmTarget::SHARED_LIBRARY ||
+ depTarget->GetType() == cmTarget::MODULE_LIBRARY)
{
- // The alternative name is needed only if the depender does
- // not really link to the dependee.
+ // This utility dependency will cause an attempt to link. If
+ // the depender does not already link the dependee we need an
+ // intermediate target.
if(!this->CheckTargetLinks(target, name))
{
- return altName;
+ return this->GetUtilityDepend(depTarget);
}
}
}
@@ -467,30 +354,6 @@ cmGlobalVisualStudioGenerator::GetUtilityForTarget(cmTarget& target,
}
//----------------------------------------------------------------------------
-void cmGlobalVisualStudioGenerator::GetTargetSets(
- TargetDependSet& projectTargets, TargetDependSet& originalTargets,
- cmLocalGenerator* root, GeneratorVector const& generators
- )
-{
- this->cmGlobalGenerator::GetTargetSets(projectTargets, originalTargets,
- root, generators);
-
- // Add alternative dependency targets created by FixUtilityDepends.
- for(TargetDependSet::iterator ti = projectTargets.begin();
- ti != projectTargets.end(); ++ti)
- {
- cmTarget* tgt = *ti;
- if(const char* altName = tgt->GetProperty("ALTERNATIVE_DEPENDENCY_NAME"))
- {
- if(cmTarget* alt = tgt->GetMakefile()->FindTarget(altName))
- {
- projectTargets.insert(alt);
- }
- }
- }
-}
-
-//----------------------------------------------------------------------------
#include <windows.h>
//----------------------------------------------------------------------------