From d67584ccc4262c103a180504cb294e3ad6b6910d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Aug 2015 19:35:45 +0200 Subject: [PATCH 01/22] cmTarget: Move link interface libraries struct out. --- Source/cmComputeLinkDepends.cxx | 8 +++--- Source/cmComputeLinkDepends.h | 2 +- Source/cmComputeTargetDepends.cxx | 2 +- Source/cmExportFileGenerator.cxx | 4 +-- Source/cmGeneratorExpressionNode.cxx | 2 +- Source/cmGeneratorTarget.cxx | 4 +-- Source/cmLinkItem.h | 40 ++++++++++++++++++++++++++++ Source/cmTarget.cxx | 36 ++++++++----------------- Source/cmTarget.h | 34 +++-------------------- 9 files changed, 65 insertions(+), 67 deletions(-) diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 59590fd16..03ec8200d 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -361,7 +361,7 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry const& qe) if(entry.Target) { // Follow the target dependencies. - if(cmTarget::LinkInterface const* iface = + if(cmLinkInterface const* iface = entry.Target->GetLinkInterface(this->Config, this->Target->Target)) { const bool isIface = @@ -396,7 +396,7 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry const& qe) //---------------------------------------------------------------------------- void cmComputeLinkDepends -::FollowSharedDeps(int depender_index, cmTarget::LinkInterface const* iface, +::FollowSharedDeps(int depender_index, cmLinkInterface const* iface, bool follow_interface) { // Follow dependencies if we have not followed them already. @@ -459,7 +459,7 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep) // Target items may have their own dependencies. if(entry.Target) { - if(cmTarget::LinkInterface const* iface = + if(cmLinkInterface const* iface = entry.Target->GetLinkInterface(this->Config, this->Target->Target)) { // Follow public and private dependencies transitively. @@ -930,7 +930,7 @@ int cmComputeLinkDepends::ComputeComponentCount(NodeList const& nl) { if(cmTarget const* target = this->EntryList[*ni].Target) { - if(cmTarget::LinkInterface const* iface = + if(cmLinkInterface const* iface = target->GetLinkInterface(this->Config, this->Target->Target)) { if(iface->Multiplicity > count) diff --git a/Source/cmComputeLinkDepends.h b/Source/cmComputeLinkDepends.h index b925a4fbe..2cbb43013 100644 --- a/Source/cmComputeLinkDepends.h +++ b/Source/cmComputeLinkDepends.h @@ -102,7 +102,7 @@ private: std::queue SharedDepQueue; std::set SharedDepFollowed; void FollowSharedDeps(int depender_index, - cmTarget::LinkInterface const* iface, + cmLinkInterface const* iface, bool follow_interface = false); void QueueSharedDependencies(int depender_index, std::vector const& deps); diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index c4a03a08d..aeb918441 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -296,7 +296,7 @@ void cmComputeTargetDepends::AddInterfaceDepends(int depender_index, std::set &emitted) { cmGeneratorTarget const* depender = this->Targets[depender_index]; - if(cmTarget::LinkInterface const* iface = + if(cmLinkInterface const* iface = dependee->Target->GetLinkInterface(config, depender->Target)) { diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index cae60b7e3..d559a0748 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -796,7 +796,7 @@ cmExportFileGenerator std::vector& missingTargets) { // Add the transitive link dependencies for this configuration. - cmTarget::LinkInterface const* iface = target->Target->GetLinkInterface( + cmLinkInterface const* iface = target->Target->GetLinkInterface( config, target->Target); if (!iface) @@ -909,7 +909,7 @@ cmExportFileGenerator } // Add the transitive link dependencies for this configuration. - if(cmTarget::LinkInterface const* iface = + if(cmLinkInterface const* iface = target->Target ->GetLinkInterface(config, target->Target)) { diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 03bc83ac5..9509c2b6e 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -1108,7 +1108,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode if(isInterfaceProperty) { - if(cmTarget::LinkInterfaceLibraries const* iface = + if(cmLinkInterfaceLibraries const* iface = target->GetLinkInterfaceLibraries(context->Config, headTarget, true)) { linkedTargetsContent = diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index dd58e7bee..06a4c6a0f 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1173,7 +1173,7 @@ public: return; } - cmTarget::LinkInterface const* iface = + cmLinkInterface const* iface = item.Target->GetLinkInterface(this->Config, this->HeadTarget); if(!iface) { return; } @@ -1511,7 +1511,7 @@ void processILibs(const std::string& config, if (item.Target && emitted.insert(item.Target).second) { tgts.push_back(item.Target); - if(cmTarget::LinkInterfaceLibraries const* iface = + if(cmLinkInterfaceLibraries const* iface = item.Target->GetLinkInterfaceLibraries(config, headTarget, true)) { for(std::vector::const_iterator diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h index a5427de49..eb585abf9 100644 --- a/Source/cmLinkItem.h +++ b/Source/cmLinkItem.h @@ -56,4 +56,44 @@ struct cmLinkImplementationLibraries std::vector WrongConfigLibraries; }; +struct cmLinkInterfaceLibraries +{ + // Libraries listed in the interface. + std::vector Libraries; +}; + +struct cmLinkInterface: public cmLinkInterfaceLibraries +{ + // Languages whose runtime libraries must be linked. + std::vector Languages; + + // Shared library dependencies needed for linking on some platforms. + std::vector SharedDeps; + + // Number of repetitions of a strongly connected component of two + // or more static libraries. + int Multiplicity; + + // Libraries listed for other configurations. + // Needed only for OLD behavior of CMP0003. + std::vector WrongConfigLibraries; + + bool ImplementationIsInterface; + + cmLinkInterface(): Multiplicity(0), ImplementationIsInterface(false) {} +}; + +struct cmOptionalLinkInterface: public cmLinkInterface +{ + cmOptionalLinkInterface(): + LibrariesDone(false), AllDone(false), + Exists(false), HadHeadSensitiveCondition(false), + ExplicitLibraries(0) {} + bool LibrariesDone; + bool AllDone; + bool Exists; + bool HadHeadSensitiveCondition; + const char* ExplicitLibraries; +}; + #endif diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 49b32399a..974aff5c1 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -91,31 +91,18 @@ public: // The backtrace when the target was created. cmListFileBacktrace Backtrace; - // Cache link interface computation from each configuration. - struct OptionalLinkInterface: public cmTarget::LinkInterface - { - OptionalLinkInterface(): - LibrariesDone(false), AllDone(false), - Exists(false), HadHeadSensitiveCondition(false), - ExplicitLibraries(0) {} - bool LibrariesDone; - bool AllDone; - bool Exists; - bool HadHeadSensitiveCondition; - const char* ExplicitLibraries; - }; void ComputeLinkInterface(cmTarget const* thisTarget, const std::string& config, - OptionalLinkInterface& iface, + cmOptionalLinkInterface& iface, cmTarget const* head) const; void ComputeLinkInterfaceLibraries(cmTarget const* thisTarget, const std::string& config, - OptionalLinkInterface& iface, + cmOptionalLinkInterface &iface, cmTarget const* head, bool usage_requirements_only); struct HeadToLinkInterfaceMap: - public std::map {}; + public std::map {}; typedef std::map LinkInterfaceMapType; LinkInterfaceMapType LinkInterfaceMap; @@ -4133,8 +4120,7 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, } //---------------------------------------------------------------------------- -cmTarget::LinkInterface const* cmTarget::GetLinkInterface( - const std::string& config, +cmLinkInterface const* cmTarget::GetLinkInterface(const std::string& config, cmTarget const* head) const { // Imported targets have their own link interface. @@ -4163,7 +4149,7 @@ cmTarget::LinkInterface const* cmTarget::GetLinkInterface( return &hm.begin()->second; } - cmTargetInternals::OptionalLinkInterface& iface = hm[head]; + cmOptionalLinkInterface& iface = hm[head]; if(!iface.LibrariesDone) { iface.LibrariesDone = true; @@ -4183,7 +4169,7 @@ cmTarget::LinkInterface const* cmTarget::GetLinkInterface( } //---------------------------------------------------------------------------- -cmTarget::LinkInterfaceLibraries const* +const cmLinkInterfaceLibraries * cmTarget::GetLinkInterfaceLibraries(const std::string& config, cmTarget const* head, bool usage_requirements_only) const @@ -4216,7 +4202,7 @@ cmTarget::GetLinkInterfaceLibraries(const std::string& config, return &hm.begin()->second; } - cmTargetInternals::OptionalLinkInterface& iface = hm[head]; + cmOptionalLinkInterface& iface = hm[head]; if(!iface.LibrariesDone) { iface.LibrariesDone = true; @@ -4228,7 +4214,7 @@ cmTarget::GetLinkInterfaceLibraries(const std::string& config, } //---------------------------------------------------------------------------- -cmTarget::LinkInterface const* +const cmLinkInterface * cmTarget::GetImportLinkInterface(const std::string& config, cmTarget const* headTarget, bool usage_requirements_only) const @@ -4252,7 +4238,7 @@ cmTarget::GetImportLinkInterface(const std::string& config, return &hm.begin()->second; } - cmTargetInternals::OptionalLinkInterface& iface = hm[headTarget]; + cmOptionalLinkInterface& iface = hm[headTarget]; if(!iface.AllDone) { iface.AllDone = true; @@ -4275,7 +4261,7 @@ void cmTargetInternals::ComputeLinkInterfaceLibraries( cmTarget const* thisTarget, const std::string& config, - OptionalLinkInterface& iface, + cmOptionalLinkInterface& iface, cmTarget const* headTarget, bool usage_requirements_only) { @@ -4423,7 +4409,7 @@ cmTargetInternals::ComputeLinkInterfaceLibraries( //---------------------------------------------------------------------------- void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget, const std::string& config, - OptionalLinkInterface& iface, + cmOptionalLinkInterface &iface, cmTarget const* headTarget) const { if(iface.ExplicitLibraries) diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 2007b4096..8594e05e0 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -233,39 +233,11 @@ public: void GetObjectLibrariesCMP0026(std::vector& objlibs) const; - /** The link interface specifies transitive library dependencies and - other information needed by targets that link to this target. */ - struct LinkInterfaceLibraries - { - // Libraries listed in the interface. - std::vector Libraries; - }; - struct LinkInterface: public LinkInterfaceLibraries - { - // Languages whose runtime libraries must be linked. - std::vector Languages; - - // Shared library dependencies needed for linking on some platforms. - std::vector SharedDeps; - - // Number of repetitions of a strongly connected component of two - // or more static libraries. - int Multiplicity; - - // Libraries listed for other configurations. - // Needed only for OLD behavior of CMP0003. - std::vector WrongConfigLibraries; - - bool ImplementationIsInterface; - - LinkInterface(): Multiplicity(0), ImplementationIsInterface(false) {} - }; - /** Get the link interface for the given configuration. Returns 0 if the target cannot be linked. */ - LinkInterface const* GetLinkInterface(const std::string& config, + cmLinkInterface const* GetLinkInterface(const std::string& config, cmTarget const* headTarget) const; - LinkInterfaceLibraries const* + cmLinkInterfaceLibraries const* GetLinkInterfaceLibraries(const std::string& config, cmTarget const* headTarget, bool usage_requirements_only) const; @@ -592,7 +564,7 @@ private: ImportInfo& info) const; - LinkInterface const* + cmLinkInterface const* GetImportLinkInterface(const std::string& config, cmTarget const* head, bool usage_requirements_only) const; From f8ca51a054732d5b0e2c6052ee102b748bd5848c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Aug 2015 19:36:13 +0200 Subject: [PATCH 02/22] cmGeneratorTarget: Move ComputeLinkInterface from cmTarget. --- Source/cmTarget.cxx | 110 ++++++++++++++++++++------------------------ Source/cmTarget.h | 8 ++++ 2 files changed, 57 insertions(+), 61 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 974aff5c1..60453e141 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -91,16 +91,6 @@ public: // The backtrace when the target was created. cmListFileBacktrace Backtrace; - void ComputeLinkInterface(cmTarget const* thisTarget, - const std::string& config, - cmOptionalLinkInterface& iface, - cmTarget const* head) const; - void ComputeLinkInterfaceLibraries(cmTarget const* thisTarget, - const std::string& config, - cmOptionalLinkInterface &iface, - cmTarget const* head, - bool usage_requirements_only); - struct HeadToLinkInterfaceMap: public std::map {}; typedef std::map @@ -4153,15 +4143,15 @@ cmLinkInterface const* cmTarget::GetLinkInterface(const std::string& config, if(!iface.LibrariesDone) { iface.LibrariesDone = true; - this->Internal->ComputeLinkInterfaceLibraries( - this, config, iface, head, false); + this->ComputeLinkInterfaceLibraries( + config, iface, head, false); } if(!iface.AllDone) { iface.AllDone = true; if(iface.Exists) { - this->Internal->ComputeLinkInterface(this, config, iface, head); + this->ComputeLinkInterface(config, iface, head); } } @@ -4206,8 +4196,8 @@ cmTarget::GetLinkInterfaceLibraries(const std::string& config, if(!iface.LibrariesDone) { iface.LibrariesDone = true; - this->Internal->ComputeLinkInterfaceLibraries( - this, config, iface, head, usage_requirements_only); + this->ComputeLinkInterfaceLibraries( + config, iface, head, usage_requirements_only); } return iface.Exists? &iface : 0; @@ -4258,12 +4248,11 @@ cmTarget::GetImportLinkInterface(const std::string& config, //---------------------------------------------------------------------------- void -cmTargetInternals::ComputeLinkInterfaceLibraries( - cmTarget const* thisTarget, +cmTarget::ComputeLinkInterfaceLibraries( const std::string& config, cmOptionalLinkInterface& iface, cmTarget const* headTarget, - bool usage_requirements_only) + bool usage_requirements_only) const { // Construct the property name suffix for this configuration. std::string suffix = "_"; @@ -4280,15 +4269,15 @@ cmTargetInternals::ComputeLinkInterfaceLibraries( // libraries and executables that export symbols. const char* explicitLibraries = 0; std::string linkIfaceProp; - if(thisTarget->GetPolicyStatusCMP0022() != cmPolicies::OLD && - thisTarget->GetPolicyStatusCMP0022() != cmPolicies::WARN) + if(this->GetPolicyStatusCMP0022() != cmPolicies::OLD && + this->GetPolicyStatusCMP0022() != cmPolicies::WARN) { // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES. linkIfaceProp = "INTERFACE_LINK_LIBRARIES"; - explicitLibraries = thisTarget->GetProperty(linkIfaceProp); + explicitLibraries = this->GetProperty(linkIfaceProp); } - else if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY || - thisTarget->IsExecutableWithExports()) + else if(this->GetType() == cmTarget::SHARED_LIBRARY || + this->IsExecutableWithExports()) { // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a // shared lib or executable. @@ -4296,30 +4285,30 @@ cmTargetInternals::ComputeLinkInterfaceLibraries( // Lookup the per-configuration property. linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; linkIfaceProp += suffix; - explicitLibraries = thisTarget->GetProperty(linkIfaceProp); + explicitLibraries = this->GetProperty(linkIfaceProp); // If not set, try the generic property. if(!explicitLibraries) { linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; - explicitLibraries = thisTarget->GetProperty(linkIfaceProp); + explicitLibraries = this->GetProperty(linkIfaceProp); } } if(explicitLibraries && - thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN && - !this->PolicyWarnedCMP0022) + this->GetPolicyStatusCMP0022() == cmPolicies::WARN && + !this->Internal->PolicyWarnedCMP0022) { // Compare the explicitly set old link interface properties to the // preferred new link interface property one and warn if different. const char* newExplicitLibraries = - thisTarget->GetProperty("INTERFACE_LINK_LIBRARIES"); + this->GetProperty("INTERFACE_LINK_LIBRARIES"); if (newExplicitLibraries && strcmp(newExplicitLibraries, explicitLibraries) != 0) { std::ostringstream w; w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n" - "Target \"" << thisTarget->GetName() << "\" has an " + "Target \"" << this->GetName() << "\" has an " "INTERFACE_LINK_LIBRARIES property which differs from its " << linkIfaceProp << " properties." "\n" @@ -4327,16 +4316,16 @@ cmTargetInternals::ComputeLinkInterfaceLibraries( " " << newExplicitLibraries << "\n" << linkIfaceProp << ":\n" " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n"; - thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); - this->PolicyWarnedCMP0022 = true; + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Internal->PolicyWarnedCMP0022 = true; } } // There is no implicit link interface for executables or modules // so if none was explicitly set then there is no link interface. if(!explicitLibraries && - (thisTarget->GetType() == cmTarget::EXECUTABLE || - (thisTarget->GetType() == cmTarget::MODULE_LIBRARY))) + (this->GetType() == cmTarget::EXECUTABLE || + (this->GetType() == cmTarget::MODULE_LIBRARY))) { return; } @@ -4346,13 +4335,13 @@ cmTargetInternals::ComputeLinkInterfaceLibraries( if(explicitLibraries) { // The interface libraries have been explicitly set. - thisTarget->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, + this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, headTarget, usage_requirements_only, iface.Libraries, iface.HadHeadSensitiveCondition); } - else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN - || thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD) + else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN + || this->GetPolicyStatusCMP0022() == cmPolicies::OLD) // If CMP0022 is NEW then the plain tll signature sets the // INTERFACE_LINK_LIBRARIES, so if we get here then the project // cleared the property explicitly and we should not fall back @@ -4360,20 +4349,20 @@ cmTargetInternals::ComputeLinkInterfaceLibraries( { // The link implementation is the default link interface. cmLinkImplementationLibraries const* impl = - thisTarget->GetLinkImplementationLibrariesInternal(config, headTarget); + this->GetLinkImplementationLibrariesInternal(config, headTarget); iface.Libraries.insert(iface.Libraries.end(), impl->Libraries.begin(), impl->Libraries.end()); - if(thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN && - !this->PolicyWarnedCMP0022 && !usage_requirements_only) + if(this->GetPolicyStatusCMP0022() == cmPolicies::WARN && + !this->Internal->PolicyWarnedCMP0022 && !usage_requirements_only) { // Compare the link implementation fallback link interface to the // preferred new link interface property and warn if different. std::vector ifaceLibs; static const std::string newProp = "INTERFACE_LINK_LIBRARIES"; - if(const char* newExplicitLibraries = thisTarget->GetProperty(newProp)) + if(const char* newExplicitLibraries = this->GetProperty(newProp)) { bool hadHeadSensitiveConditionDummy = false; - thisTarget->ExpandLinkItems(newProp, newExplicitLibraries, config, + this->ExpandLinkItems(newProp, newExplicitLibraries, config, headTarget, usage_requirements_only, ifaceLibs, hadHeadSensitiveConditionDummy); } @@ -4388,7 +4377,7 @@ cmTargetInternals::ComputeLinkInterfaceLibraries( std::ostringstream w; w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n" - "Target \"" << thisTarget->GetName() << "\" has an " + "Target \"" << this->GetName() << "\" has an " "INTERFACE_LINK_LIBRARIES property. " "This should be preferred as the source of the link interface " "for this library but because CMP0022 is not set CMake is " @@ -4399,24 +4388,23 @@ cmTargetInternals::ComputeLinkInterfaceLibraries( " " << newLibraries << "\n" "Link implementation:\n" " " << oldLibraries << "\n"; - thisTarget->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); - this->PolicyWarnedCMP0022 = true; + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->Internal->PolicyWarnedCMP0022 = true; } } } } //---------------------------------------------------------------------------- -void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget, - const std::string& config, - cmOptionalLinkInterface &iface, - cmTarget const* headTarget) const +void cmTarget::ComputeLinkInterface(const std::string& config, + cmOptionalLinkInterface &iface, + cmTarget const* headTarget) const { if(iface.ExplicitLibraries) { - if(thisTarget->GetType() == cmTarget::SHARED_LIBRARY - || thisTarget->GetType() == cmTarget::STATIC_LIBRARY - || thisTarget->GetType() == cmTarget::INTERFACE_LIBRARY) + if(this->GetType() == cmTarget::SHARED_LIBRARY + || this->GetType() == cmTarget::STATIC_LIBRARY + || this->GetType() == cmTarget::INTERFACE_LIBRARY) { // Shared libraries may have runtime implementation dependencies // on other shared libraries that are not in the interface. @@ -4426,10 +4414,10 @@ void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget, { emitted.insert(*li); } - if (thisTarget->GetType() != cmTarget::INTERFACE_LIBRARY) + if (this->GetType() != cmTarget::INTERFACE_LIBRARY) { cmTarget::LinkImplementation const* impl = - thisTarget->GetLinkImplementation(config); + this->GetLinkImplementation(config); for(std::vector::const_iterator li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li) { @@ -4455,28 +4443,28 @@ void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget, } } } - else if (thisTarget->GetPolicyStatusCMP0022() == cmPolicies::WARN - || thisTarget->GetPolicyStatusCMP0022() == cmPolicies::OLD) + else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN + || this->GetPolicyStatusCMP0022() == cmPolicies::OLD) { // The link implementation is the default link interface. cmLinkImplementationLibraries const* - impl = thisTarget->GetLinkImplementationLibrariesInternal(config, + impl = this->GetLinkImplementationLibrariesInternal(config, headTarget); iface.ImplementationIsInterface = true; iface.WrongConfigLibraries = impl->WrongConfigLibraries; } - if(thisTarget->LinkLanguagePropagatesToDependents()) + if(this->LinkLanguagePropagatesToDependents()) { // Targets using this archive need its language runtime libraries. if(cmTarget::LinkImplementation const* impl = - thisTarget->GetLinkImplementation(config)) + this->GetLinkImplementation(config)) { iface.Languages = impl->Languages; } } - if(thisTarget->GetType() == cmTarget::STATIC_LIBRARY) + if(this->GetType() == cmTarget::STATIC_LIBRARY) { // Construct the property name suffix for this configuration. std::string suffix = "_"; @@ -4493,12 +4481,12 @@ void cmTargetInternals::ComputeLinkInterface(cmTarget const* thisTarget, // dependencies? std::string propName = "LINK_INTERFACE_MULTIPLICITY"; propName += suffix; - if(const char* config_reps = thisTarget->GetProperty(propName)) + if(const char* config_reps = this->GetProperty(propName)) { sscanf(config_reps, "%u", &iface.Multiplicity); } else if(const char* reps = - thisTarget->GetProperty("LINK_INTERFACE_MULTIPLICITY")) + this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) { sscanf(reps, "%u", &iface.Multiplicity); } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 8594e05e0..563caf83e 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -233,6 +233,14 @@ public: void GetObjectLibrariesCMP0026(std::vector& objlibs) const; + void ComputeLinkInterface(const std::string& config, + cmOptionalLinkInterface& iface, + cmTarget const* head) const; + void ComputeLinkInterfaceLibraries(const std::string& config, + cmOptionalLinkInterface &iface, + cmTarget const* head, + bool usage_requirements_only) const; + /** Get the link interface for the given configuration. Returns 0 if the target cannot be linked. */ cmLinkInterface const* GetLinkInterface(const std::string& config, From 20993de46444e0f74700a641b54a8ca7e015bac4 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Aug 2015 19:37:06 +0200 Subject: [PATCH 03/22] cmTarget: Move cmHeadToLinkInterfaceMap out. --- Source/cmLinkItem.h | 5 +++++ Source/cmTarget.cxx | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h index eb585abf9..91220b8c7 100644 --- a/Source/cmLinkItem.h +++ b/Source/cmLinkItem.h @@ -96,4 +96,9 @@ struct cmOptionalLinkInterface: public cmLinkInterface const char* ExplicitLibraries; }; +struct cmHeadToLinkInterfaceMap: + public std::map +{ +}; + #endif diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 60453e141..a10cb86d8 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -91,9 +91,7 @@ public: // The backtrace when the target was created. cmListFileBacktrace Backtrace; - struct HeadToLinkInterfaceMap: - public std::map {}; - typedef std::map + typedef std::map LinkInterfaceMapType; LinkInterfaceMapType LinkInterfaceMap; LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap; @@ -4129,7 +4127,7 @@ cmLinkInterface const* cmTarget::GetLinkInterface(const std::string& config, // Lookup any existing link interface for this configuration. std::string CONFIG = cmSystemTools::UpperCase(config); - cmTargetInternals::HeadToLinkInterfaceMap& hm = + cmHeadToLinkInterfaceMap& hm = this->Internal->LinkInterfaceMap[CONFIG]; // If the link interface does not depend on the head target @@ -4180,7 +4178,7 @@ cmTarget::GetLinkInterfaceLibraries(const std::string& config, // Lookup any existing link interface for this configuration. std::string CONFIG = cmSystemTools::UpperCase(config); - cmTargetInternals::HeadToLinkInterfaceMap& hm = + cmHeadToLinkInterfaceMap& hm = (usage_requirements_only ? this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] : this->Internal->LinkInterfaceMap[CONFIG]); @@ -4216,7 +4214,7 @@ cmTarget::GetImportLinkInterface(const std::string& config, } std::string CONFIG = cmSystemTools::UpperCase(config); - cmTargetInternals::HeadToLinkInterfaceMap& hm = + cmHeadToLinkInterfaceMap& hm = (usage_requirements_only ? this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] : this->Internal->LinkInterfaceMap[CONFIG]); From 6353816786caccfef7acb3fd72aa28e0366da405 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Aug 2015 19:37:32 +0200 Subject: [PATCH 04/22] cmTarget: Add GetHeadToLinkInterfaceMap methods. --- Source/cmTarget.cxx | 28 ++++++++++++++++++++-------- Source/cmTarget.h | 5 +++++ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index a10cb86d8..fb545b102 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -4126,9 +4126,7 @@ cmLinkInterface const* cmTarget::GetLinkInterface(const std::string& config, } // Lookup any existing link interface for this configuration. - std::string CONFIG = cmSystemTools::UpperCase(config); - cmHeadToLinkInterfaceMap& hm = - this->Internal->LinkInterfaceMap[CONFIG]; + cmHeadToLinkInterfaceMap& hm = this->GetHeadToLinkInterfaceMap(config); // If the link interface does not depend on the head target // then return the one we computed first. @@ -4177,11 +4175,10 @@ cmTarget::GetLinkInterfaceLibraries(const std::string& config, } // Lookup any existing link interface for this configuration. - std::string CONFIG = cmSystemTools::UpperCase(config); cmHeadToLinkInterfaceMap& hm = (usage_requirements_only ? - this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] : - this->Internal->LinkInterfaceMap[CONFIG]); + this->GetHeadToLinkInterfaceUsageRequirementsMap(config) : + this->GetHeadToLinkInterfaceMap(config)); // If the link interface does not depend on the head target // then return the one we computed first. @@ -4201,6 +4198,21 @@ cmTarget::GetLinkInterfaceLibraries(const std::string& config, return iface.Exists? &iface : 0; } +cmHeadToLinkInterfaceMap& +cmTarget::GetHeadToLinkInterfaceMap(const std::string &config) const +{ + std::string CONFIG = cmSystemTools::UpperCase(config); + return this->Internal->LinkInterfaceMap[CONFIG]; +} + +cmHeadToLinkInterfaceMap& +cmTarget::GetHeadToLinkInterfaceUsageRequirementsMap( + const std::string &config) const +{ + std::string CONFIG = cmSystemTools::UpperCase(config); + return this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG]; +} + //---------------------------------------------------------------------------- const cmLinkInterface * cmTarget::GetImportLinkInterface(const std::string& config, @@ -4216,8 +4228,8 @@ cmTarget::GetImportLinkInterface(const std::string& config, std::string CONFIG = cmSystemTools::UpperCase(config); cmHeadToLinkInterfaceMap& hm = (usage_requirements_only ? - this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG] : - this->Internal->LinkInterfaceMap[CONFIG]); + this->GetHeadToLinkInterfaceUsageRequirementsMap(config) : + this->GetHeadToLinkInterfaceMap(config)); // If the link interface does not depend on the head target // then return the one we computed first. diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 563caf83e..53a8bd643 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -250,6 +250,11 @@ public: cmTarget const* headTarget, bool usage_requirements_only) const; + cmHeadToLinkInterfaceMap& + GetHeadToLinkInterfaceMap(std::string const& config) const; + cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap( + std::string const& config) const; + struct LinkImplementation: public cmLinkImplementationLibraries { // Languages whose runtime libraries must be linked. From 6220241fd0bb7902c932742a7aa3d6a96fd0e919 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Aug 2015 19:37:45 +0200 Subject: [PATCH 05/22] cmGeneratorTarget: Move GetLinkInterface from cmTarget. --- Source/cmComputeLinkDepends.cxx | 12 +++++-- Source/cmComputeTargetDepends.cxx | 2 +- Source/cmExportFileGenerator.cxx | 8 ++--- Source/cmGeneratorTarget.cxx | 55 +++++++++++++++++++++++++++++-- Source/cmGeneratorTarget.h | 4 ++- Source/cmTarget.cxx | 47 -------------------------- Source/cmTarget.h | 4 --- 7 files changed, 69 insertions(+), 63 deletions(-) diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 03ec8200d..5e9627bd4 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -360,9 +360,11 @@ void cmComputeLinkDepends::FollowLinkEntry(BFSEntry const& qe) // Follow the item's dependencies. if(entry.Target) { + cmGeneratorTarget* gtgt = + this->GlobalGenerator->GetGeneratorTarget(entry.Target); // Follow the target dependencies. if(cmLinkInterface const* iface = - entry.Target->GetLinkInterface(this->Config, this->Target->Target)) + gtgt->GetLinkInterface(this->Config, this->Target->Target)) { const bool isIface = entry.Target->GetType() == cmTarget::INTERFACE_LIBRARY; @@ -459,8 +461,10 @@ void cmComputeLinkDepends::HandleSharedDependency(SharedDepEntry const& dep) // Target items may have their own dependencies. if(entry.Target) { + cmGeneratorTarget* gtgt = + this->GlobalGenerator->GetGeneratorTarget(entry.Target); if(cmLinkInterface const* iface = - entry.Target->GetLinkInterface(this->Config, this->Target->Target)) + gtgt->GetLinkInterface(this->Config, this->Target->Target)) { // Follow public and private dependencies transitively. this->FollowSharedDeps(index, iface, true); @@ -930,8 +934,10 @@ int cmComputeLinkDepends::ComputeComponentCount(NodeList const& nl) { if(cmTarget const* target = this->EntryList[*ni].Target) { + cmGeneratorTarget* gtgt = + this->GlobalGenerator->GetGeneratorTarget(target); if(cmLinkInterface const* iface = - target->GetLinkInterface(this->Config, this->Target->Target)) + gtgt->GetLinkInterface(this->Config, this->Target->Target)) { if(iface->Multiplicity > count) { diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index aeb918441..83b2a0ede 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -297,7 +297,7 @@ void cmComputeTargetDepends::AddInterfaceDepends(int depender_index, { cmGeneratorTarget const* depender = this->Targets[depender_index]; if(cmLinkInterface const* iface = - dependee->Target->GetLinkInterface(config, + dependee->GetLinkInterface(config, depender->Target)) { for(std::vector::const_iterator diff --git a/Source/cmExportFileGenerator.cxx b/Source/cmExportFileGenerator.cxx index d559a0748..9a7d73f4b 100644 --- a/Source/cmExportFileGenerator.cxx +++ b/Source/cmExportFileGenerator.cxx @@ -796,9 +796,8 @@ cmExportFileGenerator std::vector& missingTargets) { // Add the transitive link dependencies for this configuration. - cmLinkInterface const* iface = target->Target->GetLinkInterface( - config, - target->Target); + cmLinkInterface const* iface = target->GetLinkInterface(config, + target->Target); if (!iface) { return; @@ -910,8 +909,7 @@ cmExportFileGenerator // Add the transitive link dependencies for this configuration. if(cmLinkInterface const* iface = - target->Target - ->GetLinkInterface(config, target->Target)) + target->GetLinkInterface(config, target->Target)) { this->SetImportLinkProperty(suffix, target, "IMPORTED_LINK_INTERFACE_LANGUAGES", diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 06a4c6a0f..5d843098e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1172,9 +1172,11 @@ public: { return; } - + cmGeneratorTarget* gtgt = + this->Target->GetLocalGenerator()->GetGlobalGenerator() + ->GetGeneratorTarget(item.Target); cmLinkInterface const* iface = - item.Target->GetLinkInterface(this->Config, this->HeadTarget); + gtgt->GetLinkInterface(this->Config, this->HeadTarget); if(!iface) { return; } for(std::vector::const_iterator @@ -3354,3 +3356,52 @@ cmGeneratorTarget::ReportPropertyOrigin(const std::string &p, this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport); } + +//---------------------------------------------------------------------------- +cmLinkInterface const* +cmGeneratorTarget::GetLinkInterface(const std::string& config, + cmTarget const* head) const +{ + // Imported targets have their own link interface. + if(this->IsImported()) + { + return this->Target->GetImportLinkInterface(config, head, false); + } + + // Link interfaces are not supported for executables that do not + // export symbols. + if(this->GetType() == cmTarget::EXECUTABLE && + !this->Target->IsExecutableWithExports()) + { + return 0; + } + + // Lookup any existing link interface for this configuration. + cmHeadToLinkInterfaceMap& hm = + this->Target->GetHeadToLinkInterfaceMap(config); + + // If the link interface does not depend on the head target + // then return the one we computed first. + if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) + { + return &hm.begin()->second; + } + + cmOptionalLinkInterface& iface = hm[head]; + if(!iface.LibrariesDone) + { + iface.LibrariesDone = true; + this->Target->ComputeLinkInterfaceLibraries( + config, iface, head, false); + } + if(!iface.AllDone) + { + iface.AllDone = true; + if(iface.Exists) + { + this->Target->ComputeLinkInterface(config, iface, head); + } + } + + return iface.Exists? &iface : 0; +} diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 15b333566..2dbb502e8 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -12,7 +12,7 @@ #ifndef cmGeneratorTarget_h #define cmGeneratorTarget_h -#include "cmStandardIncludes.h" +#include "cmLinkItem.h" class cmCustomCommand; class cmGlobalGenerator; @@ -106,6 +106,8 @@ public: const char *GetLinkInterfaceDependentNumberMaxProperty(const std::string &p, const std::string& config) const; + cmLinkInterface const* GetLinkInterface(const std::string& config, + cmTarget const* headTarget) const; /** Get the full path to the target according to the settings in its makefile and the configuration type. */ diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index fb545b102..ee298acad 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -4107,53 +4107,6 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, } } -//---------------------------------------------------------------------------- -cmLinkInterface const* cmTarget::GetLinkInterface(const std::string& config, - cmTarget const* head) const -{ - // Imported targets have their own link interface. - if(this->IsImported()) - { - return this->GetImportLinkInterface(config, head, false); - } - - // Link interfaces are not supported for executables that do not - // export symbols. - if(this->GetType() == cmTarget::EXECUTABLE && - !this->IsExecutableWithExports()) - { - return 0; - } - - // Lookup any existing link interface for this configuration. - cmHeadToLinkInterfaceMap& hm = this->GetHeadToLinkInterfaceMap(config); - - // If the link interface does not depend on the head target - // then return the one we computed first. - if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) - { - return &hm.begin()->second; - } - - cmOptionalLinkInterface& iface = hm[head]; - if(!iface.LibrariesDone) - { - iface.LibrariesDone = true; - this->ComputeLinkInterfaceLibraries( - config, iface, head, false); - } - if(!iface.AllDone) - { - iface.AllDone = true; - if(iface.Exists) - { - this->ComputeLinkInterface(config, iface, head); - } - } - - return iface.Exists? &iface : 0; -} - //---------------------------------------------------------------------------- const cmLinkInterfaceLibraries * cmTarget::GetLinkInterfaceLibraries(const std::string& config, diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 53a8bd643..a8c6e8fd3 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -241,10 +241,6 @@ public: cmTarget const* head, bool usage_requirements_only) const; - /** Get the link interface for the given configuration. Returns 0 - if the target cannot be linked. */ - cmLinkInterface const* GetLinkInterface(const std::string& config, - cmTarget const* headTarget) const; cmLinkInterfaceLibraries const* GetLinkInterfaceLibraries(const std::string& config, cmTarget const* headTarget, From 84b847e42fde288bc102198aedeb68e19b41ef1e Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Aug 2015 19:38:14 +0200 Subject: [PATCH 06/22] cmGeneratorTarget: Move ComputeLinkInterface from cmTarget. --- Source/cmGeneratorTarget.cxx | 100 ++++++++++++++++++++++++++++++++++- Source/cmGeneratorTarget.h | 3 ++ Source/cmTarget.cxx | 97 --------------------------------- Source/cmTarget.h | 3 -- 4 files changed, 102 insertions(+), 101 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 5d843098e..058a12064 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3399,9 +3399,107 @@ cmGeneratorTarget::GetLinkInterface(const std::string& config, iface.AllDone = true; if(iface.Exists) { - this->Target->ComputeLinkInterface(config, iface, head); + this->ComputeLinkInterface(config, iface, head); } } return iface.Exists? &iface : 0; } + +//---------------------------------------------------------------------------- +void cmGeneratorTarget::ComputeLinkInterface(const std::string& config, + cmOptionalLinkInterface &iface, + cmTarget const* headTarget) const +{ + if(iface.ExplicitLibraries) + { + if(this->GetType() == cmTarget::SHARED_LIBRARY + || this->GetType() == cmTarget::STATIC_LIBRARY + || this->GetType() == cmTarget::INTERFACE_LIBRARY) + { + // Shared libraries may have runtime implementation dependencies + // on other shared libraries that are not in the interface. + UNORDERED_SET emitted; + for(std::vector::const_iterator + li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li) + { + emitted.insert(*li); + } + if (this->GetType() != cmTarget::INTERFACE_LIBRARY) + { + cmTarget::LinkImplementation const* impl = + this->Target->GetLinkImplementation(config); + for(std::vector::const_iterator + li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li) + { + if(emitted.insert(*li).second) + { + if(li->Target) + { + // This is a runtime dependency on another shared library. + if(li->Target->GetType() == cmTarget::SHARED_LIBRARY) + { + iface.SharedDeps.push_back(*li); + } + } + else + { + // TODO: Recognize shared library file names. Perhaps this + // should be moved to cmComputeLinkInformation, but that creates + // a chicken-and-egg problem since this list is needed for its + // construction. + } + } + } + } + } + } + else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN + || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD) + { + // The link implementation is the default link interface. + cmLinkImplementationLibraries const* + impl = this->Target->GetLinkImplementationLibrariesInternal(config, + headTarget); + iface.ImplementationIsInterface = true; + iface.WrongConfigLibraries = impl->WrongConfigLibraries; + } + + if(this->Target->LinkLanguagePropagatesToDependents()) + { + // Targets using this archive need its language runtime libraries. + if(cmTarget::LinkImplementation const* impl = + this->Target->GetLinkImplementation(config)) + { + iface.Languages = impl->Languages; + } + } + + if(this->GetType() == cmTarget::STATIC_LIBRARY) + { + // Construct the property name suffix for this configuration. + std::string suffix = "_"; + if(!config.empty()) + { + suffix += cmSystemTools::UpperCase(config); + } + else + { + suffix += "NOCONFIG"; + } + + // How many repetitions are needed if this library has cyclic + // dependencies? + std::string propName = "LINK_INTERFACE_MULTIPLICITY"; + propName += suffix; + if(const char* config_reps = this->GetProperty(propName)) + { + sscanf(config_reps, "%u", &iface.Multiplicity); + } + else if(const char* reps = + this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) + { + sscanf(reps, "%u", &iface.Multiplicity); + } + } +} diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 2dbb502e8..282ab8997 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -108,6 +108,9 @@ public: cmLinkInterface const* GetLinkInterface(const std::string& config, cmTarget const* headTarget) const; + void ComputeLinkInterface(const std::string& config, + cmOptionalLinkInterface& iface, + cmTarget const* head) const; /** Get the full path to the target according to the settings in its makefile and the configuration type. */ diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ee298acad..c8a91482a 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -4358,103 +4358,6 @@ cmTarget::ComputeLinkInterfaceLibraries( } } -//---------------------------------------------------------------------------- -void cmTarget::ComputeLinkInterface(const std::string& config, - cmOptionalLinkInterface &iface, - cmTarget const* headTarget) const -{ - if(iface.ExplicitLibraries) - { - if(this->GetType() == cmTarget::SHARED_LIBRARY - || this->GetType() == cmTarget::STATIC_LIBRARY - || this->GetType() == cmTarget::INTERFACE_LIBRARY) - { - // Shared libraries may have runtime implementation dependencies - // on other shared libraries that are not in the interface. - UNORDERED_SET emitted; - for(std::vector::const_iterator - li = iface.Libraries.begin(); li != iface.Libraries.end(); ++li) - { - emitted.insert(*li); - } - if (this->GetType() != cmTarget::INTERFACE_LIBRARY) - { - cmTarget::LinkImplementation const* impl = - this->GetLinkImplementation(config); - for(std::vector::const_iterator - li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li) - { - if(emitted.insert(*li).second) - { - if(li->Target) - { - // This is a runtime dependency on another shared library. - if(li->Target->GetType() == cmTarget::SHARED_LIBRARY) - { - iface.SharedDeps.push_back(*li); - } - } - else - { - // TODO: Recognize shared library file names. Perhaps this - // should be moved to cmComputeLinkInformation, but that creates - // a chicken-and-egg problem since this list is needed for its - // construction. - } - } - } - } - } - } - else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN - || this->GetPolicyStatusCMP0022() == cmPolicies::OLD) - { - // The link implementation is the default link interface. - cmLinkImplementationLibraries const* - impl = this->GetLinkImplementationLibrariesInternal(config, - headTarget); - iface.ImplementationIsInterface = true; - iface.WrongConfigLibraries = impl->WrongConfigLibraries; - } - - if(this->LinkLanguagePropagatesToDependents()) - { - // Targets using this archive need its language runtime libraries. - if(cmTarget::LinkImplementation const* impl = - this->GetLinkImplementation(config)) - { - iface.Languages = impl->Languages; - } - } - - if(this->GetType() == cmTarget::STATIC_LIBRARY) - { - // Construct the property name suffix for this configuration. - std::string suffix = "_"; - if(!config.empty()) - { - suffix += cmSystemTools::UpperCase(config); - } - else - { - suffix += "NOCONFIG"; - } - - // How many repetitions are needed if this library has cyclic - // dependencies? - std::string propName = "LINK_INTERFACE_MULTIPLICITY"; - propName += suffix; - if(const char* config_reps = this->GetProperty(propName)) - { - sscanf(config_reps, "%u", &iface.Multiplicity); - } - else if(const char* reps = - this->GetProperty("LINK_INTERFACE_MULTIPLICITY")) - { - sscanf(reps, "%u", &iface.Multiplicity); - } - } -} //---------------------------------------------------------------------------- void cmTargetInternals::AddInterfaceEntries( diff --git a/Source/cmTarget.h b/Source/cmTarget.h index a8c6e8fd3..e71820e6c 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -233,9 +233,6 @@ public: void GetObjectLibrariesCMP0026(std::vector& objlibs) const; - void ComputeLinkInterface(const std::string& config, - cmOptionalLinkInterface& iface, - cmTarget const* head) const; void ComputeLinkInterfaceLibraries(const std::string& config, cmOptionalLinkInterface &iface, cmTarget const* head, From 0db9d9278760c90be1fbf5c4eeb93ef9c524041a Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Aug 2015 19:38:37 +0200 Subject: [PATCH 07/22] cmGeneratorTarget: Move GetLinkInterfaceLibraries from cmTarget. --- Source/cmGeneratorExpressionNode.cxx | 2 +- Source/cmGeneratorTarget.cxx | 56 ++++++++++++++++++++++++++-- Source/cmGeneratorTarget.h | 5 +++ Source/cmTarget.cxx | 44 ---------------------- Source/cmTarget.h | 5 --- 5 files changed, 59 insertions(+), 53 deletions(-) diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index 9509c2b6e..31b6766a2 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -1109,7 +1109,7 @@ static const struct TargetPropertyNode : public cmGeneratorExpressionNode if(isInterfaceProperty) { if(cmLinkInterfaceLibraries const* iface = - target->GetLinkInterfaceLibraries(context->Config, headTarget, true)) + gtgt->GetLinkInterfaceLibraries(context->Config, headTarget, true)) { linkedTargetsContent = getLinkedTargetsContent(iface->Libraries, target, diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 058a12064..2489c990a 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1507,20 +1507,22 @@ void cmGeneratorTarget::GetAutoUicOptions(std::vector &result, void processILibs(const std::string& config, cmTarget const* headTarget, cmLinkItem const& item, + cmGlobalGenerator* gg, std::vector& tgts, std::set& emitted) { if (item.Target && emitted.insert(item.Target).second) { tgts.push_back(item.Target); + cmGeneratorTarget* gt = gg->GetGeneratorTarget(item.Target); if(cmLinkInterfaceLibraries const* iface = - item.Target->GetLinkInterfaceLibraries(config, headTarget, true)) + gt->GetLinkInterfaceLibraries(config, headTarget, true)) { for(std::vector::const_iterator it = iface->Libraries.begin(); it != iface->Libraries.end(); ++it) { - processILibs(config, headTarget, *it, tgts, emitted); + processILibs(config, headTarget, *it, gg, tgts, emitted); } } } @@ -1545,7 +1547,9 @@ cmGeneratorTarget::GetLinkImplementationClosure( it = impl->Libraries.begin(); it != impl->Libraries.end(); ++it) { - processILibs(config, this->Target, *it, tgts , emitted); + processILibs(config, this->Target, *it, + this->LocalGenerator->GetGlobalGenerator(), + tgts , emitted); } } return tgts; @@ -3503,3 +3507,49 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config, } } } + +//---------------------------------------------------------------------------- +const cmLinkInterfaceLibraries * +cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config, + cmTarget const* head, + bool usage_requirements_only) const +{ + // Imported targets have their own link interface. + if(this->IsImported()) + { + return this->Target->GetImportLinkInterface(config, head, + usage_requirements_only); + } + + // Link interfaces are not supported for executables that do not + // export symbols. + if(this->GetType() == cmTarget::EXECUTABLE && + !this->Target->IsExecutableWithExports()) + { + return 0; + } + + // Lookup any existing link interface for this configuration. + std::string CONFIG = cmSystemTools::UpperCase(config); + cmHeadToLinkInterfaceMap& hm = + (usage_requirements_only ? + this->Target->GetHeadToLinkInterfaceUsageRequirementsMap(config) : + this->Target->GetHeadToLinkInterfaceMap(config)); + + // If the link interface does not depend on the head target + // then return the one we computed first. + if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) + { + return &hm.begin()->second; + } + + cmOptionalLinkInterface& iface = hm[head]; + if(!iface.LibrariesDone) + { + iface.LibrariesDone = true; + this->Target->ComputeLinkInterfaceLibraries( + config, iface, head, usage_requirements_only); + } + + return iface.Exists? &iface : 0; +} diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 282ab8997..43fcb4a2b 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -112,6 +112,11 @@ public: cmOptionalLinkInterface& iface, cmTarget const* head) const; + cmLinkInterfaceLibraries const* + GetLinkInterfaceLibraries(const std::string& config, + cmTarget const* headTarget, + bool usage_requirements_only) const; + /** Get the full path to the target according to the settings in its makefile and the configuration type. */ std::string GetFullPath(const std::string& config="", bool implib = false, diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index c8a91482a..00dbc6a3d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -4107,50 +4107,6 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, } } -//---------------------------------------------------------------------------- -const cmLinkInterfaceLibraries * -cmTarget::GetLinkInterfaceLibraries(const std::string& config, - cmTarget const* head, - bool usage_requirements_only) const -{ - // Imported targets have their own link interface. - if(this->IsImported()) - { - return this->GetImportLinkInterface(config, head, usage_requirements_only); - } - - // Link interfaces are not supported for executables that do not - // export symbols. - if(this->GetType() == cmTarget::EXECUTABLE && - !this->IsExecutableWithExports()) - { - return 0; - } - - // Lookup any existing link interface for this configuration. - cmHeadToLinkInterfaceMap& hm = - (usage_requirements_only ? - this->GetHeadToLinkInterfaceUsageRequirementsMap(config) : - this->GetHeadToLinkInterfaceMap(config)); - - // If the link interface does not depend on the head target - // then return the one we computed first. - if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) - { - return &hm.begin()->second; - } - - cmOptionalLinkInterface& iface = hm[head]; - if(!iface.LibrariesDone) - { - iface.LibrariesDone = true; - this->ComputeLinkInterfaceLibraries( - config, iface, head, usage_requirements_only); - } - - return iface.Exists? &iface : 0; -} - cmHeadToLinkInterfaceMap& cmTarget::GetHeadToLinkInterfaceMap(const std::string &config) const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index e71820e6c..f124084c6 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -238,11 +238,6 @@ public: cmTarget const* head, bool usage_requirements_only) const; - cmLinkInterfaceLibraries const* - GetLinkInterfaceLibraries(const std::string& config, - cmTarget const* headTarget, - bool usage_requirements_only) const; - cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceMap(std::string const& config) const; cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap( From 6d3d099b4a2d8b020fb1a9ebeb29b17b3fb6c9d6 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Aug 2015 19:38:57 +0200 Subject: [PATCH 08/22] cmGeneratorTarget: Move ComputeLinkInterfaceLibraries from cmTarget. --- Source/cmGeneratorTarget.cxx | 158 ++++++++++++++++++++++++++++++++++- Source/cmGeneratorTarget.h | 6 ++ Source/cmTarget.cxx | 153 --------------------------------- Source/cmTarget.h | 5 -- 4 files changed, 161 insertions(+), 161 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 2489c990a..40a36378e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -230,7 +230,8 @@ struct TagVisitor //---------------------------------------------------------------------------- cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) : Target(t), - SourceFileFlagsConstructed(false) + SourceFileFlagsConstructed(false), + PolicyWarnedCMP0022(false) { this->Makefile = this->Target->GetMakefile(); this->LocalGenerator = lg; @@ -3395,7 +3396,7 @@ cmGeneratorTarget::GetLinkInterface(const std::string& config, if(!iface.LibrariesDone) { iface.LibrariesDone = true; - this->Target->ComputeLinkInterfaceLibraries( + this->ComputeLinkInterfaceLibraries( config, iface, head, false); } if(!iface.AllDone) @@ -3547,9 +3548,160 @@ cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config, if(!iface.LibrariesDone) { iface.LibrariesDone = true; - this->Target->ComputeLinkInterfaceLibraries( + this->ComputeLinkInterfaceLibraries( config, iface, head, usage_requirements_only); } return iface.Exists? &iface : 0; } + +//---------------------------------------------------------------------------- +void +cmGeneratorTarget::ComputeLinkInterfaceLibraries( + const std::string& config, + cmOptionalLinkInterface& iface, + cmTarget const* headTarget, + bool usage_requirements_only) const +{ + // Construct the property name suffix for this configuration. + std::string suffix = "_"; + if(!config.empty()) + { + suffix += cmSystemTools::UpperCase(config); + } + else + { + suffix += "NOCONFIG"; + } + + // An explicit list of interface libraries may be set for shared + // libraries and executables that export symbols. + const char* explicitLibraries = 0; + std::string linkIfaceProp; + if(this->Target->GetPolicyStatusCMP0022() != cmPolicies::OLD && + this->Target->GetPolicyStatusCMP0022() != cmPolicies::WARN) + { + // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES. + linkIfaceProp = "INTERFACE_LINK_LIBRARIES"; + explicitLibraries = this->GetProperty(linkIfaceProp); + } + else if(this->GetType() == cmTarget::SHARED_LIBRARY || + this->Target->IsExecutableWithExports()) + { + // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a + // shared lib or executable. + + // Lookup the per-configuration property. + linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; + linkIfaceProp += suffix; + explicitLibraries = this->GetProperty(linkIfaceProp); + + // If not set, try the generic property. + if(!explicitLibraries) + { + linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; + explicitLibraries = this->GetProperty(linkIfaceProp); + } + } + + if(explicitLibraries && + this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN && + !this->PolicyWarnedCMP0022) + { + // Compare the explicitly set old link interface properties to the + // preferred new link interface property one and warn if different. + const char* newExplicitLibraries = + this->GetProperty("INTERFACE_LINK_LIBRARIES"); + if (newExplicitLibraries + && strcmp(newExplicitLibraries, explicitLibraries) != 0) + { + std::ostringstream w; + w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n" + "Target \"" << this->GetName() << "\" has an " + "INTERFACE_LINK_LIBRARIES property which differs from its " << + linkIfaceProp << " properties." + "\n" + "INTERFACE_LINK_LIBRARIES:\n" + " " << newExplicitLibraries << "\n" << + linkIfaceProp << ":\n" + " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n"; + this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->PolicyWarnedCMP0022 = true; + } + } + + // There is no implicit link interface for executables or modules + // so if none was explicitly set then there is no link interface. + if(!explicitLibraries && + (this->GetType() == cmTarget::EXECUTABLE || + (this->GetType() == cmTarget::MODULE_LIBRARY))) + { + return; + } + iface.Exists = true; + iface.ExplicitLibraries = explicitLibraries; + + if(explicitLibraries) + { + // The interface libraries have been explicitly set. + this->Target->ExpandLinkItems(linkIfaceProp, explicitLibraries, + config, + headTarget, usage_requirements_only, + iface.Libraries, + iface.HadHeadSensitiveCondition); + } + else if (this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN + || this->Target->GetPolicyStatusCMP0022() == cmPolicies::OLD) + // If CMP0022 is NEW then the plain tll signature sets the + // INTERFACE_LINK_LIBRARIES, so if we get here then the project + // cleared the property explicitly and we should not fall back + // to the link implementation. + { + // The link implementation is the default link interface. + cmLinkImplementationLibraries const* impl = + this->Target->GetLinkImplementationLibrariesInternal(config, + headTarget); + iface.Libraries.insert(iface.Libraries.end(), + impl->Libraries.begin(), impl->Libraries.end()); + if(this->Target->GetPolicyStatusCMP0022() == cmPolicies::WARN && + !this->PolicyWarnedCMP0022 && !usage_requirements_only) + { + // Compare the link implementation fallback link interface to the + // preferred new link interface property and warn if different. + std::vector ifaceLibs; + static const std::string newProp = "INTERFACE_LINK_LIBRARIES"; + if(const char* newExplicitLibraries = this->GetProperty(newProp)) + { + bool hadHeadSensitiveConditionDummy = false; + this->Target->ExpandLinkItems(newProp, newExplicitLibraries, config, + headTarget, usage_requirements_only, + ifaceLibs, hadHeadSensitiveConditionDummy); + } + if (ifaceLibs != iface.Libraries) + { + std::string oldLibraries = cmJoin(impl->Libraries, ";"); + std::string newLibraries = cmJoin(ifaceLibs, ";"); + if(oldLibraries.empty()) + { oldLibraries = "(empty)"; } + if(newLibraries.empty()) + { newLibraries = "(empty)"; } + + std::ostringstream w; + w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n" + "Target \"" << this->GetName() << "\" has an " + "INTERFACE_LINK_LIBRARIES property. " + "This should be preferred as the source of the link interface " + "for this library but because CMP0022 is not set CMake is " + "ignoring the property and using the link implementation " + "as the link interface instead." + "\n" + "INTERFACE_LINK_LIBRARIES:\n" + " " << newLibraries << "\n" + "Link implementation:\n" + " " << oldLibraries << "\n"; + this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->PolicyWarnedCMP0022 = true; + } + } + } +} diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 43fcb4a2b..ac2b96cc7 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -117,6 +117,11 @@ public: cmTarget const* headTarget, bool usage_requirements_only) const; + void ComputeLinkInterfaceLibraries(const std::string& config, + cmOptionalLinkInterface &iface, + cmTarget const* head, + bool usage_requirements_only) const; + /** Get the full path to the target according to the settings in its makefile and the configuration type. */ std::string GetFullPath(const std::string& config="", bool implib = false, @@ -388,6 +393,7 @@ private: typedef std::pair OutputNameKey; typedef std::map OutputNameMapType; mutable OutputNameMapType OutputNameMap; + mutable bool PolicyWarnedCMP0022; public: std::vector const& diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 00dbc6a3d..9e9aed4e2 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -77,13 +77,11 @@ public: cmTargetInternals() : Backtrace() { - this->PolicyWarnedCMP0022 = false; this->UtilityItemsDone = false; } cmTargetInternals(cmTargetInternals const&) : Backtrace() { - this->PolicyWarnedCMP0022 = false; this->UtilityItemsDone = false; } ~cmTargetInternals(); @@ -95,7 +93,6 @@ public: LinkInterfaceMapType; LinkInterfaceMapType LinkInterfaceMap; LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap; - bool PolicyWarnedCMP0022; typedef std::map OutputInfoMapType; OutputInfoMapType OutputInfoMap; @@ -4165,156 +4162,6 @@ cmTarget::GetImportLinkInterface(const std::string& config, return &iface; } -//---------------------------------------------------------------------------- -void -cmTarget::ComputeLinkInterfaceLibraries( - const std::string& config, - cmOptionalLinkInterface& iface, - cmTarget const* headTarget, - bool usage_requirements_only) const -{ - // Construct the property name suffix for this configuration. - std::string suffix = "_"; - if(!config.empty()) - { - suffix += cmSystemTools::UpperCase(config); - } - else - { - suffix += "NOCONFIG"; - } - - // An explicit list of interface libraries may be set for shared - // libraries and executables that export symbols. - const char* explicitLibraries = 0; - std::string linkIfaceProp; - if(this->GetPolicyStatusCMP0022() != cmPolicies::OLD && - this->GetPolicyStatusCMP0022() != cmPolicies::WARN) - { - // CMP0022 NEW behavior is to use INTERFACE_LINK_LIBRARIES. - linkIfaceProp = "INTERFACE_LINK_LIBRARIES"; - explicitLibraries = this->GetProperty(linkIfaceProp); - } - else if(this->GetType() == cmTarget::SHARED_LIBRARY || - this->IsExecutableWithExports()) - { - // CMP0022 OLD behavior is to use LINK_INTERFACE_LIBRARIES if set on a - // shared lib or executable. - - // Lookup the per-configuration property. - linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; - linkIfaceProp += suffix; - explicitLibraries = this->GetProperty(linkIfaceProp); - - // If not set, try the generic property. - if(!explicitLibraries) - { - linkIfaceProp = "LINK_INTERFACE_LIBRARIES"; - explicitLibraries = this->GetProperty(linkIfaceProp); - } - } - - if(explicitLibraries && - this->GetPolicyStatusCMP0022() == cmPolicies::WARN && - !this->Internal->PolicyWarnedCMP0022) - { - // Compare the explicitly set old link interface properties to the - // preferred new link interface property one and warn if different. - const char* newExplicitLibraries = - this->GetProperty("INTERFACE_LINK_LIBRARIES"); - if (newExplicitLibraries - && strcmp(newExplicitLibraries, explicitLibraries) != 0) - { - std::ostringstream w; - w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n" - "Target \"" << this->GetName() << "\" has an " - "INTERFACE_LINK_LIBRARIES property which differs from its " << - linkIfaceProp << " properties." - "\n" - "INTERFACE_LINK_LIBRARIES:\n" - " " << newExplicitLibraries << "\n" << - linkIfaceProp << ":\n" - " " << (explicitLibraries ? explicitLibraries : "(empty)") << "\n"; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); - this->Internal->PolicyWarnedCMP0022 = true; - } - } - - // There is no implicit link interface for executables or modules - // so if none was explicitly set then there is no link interface. - if(!explicitLibraries && - (this->GetType() == cmTarget::EXECUTABLE || - (this->GetType() == cmTarget::MODULE_LIBRARY))) - { - return; - } - iface.Exists = true; - iface.ExplicitLibraries = explicitLibraries; - - if(explicitLibraries) - { - // The interface libraries have been explicitly set. - this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, - headTarget, usage_requirements_only, - iface.Libraries, - iface.HadHeadSensitiveCondition); - } - else if (this->GetPolicyStatusCMP0022() == cmPolicies::WARN - || this->GetPolicyStatusCMP0022() == cmPolicies::OLD) - // If CMP0022 is NEW then the plain tll signature sets the - // INTERFACE_LINK_LIBRARIES, so if we get here then the project - // cleared the property explicitly and we should not fall back - // to the link implementation. - { - // The link implementation is the default link interface. - cmLinkImplementationLibraries const* impl = - this->GetLinkImplementationLibrariesInternal(config, headTarget); - iface.Libraries.insert(iface.Libraries.end(), - impl->Libraries.begin(), impl->Libraries.end()); - if(this->GetPolicyStatusCMP0022() == cmPolicies::WARN && - !this->Internal->PolicyWarnedCMP0022 && !usage_requirements_only) - { - // Compare the link implementation fallback link interface to the - // preferred new link interface property and warn if different. - std::vector ifaceLibs; - static const std::string newProp = "INTERFACE_LINK_LIBRARIES"; - if(const char* newExplicitLibraries = this->GetProperty(newProp)) - { - bool hadHeadSensitiveConditionDummy = false; - this->ExpandLinkItems(newProp, newExplicitLibraries, config, - headTarget, usage_requirements_only, - ifaceLibs, hadHeadSensitiveConditionDummy); - } - if (ifaceLibs != iface.Libraries) - { - std::string oldLibraries = cmJoin(impl->Libraries, ";"); - std::string newLibraries = cmJoin(ifaceLibs, ";"); - if(oldLibraries.empty()) - { oldLibraries = "(empty)"; } - if(newLibraries.empty()) - { newLibraries = "(empty)"; } - - std::ostringstream w; - w << cmPolicies::GetPolicyWarning(cmPolicies::CMP0022) << "\n" - "Target \"" << this->GetName() << "\" has an " - "INTERFACE_LINK_LIBRARIES property. " - "This should be preferred as the source of the link interface " - "for this library but because CMP0022 is not set CMake is " - "ignoring the property and using the link implementation " - "as the link interface instead." - "\n" - "INTERFACE_LINK_LIBRARIES:\n" - " " << newLibraries << "\n" - "Link implementation:\n" - " " << oldLibraries << "\n"; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); - this->Internal->PolicyWarnedCMP0022 = true; - } - } - } -} - - //---------------------------------------------------------------------------- void cmTargetInternals::AddInterfaceEntries( cmTarget const* thisTarget, std::string const& config, diff --git a/Source/cmTarget.h b/Source/cmTarget.h index f124084c6..985e95870 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -233,11 +233,6 @@ public: void GetObjectLibrariesCMP0026(std::vector& objlibs) const; - void ComputeLinkInterfaceLibraries(const std::string& config, - cmOptionalLinkInterface &iface, - cmTarget const* head, - bool usage_requirements_only) const; - cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceMap(std::string const& config) const; cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap( From 2cb3e5740269757f6f93d24a4d13570ee72de318 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Aug 2015 19:39:17 +0200 Subject: [PATCH 09/22] cmGeneratorTarget: Move GetImportLinkInterface from cmTarget. --- Source/cmGeneratorTarget.cxx | 69 +++++++++++++++++++++++++++++++++--- Source/cmGeneratorTarget.h | 14 ++++++++ Source/cmTarget.cxx | 65 --------------------------------- Source/cmTarget.h | 10 ------ 4 files changed, 78 insertions(+), 80 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 40a36378e..c966e2480 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3370,7 +3370,7 @@ cmGeneratorTarget::GetLinkInterface(const std::string& config, // Imported targets have their own link interface. if(this->IsImported()) { - return this->Target->GetImportLinkInterface(config, head, false); + return this->GetImportLinkInterface(config, head, false); } // Link interfaces are not supported for executables that do not @@ -3383,7 +3383,7 @@ cmGeneratorTarget::GetLinkInterface(const std::string& config, // Lookup any existing link interface for this configuration. cmHeadToLinkInterfaceMap& hm = - this->Target->GetHeadToLinkInterfaceMap(config); + this->GetHeadToLinkInterfaceMap(config); // If the link interface does not depend on the head target // then return the one we computed first. @@ -3518,7 +3518,7 @@ cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config, // Imported targets have their own link interface. if(this->IsImported()) { - return this->Target->GetImportLinkInterface(config, head, + return this->GetImportLinkInterface(config, head, usage_requirements_only); } @@ -3534,8 +3534,8 @@ cmGeneratorTarget::GetLinkInterfaceLibraries(const std::string& config, std::string CONFIG = cmSystemTools::UpperCase(config); cmHeadToLinkInterfaceMap& hm = (usage_requirements_only ? - this->Target->GetHeadToLinkInterfaceUsageRequirementsMap(config) : - this->Target->GetHeadToLinkInterfaceMap(config)); + this->GetHeadToLinkInterfaceUsageRequirementsMap(config) : + this->GetHeadToLinkInterfaceMap(config)); // If the link interface does not depend on the head target // then return the one we computed first. @@ -3705,3 +3705,62 @@ cmGeneratorTarget::ComputeLinkInterfaceLibraries( } } } + +//---------------------------------------------------------------------------- +const cmLinkInterface * +cmGeneratorTarget::GetImportLinkInterface(const std::string& config, + cmTarget const* headTarget, + bool usage_requirements_only) const +{ + cmTarget::ImportInfo const* info = this->Target->GetImportInfo(config); + if(!info) + { + return 0; + } + + std::string CONFIG = cmSystemTools::UpperCase(config); + cmHeadToLinkInterfaceMap& hm = + (usage_requirements_only ? + this->GetHeadToLinkInterfaceUsageRequirementsMap(config) : + this->GetHeadToLinkInterfaceMap(config)); + + // If the link interface does not depend on the head target + // then return the one we computed first. + if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) + { + return &hm.begin()->second; + } + + cmOptionalLinkInterface& iface = hm[headTarget]; + if(!iface.AllDone) + { + iface.AllDone = true; + iface.Multiplicity = info->Multiplicity; + cmSystemTools::ExpandListArgument(info->Languages, iface.Languages); + this->Target->ExpandLinkItems(info->LibrariesProp, info->Libraries, + config, + headTarget, usage_requirements_only, + iface.Libraries, + iface.HadHeadSensitiveCondition); + std::vector deps; + cmSystemTools::ExpandListArgument(info->SharedDeps, deps); + this->Target->LookupLinkItems(deps, iface.SharedDeps); + } + + return &iface; +} + +cmHeadToLinkInterfaceMap& +cmGeneratorTarget::GetHeadToLinkInterfaceMap(const std::string &config) const +{ + std::string CONFIG = cmSystemTools::UpperCase(config); + return this->LinkInterfaceMap[CONFIG]; +} + +cmHeadToLinkInterfaceMap& +cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap( + const std::string &config) const +{ + std::string CONFIG = cmSystemTools::UpperCase(config); + return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG]; +} diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index ac2b96cc7..9c5adf654 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -390,6 +390,20 @@ private: }; mutable std::map LinkImplClosureMap; + typedef std::map + LinkInterfaceMapType; + mutable LinkInterfaceMapType LinkInterfaceMap; + mutable LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap; + + cmHeadToLinkInterfaceMap& + GetHeadToLinkInterfaceMap(std::string const& config) const; + cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap( + std::string const& config) const; + + cmLinkInterface const* + GetImportLinkInterface(const std::string& config, cmTarget const* head, + bool usage_requirements_only) const; + typedef std::pair OutputNameKey; typedef std::map OutputNameMapType; mutable OutputNameMapType OutputNameMap; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 9e9aed4e2..86285837c 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -89,11 +89,6 @@ public: // The backtrace when the target was created. cmListFileBacktrace Backtrace; - typedef std::map - LinkInterfaceMapType; - LinkInterfaceMapType LinkInterfaceMap; - LinkInterfaceMapType LinkInterfaceUsageRequirementsOnlyMap; - typedef std::map OutputInfoMapType; OutputInfoMapType OutputInfoMap; @@ -510,8 +505,6 @@ void cmTarget::ClearLinkMaps() { this->LinkImplementationLanguageIsContextDependent = true; this->Internal->LinkImplMap.clear(); - this->Internal->LinkInterfaceMap.clear(); - this->Internal->LinkInterfaceUsageRequirementsOnlyMap.clear(); this->Internal->SourceFilesMap.clear(); } @@ -4104,64 +4097,6 @@ void cmTarget::ComputeImportInfo(std::string const& desired_config, } } -cmHeadToLinkInterfaceMap& -cmTarget::GetHeadToLinkInterfaceMap(const std::string &config) const -{ - std::string CONFIG = cmSystemTools::UpperCase(config); - return this->Internal->LinkInterfaceMap[CONFIG]; -} - -cmHeadToLinkInterfaceMap& -cmTarget::GetHeadToLinkInterfaceUsageRequirementsMap( - const std::string &config) const -{ - std::string CONFIG = cmSystemTools::UpperCase(config); - return this->Internal->LinkInterfaceUsageRequirementsOnlyMap[CONFIG]; -} - -//---------------------------------------------------------------------------- -const cmLinkInterface * -cmTarget::GetImportLinkInterface(const std::string& config, - cmTarget const* headTarget, - bool usage_requirements_only) const -{ - cmTarget::ImportInfo const* info = this->GetImportInfo(config); - if(!info) - { - return 0; - } - - std::string CONFIG = cmSystemTools::UpperCase(config); - cmHeadToLinkInterfaceMap& hm = - (usage_requirements_only ? - this->GetHeadToLinkInterfaceUsageRequirementsMap(config) : - this->GetHeadToLinkInterfaceMap(config)); - - // If the link interface does not depend on the head target - // then return the one we computed first. - if(!hm.empty() && !hm.begin()->second.HadHeadSensitiveCondition) - { - return &hm.begin()->second; - } - - cmOptionalLinkInterface& iface = hm[headTarget]; - if(!iface.AllDone) - { - iface.AllDone = true; - iface.Multiplicity = info->Multiplicity; - cmSystemTools::ExpandListArgument(info->Languages, iface.Languages); - this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config, - headTarget, usage_requirements_only, - iface.Libraries, - iface.HadHeadSensitiveCondition); - std::vector deps; - cmSystemTools::ExpandListArgument(info->SharedDeps, deps); - this->LookupLinkItems(deps, iface.SharedDeps); - } - - return &iface; -} - //---------------------------------------------------------------------------- void cmTargetInternals::AddInterfaceEntries( cmTarget const* thisTarget, std::string const& config, diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 985e95870..25de6a659 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -233,11 +233,6 @@ public: void GetObjectLibrariesCMP0026(std::vector& objlibs) const; - cmHeadToLinkInterfaceMap& - GetHeadToLinkInterfaceMap(std::string const& config) const; - cmHeadToLinkInterfaceMap& GetHeadToLinkInterfaceUsageRequirementsMap( - std::string const& config) const; - struct LinkImplementation: public cmLinkImplementationLibraries { // Languages whose runtime libraries must be linked. @@ -559,11 +554,6 @@ private: void ComputeImportInfo(std::string const& desired_config, ImportInfo& info) const; - - cmLinkInterface const* - GetImportLinkInterface(const std::string& config, cmTarget const* head, - bool usage_requirements_only) const; - cmLinkImplementationLibraries const* GetLinkImplementationLibrariesInternal(const std::string& config, cmTarget const* head) const; From 8bfb0c53dae93d697ca5d92ff79068af351fe56b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 4 Aug 2015 19:22:30 +0200 Subject: [PATCH 10/22] cmGeneratorTarget: Move link iface helpers from cmTarget. --- Source/cmGeneratorTarget.cxx | 53 +++++++++++++++++++++++++++++++++--- Source/cmGeneratorTarget.h | 8 ++++++ Source/cmTarget.cxx | 45 ------------------------------ Source/cmTarget.h | 8 ------ 4 files changed, 57 insertions(+), 57 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index c966e2480..42508060e 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -3362,6 +3362,51 @@ cmGeneratorTarget::ReportPropertyOrigin(const std::string &p, this->Makefile->GetCMakeInstance()->IssueMessage(cmake::LOG, areport); } +//---------------------------------------------------------------------------- +void cmGeneratorTarget::LookupLinkItems(std::vector const& names, + std::vector& items) const +{ + for(std::vector::const_iterator i = names.begin(); + i != names.end(); ++i) + { + std::string name = this->Target->CheckCMP0004(*i); + if(name == this->GetName() || name.empty()) + { + continue; + } + items.push_back(cmLinkItem(name, this->Target->FindTargetToLink(name))); + } +} + +//---------------------------------------------------------------------------- +void cmGeneratorTarget::ExpandLinkItems(std::string const& prop, + std::string const& value, + std::string const& config, + cmTarget const* headTarget, + bool usage_requirements_only, + std::vector& items, + bool& hadHeadSensitiveCondition) const +{ + cmGeneratorExpression ge; + cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0); + // The $ expression may be in a link interface to specify private + // link dependencies that are otherwise excluded from usage requirements. + if(usage_requirements_only) + { + dagChecker.SetTransitivePropertiesOnly(); + } + std::vector libs; + cmsys::auto_ptr cge = ge.Parse(value); + cmSystemTools::ExpandListArgument(cge->Evaluate( + this->Makefile, + config, + false, + headTarget, + this->Target, &dagChecker), libs); + this->LookupLinkItems(libs, items); + hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition(); +} + //---------------------------------------------------------------------------- cmLinkInterface const* cmGeneratorTarget::GetLinkInterface(const std::string& config, @@ -3644,7 +3689,7 @@ cmGeneratorTarget::ComputeLinkInterfaceLibraries( if(explicitLibraries) { // The interface libraries have been explicitly set. - this->Target->ExpandLinkItems(linkIfaceProp, explicitLibraries, + this->ExpandLinkItems(linkIfaceProp, explicitLibraries, config, headTarget, usage_requirements_only, iface.Libraries, @@ -3673,7 +3718,7 @@ cmGeneratorTarget::ComputeLinkInterfaceLibraries( if(const char* newExplicitLibraries = this->GetProperty(newProp)) { bool hadHeadSensitiveConditionDummy = false; - this->Target->ExpandLinkItems(newProp, newExplicitLibraries, config, + this->ExpandLinkItems(newProp, newExplicitLibraries, config, headTarget, usage_requirements_only, ifaceLibs, hadHeadSensitiveConditionDummy); } @@ -3737,14 +3782,14 @@ cmGeneratorTarget::GetImportLinkInterface(const std::string& config, iface.AllDone = true; iface.Multiplicity = info->Multiplicity; cmSystemTools::ExpandListArgument(info->Languages, iface.Languages); - this->Target->ExpandLinkItems(info->LibrariesProp, info->Libraries, + this->ExpandLinkItems(info->LibrariesProp, info->Libraries, config, headTarget, usage_requirements_only, iface.Libraries, iface.HadHeadSensitiveCondition); std::vector deps; cmSystemTools::ExpandListArgument(info->SharedDeps, deps); - this->Target->LookupLinkItems(deps, iface.SharedDeps); + this->LookupLinkItems(deps, iface.SharedDeps); } return &iface; diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 9c5adf654..2e0d5fe76 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -404,6 +404,14 @@ private: GetImportLinkInterface(const std::string& config, cmTarget const* head, bool usage_requirements_only) const; + void ExpandLinkItems(std::string const& prop, std::string const& value, + std::string const& config, cmTarget const* headTarget, + bool usage_requirements_only, + std::vector& items, + bool& hadHeadSensitiveCondition) const; + void LookupLinkItems(std::vector const& names, + std::vector& items) const; + typedef std::pair OutputNameKey; typedef std::map OutputNameMapType; mutable OutputNameMapType OutputNameMap; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 86285837c..be8d58ea5 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3060,51 +3060,6 @@ bool cmTarget::GetPropertyAsBool(const std::string& prop) const return cmSystemTools::IsOn(this->GetProperty(prop)); } -//---------------------------------------------------------------------------- -void cmTarget::ExpandLinkItems(std::string const& prop, - std::string const& value, - std::string const& config, - cmTarget const* headTarget, - bool usage_requirements_only, - std::vector& items, - bool& hadHeadSensitiveCondition) const -{ - cmGeneratorExpression ge; - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), prop, 0, 0); - // The $ expression may be in a link interface to specify private - // link dependencies that are otherwise excluded from usage requirements. - if(usage_requirements_only) - { - dagChecker.SetTransitivePropertiesOnly(); - } - std::vector libs; - cmsys::auto_ptr cge = ge.Parse(value); - cmSystemTools::ExpandListArgument(cge->Evaluate( - this->Makefile, - config, - false, - headTarget, - this, &dagChecker), libs); - this->LookupLinkItems(libs, items); - hadHeadSensitiveCondition = cge->GetHadHeadSensitiveCondition(); -} - -//---------------------------------------------------------------------------- -void cmTarget::LookupLinkItems(std::vector const& names, - std::vector& items) const -{ - for(std::vector::const_iterator i = names.begin(); - i != names.end(); ++i) - { - std::string name = this->CheckCMP0004(*i); - if(name == this->GetName() || name.empty()) - { - continue; - } - items.push_back(cmLinkItem(name, this->FindTargetToLink(name))); - } -} - //---------------------------------------------------------------------------- const char* cmTarget::GetSuffixVariableInternal(bool implib) const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 25de6a659..103a7e824 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -558,14 +558,6 @@ private: GetLinkImplementationLibrariesInternal(const std::string& config, cmTarget const* head) const; - void ExpandLinkItems(std::string const& prop, std::string const& value, - std::string const& config, cmTarget const* headTarget, - bool usage_requirements_only, - std::vector& items, - bool& hadHeadSensitiveCondition) const; - void LookupLinkItems(std::vector const& names, - std::vector& items) const; - std::string ProcessSourceItemCMP0049(const std::string& s); void ClearLinkMaps(); From e6ccbf6f30fb7b893b00a7c26fa165065eed4323 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 4 Aug 2015 23:14:53 +0200 Subject: [PATCH 11/22] cmGeneratorTarget: Move include directory processing from cmTarget. --- Source/cmGeneratorTarget.cxx | 275 ++++++++++++++++++++++++++- Source/cmGeneratorTarget.h | 5 + Source/cmGhsMultiTargetGenerator.cxx | 2 +- Source/cmTarget.cxx | 234 +---------------------- Source/cmTarget.h | 7 +- 5 files changed, 292 insertions(+), 231 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 42508060e..7ba28633c 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -34,6 +34,18 @@ #define UNORDERED_SET std::set #endif +class cmGeneratorTarget::TargetPropertyEntry { + static cmLinkImplItem NoLinkImplItem; +public: + TargetPropertyEntry(cmsys::auto_ptr cge, + cmLinkImplItem const& item = NoLinkImplItem) + : ge(cge), LinkImplItem(item) + {} + const cmsys::auto_ptr ge; + cmLinkImplItem const& LinkImplItem; +}; +cmLinkImplItem cmGeneratorTarget::TargetPropertyEntry::NoLinkImplItem; + //---------------------------------------------------------------------------- void reportBadObjLib(std::vector const& badObjLib, cmGeneratorTarget const* target, cmake *cm) @@ -227,19 +239,43 @@ struct TagVisitor } }; +void CreatePropertyGeneratorExpressions( + cmStringRange const& entries, + cmBacktraceRange const& backtraces, + std::vector& items, + bool evaluateForBuildsystem = false) +{ + std::vector::const_iterator btIt = backtraces.begin(); + for (std::vector::const_iterator it = entries.begin(); + it != entries.end(); ++it, ++btIt) + { + cmGeneratorExpression ge(*btIt); + cmsys::auto_ptr cge = ge.Parse(*it); + cge->SetEvaluateForBuildsystem(evaluateForBuildsystem); + items.push_back(new cmGeneratorTarget::TargetPropertyEntry(cge)); + } +} + //---------------------------------------------------------------------------- cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) : Target(t), SourceFileFlagsConstructed(false), - PolicyWarnedCMP0022(false) + PolicyWarnedCMP0022(false), + DebugIncludesDone(false) { this->Makefile = this->Target->GetMakefile(); this->LocalGenerator = lg; this->GlobalGenerator = this->LocalGenerator->GetGlobalGenerator(); + + CreatePropertyGeneratorExpressions( + t->GetIncludeDirectoriesEntries(), + t->GetIncludeDirectoriesBacktraces(), + this->IncludeDirectoriesEntries); } cmGeneratorTarget::~cmGeneratorTarget() { + cmDeleteAll(this->IncludeDirectoriesEntries); cmDeleteAll(this->LinkInformation); this->LinkInformation.clear(); } @@ -1964,13 +2000,248 @@ cmGeneratorTarget::GetCreateRuleVariable(std::string const& lang, } return ""; } +//---------------------------------------------------------------------------- +static void processIncludeDirectories(cmGeneratorTarget const* tgt, + const std::vector &entries, + std::vector &includes, + UNORDERED_SET &uniqueIncludes, + cmGeneratorExpressionDAGChecker *dagChecker, + const std::string& config, bool debugIncludes, + const std::string& language) +{ + cmMakefile *mf = tgt->Target->GetMakefile(); + + for (std::vector::const_iterator + it = entries.begin(), end = entries.end(); it != end; ++it) + { + cmLinkImplItem const& item = (*it)->LinkImplItem; + std::string const& targetName = item; + bool const fromImported = item.Target && item.Target->IsImported(); + bool const checkCMP0027 = item.FromGenex; + std::vector entryIncludes; + cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf, + config, + false, + tgt->Target, + dagChecker, language), + entryIncludes); + + std::string usedIncludes; + for(std::vector::iterator + li = entryIncludes.begin(); li != entryIncludes.end(); ++li) + { + if (fromImported + && !cmSystemTools::FileExists(li->c_str())) + { + std::ostringstream e; + cmake::MessageType messageType = cmake::FATAL_ERROR; + if (checkCMP0027) + { + switch(tgt->Target->GetPolicyStatusCMP0027()) + { + case cmPolicies::WARN: + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n"; + case cmPolicies::OLD: + messageType = cmake::AUTHOR_WARNING; + break; + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::NEW: + break; + } + } + e << "Imported target \"" << targetName << "\" includes " + "non-existent path\n \"" << *li << "\"\nin its " + "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n" + "* The path was deleted, renamed, or moved to another " + "location.\n" + "* An install or uninstall procedure did not complete " + "successfully.\n" + "* The installation package was faulty and references files it " + "does not provide.\n"; + tgt->GetLocalGenerator()->IssueMessage(messageType, e.str()); + return; + } + + if (!cmSystemTools::FileIsFullPath(li->c_str())) + { + std::ostringstream e; + bool noMessage = false; + cmake::MessageType messageType = cmake::FATAL_ERROR; + if (!targetName.empty()) + { + e << "Target \"" << targetName << "\" contains relative " + "path in its INTERFACE_INCLUDE_DIRECTORIES:\n" + " \"" << *li << "\""; + } + else + { + switch(tgt->Target->GetPolicyStatusCMP0021()) + { + case cmPolicies::WARN: + { + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n"; + messageType = cmake::AUTHOR_WARNING; + } + break; + case cmPolicies::OLD: + noMessage = true; + case cmPolicies::REQUIRED_IF_USED: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::NEW: + // Issue the fatal message. + break; + } + e << "Found relative path while evaluating include directories of " + "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n"; + } + if (!noMessage) + { + tgt->GetLocalGenerator()->IssueMessage(messageType, e.str()); + if (messageType == cmake::FATAL_ERROR) + { + return; + } + } + } + + if (!cmSystemTools::IsOff(li->c_str())) + { + cmSystemTools::ConvertToUnixSlashes(*li); + } + std::string inc = *li; + + if(uniqueIncludes.insert(inc).second) + { + includes.push_back(inc); + if (debugIncludes) + { + usedIncludes += " * " + inc + "\n"; + } + } + } + if (!usedIncludes.empty()) + { + mf->GetCMakeInstance()->IssueMessage(cmake::LOG, + std::string("Used includes for target ") + + tgt->GetName() + ":\n" + + usedIncludes, (*it)->ge->GetBacktrace()); + } + } +} + + +//---------------------------------------------------------------------------- +static void AddInterfaceEntries( + cmGeneratorTarget const* thisTarget, std::string const& config, + std::string const& prop, + std::vector& entries) +{ + if(cmLinkImplementationLibraries const* impl = + thisTarget->Target->GetLinkImplementationLibraries(config)) + { + for (std::vector::const_iterator + it = impl->Libraries.begin(), end = impl->Libraries.end(); + it != end; ++it) + { + if(it->Target) + { + std::string genex = + "$"; + cmGeneratorExpression ge(it->Backtrace); + cmsys::auto_ptr cge = ge.Parse(genex); + cge->SetEvaluateForBuildsystem(true); + entries.push_back( + new cmGeneratorTarget::TargetPropertyEntry(cge, *it)); + } + } + } +} //---------------------------------------------------------------------------- std::vector cmGeneratorTarget::GetIncludeDirectories(const std::string& config, const std::string& lang) const { - return this->Target->GetIncludeDirectories(config, lang); + std::vector includes; + UNORDERED_SET uniqueIncludes; + + cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), + "INCLUDE_DIRECTORIES", 0, 0); + + std::vector debugProperties; + const char *debugProp = + this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); + if (debugProp) + { + cmSystemTools::ExpandListArgument(debugProp, debugProperties); + } + + bool debugIncludes = !this->DebugIncludesDone + && std::find(debugProperties.begin(), + debugProperties.end(), + "INCLUDE_DIRECTORIES") + != debugProperties.end(); + + if (this->Makefile->IsConfigured()) + { + this->DebugIncludesDone = true; + } + + processIncludeDirectories(this, + this->IncludeDirectoriesEntries, + includes, + uniqueIncludes, + &dagChecker, + config, + debugIncludes, + lang); + + std::vector + linkInterfaceIncludeDirectoriesEntries; + AddInterfaceEntries( + this, config, "INTERFACE_INCLUDE_DIRECTORIES", + linkInterfaceIncludeDirectoriesEntries); + + if(this->Makefile->IsOn("APPLE")) + { + cmLinkImplementationLibraries const* impl = + this->Target->GetLinkImplementationLibraries(config); + for(std::vector::const_iterator + it = impl->Libraries.begin(); + it != impl->Libraries.end(); ++it) + { + std::string libDir = cmSystemTools::CollapseFullPath(*it); + + static cmsys::RegularExpression + frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$"); + if(!frameworkCheck.find(libDir)) + { + continue; + } + + libDir = frameworkCheck.match(1); + + cmGeneratorExpression ge; + cmsys::auto_ptr cge = + ge.Parse(libDir.c_str()); + linkInterfaceIncludeDirectoriesEntries + .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge)); + } + } + + processIncludeDirectories(this, + linkInterfaceIncludeDirectoriesEntries, + includes, + uniqueIncludes, + &dagChecker, + config, + debugIncludes, + lang); + + cmDeleteAll(linkInterfaceIncludeDirectoriesEntries); + + return includes; } //---------------------------------------------------------------------------- diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 2e0d5fe76..513884fd7 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -332,6 +332,8 @@ public: const std::string &report, const std::string &compatibilityType) const; + class TargetPropertyEntry; + private: friend class cmTargetTraceDependencies; struct SourceEntry { std::vector Depends; }; @@ -404,6 +406,8 @@ private: GetImportLinkInterface(const std::string& config, cmTarget const* head, bool usage_requirements_only) const; + std::vector IncludeDirectoriesEntries; + void ExpandLinkItems(std::string const& prop, std::string const& value, std::string const& config, cmTarget const* headTarget, bool usage_requirements_only, @@ -416,6 +420,7 @@ private: typedef std::map OutputNameMapType; mutable OutputNameMapType OutputNameMap; mutable bool PolicyWarnedCMP0022; + mutable bool DebugIncludesDone; public: std::vector const& diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 1e57c3393..7af17cd22 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -343,7 +343,7 @@ void cmGhsMultiTargetGenerator::WriteIncludes(const std::string &config, const std::string &language) { std::vector includes = - this->Target->GetIncludeDirectories(config, language); + this->GeneratorTarget->GetIncludeDirectories(config, language); for (std::vector::const_iterator includes_i = includes.begin(); includes_i != includes.end(); ++includes_i) { diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index be8d58ea5..06d21cc6e 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -139,7 +139,6 @@ public: }; std::vector IncludeDirectoriesEntries; std::vector IncludeDirectoriesBacktraces; - std::vector IncludeDirectoriesItems; std::vector CompileOptionsEntries; std::vector CompileOptionsBacktraces; std::vector CompileOptionsItems; @@ -177,7 +176,6 @@ cmTarget::cmTarget() this->IsApple = false; this->IsImportedTarget = false; this->BuildInterfaceIncludesAppended = false; - this->DebugIncludesDone = false; this->DebugCompileOptionsDone = false; this->DebugCompileFeaturesDone = false; this->DebugCompileDefinitionsDone = false; @@ -425,11 +423,6 @@ void CreatePropertyGeneratorExpressions( void cmTarget::Compute() { - CreatePropertyGeneratorExpressions( - this->Internal->IncludeDirectoriesEntries, - this->Internal->IncludeDirectoriesBacktraces, - this->Internal->IncludeDirectoriesItems); - CreatePropertyGeneratorExpressions( this->Internal->CompileOptionsEntries, this->Internal->CompileOptionsBacktraces, @@ -1319,6 +1312,16 @@ cmTarget::AddSystemIncludeDirectories(const std::set &incs) this->SystemIncludeDirectories.insert(incs.begin(), incs.end()); } +cmStringRange cmTarget::GetIncludeDirectoriesEntries() const +{ + return cmMakeRange(this->Internal->IncludeDirectoriesEntries); +} + +cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const +{ + return cmMakeRange(this->Internal->IncludeDirectoriesBacktraces); +} + #if defined(_WIN32) && !defined(__CYGWIN__) //---------------------------------------------------------------------------- void @@ -1915,222 +1918,6 @@ void cmTarget::InsertCompileDefinition(std::string const& entry, this->Internal->CompileDefinitionsBacktraces.push_back(bt); } -//---------------------------------------------------------------------------- -static void processIncludeDirectories(cmTarget const* tgt, - const std::vector &entries, - std::vector &includes, - UNORDERED_SET &uniqueIncludes, - cmGeneratorExpressionDAGChecker *dagChecker, - const std::string& config, bool debugIncludes, - const std::string& language) -{ - cmMakefile *mf = tgt->GetMakefile(); - - for (std::vector::const_iterator - it = entries.begin(), end = entries.end(); it != end; ++it) - { - cmLinkImplItem const& item = (*it)->LinkImplItem; - std::string const& targetName = item; - bool const fromImported = item.Target && item.Target->IsImported(); - bool const checkCMP0027 = item.FromGenex; - std::vector entryIncludes; - cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf, - config, - false, - tgt, - dagChecker, language), - entryIncludes); - - std::string usedIncludes; - for(std::vector::iterator - li = entryIncludes.begin(); li != entryIncludes.end(); ++li) - { - if (fromImported - && !cmSystemTools::FileExists(li->c_str())) - { - std::ostringstream e; - cmake::MessageType messageType = cmake::FATAL_ERROR; - if (checkCMP0027) - { - switch(tgt->GetPolicyStatusCMP0027()) - { - case cmPolicies::WARN: - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0027) << "\n"; - case cmPolicies::OLD: - messageType = cmake::AUTHOR_WARNING; - break; - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::NEW: - break; - } - } - e << "Imported target \"" << targetName << "\" includes " - "non-existent path\n \"" << *li << "\"\nin its " - "INTERFACE_INCLUDE_DIRECTORIES. Possible reasons include:\n" - "* The path was deleted, renamed, or moved to another " - "location.\n" - "* An install or uninstall procedure did not complete " - "successfully.\n" - "* The installation package was faulty and references files it " - "does not provide.\n"; - tgt->GetMakefile()->IssueMessage(messageType, e.str()); - return; - } - - if (!cmSystemTools::FileIsFullPath(li->c_str())) - { - std::ostringstream e; - bool noMessage = false; - cmake::MessageType messageType = cmake::FATAL_ERROR; - if (!targetName.empty()) - { - e << "Target \"" << targetName << "\" contains relative " - "path in its INTERFACE_INCLUDE_DIRECTORIES:\n" - " \"" << *li << "\""; - } - else - { - switch(tgt->GetPolicyStatusCMP0021()) - { - case cmPolicies::WARN: - { - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0021) << "\n"; - messageType = cmake::AUTHOR_WARNING; - } - break; - case cmPolicies::OLD: - noMessage = true; - case cmPolicies::REQUIRED_IF_USED: - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::NEW: - // Issue the fatal message. - break; - } - e << "Found relative path while evaluating include directories of " - "\"" << tgt->GetName() << "\":\n \"" << *li << "\"\n"; - } - if (!noMessage) - { - tgt->GetMakefile()->IssueMessage(messageType, e.str()); - if (messageType == cmake::FATAL_ERROR) - { - return; - } - } - } - - if (!cmSystemTools::IsOff(li->c_str())) - { - cmSystemTools::ConvertToUnixSlashes(*li); - } - std::string inc = *li; - - if(uniqueIncludes.insert(inc).second) - { - includes.push_back(inc); - if (debugIncludes) - { - usedIncludes += " * " + inc + "\n"; - } - } - } - if (!usedIncludes.empty()) - { - mf->GetCMakeInstance()->IssueMessage(cmake::LOG, - std::string("Used includes for target ") - + tgt->GetName() + ":\n" - + usedIncludes, (*it)->ge->GetBacktrace()); - } - } -} - -//---------------------------------------------------------------------------- -std::vector -cmTarget::GetIncludeDirectories(const std::string& config, - const std::string& language) const -{ - std::vector includes; - UNORDERED_SET uniqueIncludes; - - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), - "INCLUDE_DIRECTORIES", 0, 0); - - std::vector debugProperties; - const char *debugProp = - this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); - if (debugProp) - { - cmSystemTools::ExpandListArgument(debugProp, debugProperties); - } - - bool debugIncludes = !this->DebugIncludesDone - && std::find(debugProperties.begin(), - debugProperties.end(), - "INCLUDE_DIRECTORIES") - != debugProperties.end(); - - if (this->Makefile->IsConfigured()) - { - this->DebugIncludesDone = true; - } - - processIncludeDirectories(this, - this->Internal->IncludeDirectoriesItems, - includes, - uniqueIncludes, - &dagChecker, - config, - debugIncludes, - language); - - std::vector - linkInterfaceIncludeDirectoriesEntries; - this->Internal->AddInterfaceEntries( - this, config, "INTERFACE_INCLUDE_DIRECTORIES", - linkInterfaceIncludeDirectoriesEntries); - - if(this->Makefile->IsOn("APPLE")) - { - cmLinkImplementationLibraries const* impl = - this->GetLinkImplementationLibraries(config); - for(std::vector::const_iterator - it = impl->Libraries.begin(); - it != impl->Libraries.end(); ++it) - { - std::string libDir = cmSystemTools::CollapseFullPath(*it); - - static cmsys::RegularExpression - frameworkCheck("(.*\\.framework)(/Versions/[^/]+)?/[^/]+$"); - if(!frameworkCheck.find(libDir)) - { - continue; - } - - libDir = frameworkCheck.match(1); - - cmGeneratorExpression ge; - cmsys::auto_ptr cge = - ge.Parse(libDir.c_str()); - linkInterfaceIncludeDirectoriesEntries - .push_back(new cmTargetInternals::TargetPropertyEntry(cge)); - } - } - - processIncludeDirectories(this, - linkInterfaceIncludeDirectoriesEntries, - includes, - uniqueIncludes, - &dagChecker, - config, - debugIncludes, - language); - - cmDeleteAll(linkInterfaceIncludeDirectoriesEntries); - - return includes; -} - //---------------------------------------------------------------------------- static void processCompileOptionsInternal(cmTarget const* tgt, const std::vector &entries, @@ -4379,7 +4166,6 @@ cmTargetInternalPointer //---------------------------------------------------------------------------- cmTargetInternalPointer::~cmTargetInternalPointer() { - cmDeleteAll(this->Pointer->IncludeDirectoriesItems); cmDeleteAll(this->Pointer->CompileOptionsItems); cmDeleteAll(this->Pointer->CompileFeaturesItems); cmDeleteAll(this->Pointer->CompileDefinitionsItems); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 103a7e824..13e4f2de0 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -364,9 +364,6 @@ public: /** @return whether this target have a well defined output file name. */ bool HaveWellDefinedOutputFiles() const; - std::vector GetIncludeDirectories( - const std::string& config, - const std::string& language) const; void InsertInclude(std::string const& entry, cmListFileBacktrace const& bt, bool before = false); @@ -402,6 +399,9 @@ public: return this->MaxLanguageStandards; } + cmStringRange GetIncludeDirectoriesEntries() const; + cmBacktraceRange GetIncludeDirectoriesBacktraces() const; + #if defined(_WIN32) && !defined(__CYGWIN__) const LinkLibraryVectorType &GetLinkLibrariesForVS6() const { return this->LinkLibrariesForVS6;} @@ -516,7 +516,6 @@ private: bool IsApple; bool IsImportedTarget; bool BuildInterfaceIncludesAppended; - mutable bool DebugIncludesDone; mutable bool DebugCompileOptionsDone; mutable bool DebugCompileDefinitionsDone; mutable bool DebugSourcesDone; From db4cb92bda8b43c3d66d27533622bb802e823589 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 4 Aug 2015 23:43:56 +0200 Subject: [PATCH 12/22] cmGeneratorTarget: Move compile options processing from cmTarget. --- Source/cmGeneratorTarget.cxx | 128 ++++++++++++++++++++++++++- Source/cmGeneratorTarget.h | 6 ++ Source/cmGhsMultiTargetGenerator.cxx | 4 +- Source/cmLocalGenerator.cxx | 8 +- Source/cmTarget.cxx | 89 +++---------------- Source/cmTarget.h | 7 +- 6 files changed, 154 insertions(+), 88 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 7ba28633c..77e352f56 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -261,7 +261,8 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) : Target(t), SourceFileFlagsConstructed(false), PolicyWarnedCMP0022(false), - DebugIncludesDone(false) + DebugIncludesDone(false), + DebugCompileOptionsDone(false) { this->Makefile = this->Target->GetMakefile(); this->LocalGenerator = lg; @@ -271,11 +272,17 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) t->GetIncludeDirectoriesEntries(), t->GetIncludeDirectoriesBacktraces(), this->IncludeDirectoriesEntries); + + CreatePropertyGeneratorExpressions( + t->GetCompileOptionsEntries(), + t->GetCompileOptionsBacktraces(), + this->CompileOptionsEntries); } cmGeneratorTarget::~cmGeneratorTarget() { cmDeleteAll(this->IncludeDirectoriesEntries); + cmDeleteAll(this->CompileOptionsEntries); cmDeleteAll(this->LinkInformation); this->LinkInformation.clear(); } @@ -2244,6 +2251,125 @@ cmGeneratorTarget::GetIncludeDirectories(const std::string& config, return includes; } +//---------------------------------------------------------------------------- +static void processCompileOptionsInternal(cmGeneratorTarget const* tgt, + const std::vector &entries, + std::vector &options, + UNORDERED_SET &uniqueOptions, + cmGeneratorExpressionDAGChecker *dagChecker, + const std::string& config, bool debugOptions, const char *logName, + std::string const& language) +{ + cmMakefile *mf = tgt->Target->GetMakefile(); + + for (std::vector::const_iterator + it = entries.begin(), end = entries.end(); it != end; ++it) + { + std::vector entryOptions; + cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf, + config, + false, + tgt->Target, + dagChecker, + language), + entryOptions); + std::string usedOptions; + for(std::vector::iterator + li = entryOptions.begin(); li != entryOptions.end(); ++li) + { + std::string const& opt = *li; + + if(uniqueOptions.insert(opt).second) + { + options.push_back(opt); + if (debugOptions) + { + usedOptions += " * " + opt + "\n"; + } + } + } + if (!usedOptions.empty()) + { + mf->GetCMakeInstance()->IssueMessage(cmake::LOG, + std::string("Used compile ") + logName + + std::string(" for target ") + + tgt->GetName() + ":\n" + + usedOptions, (*it)->ge->GetBacktrace()); + } + } +} + +//---------------------------------------------------------------------------- +static void processCompileOptions(cmGeneratorTarget const* tgt, + const std::vector &entries, + std::vector &options, + UNORDERED_SET &uniqueOptions, + cmGeneratorExpressionDAGChecker *dagChecker, + const std::string& config, bool debugOptions, + std::string const& language) +{ + processCompileOptionsInternal(tgt, entries, options, uniqueOptions, + dagChecker, config, debugOptions, "options", + language); +} + +//---------------------------------------------------------------------------- +void cmGeneratorTarget::GetCompileOptions(std::vector &result, + const std::string& config, + const std::string& language) const +{ + UNORDERED_SET uniqueOptions; + + cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), + "COMPILE_OPTIONS", 0, 0); + + std::vector debugProperties; + const char *debugProp = + this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); + if (debugProp) + { + cmSystemTools::ExpandListArgument(debugProp, debugProperties); + } + + bool debugOptions = !this->DebugCompileOptionsDone + && std::find(debugProperties.begin(), + debugProperties.end(), + "COMPILE_OPTIONS") + != debugProperties.end(); + + if (this->Makefile->IsConfigured()) + { + this->DebugCompileOptionsDone = true; + } + + processCompileOptions(this, + this->CompileOptionsEntries, + result, + uniqueOptions, + &dagChecker, + config, + debugOptions, + language); + + std::vector + linkInterfaceCompileOptionsEntries; + + AddInterfaceEntries( + this, config, "INTERFACE_COMPILE_OPTIONS", + linkInterfaceCompileOptionsEntries); + + processCompileOptions(this, + linkInterfaceCompileOptionsEntries, + result, + uniqueOptions, + &dagChecker, + config, + debugOptions, + language); + + cmDeleteAll(linkInterfaceCompileOptionsEntries); +} + //---------------------------------------------------------------------------- void cmGeneratorTarget::GenerateTargetManifest( const std::string& config) const diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 513884fd7..1fb8cfe05 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -217,6 +217,10 @@ public: std::vector GetIncludeDirectories( const std::string& config, const std::string& lang) const; + void GetCompileOptions(std::vector &result, + const std::string& config, + const std::string& language) const; + bool IsSystemIncludeDirectory(const std::string& dir, const std::string& config) const; @@ -407,6 +411,7 @@ private: bool usage_requirements_only) const; std::vector IncludeDirectoriesEntries; + std::vector CompileOptionsEntries; void ExpandLinkItems(std::string const& prop, std::string const& value, std::string const& config, cmTarget const* headTarget, @@ -421,6 +426,7 @@ private: mutable OutputNameMapType OutputNameMap; mutable bool PolicyWarnedCMP0022; mutable bool DebugIncludesDone; + mutable bool DebugCompileOptionsDone; public: std::vector const& diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 7af17cd22..790e68b2a 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -558,7 +558,7 @@ bool cmGhsMultiTargetGenerator::IsNotKernel(std::string const &config, { bool output; std::vector options; - this->Target->GetCompileOptions(options, config, language); + this->GeneratorTarget->GetCompileOptions(options, config, language); output = options.end() == std::find(options.begin(), options.end(), "-kernel"); return output; @@ -587,7 +587,7 @@ bool cmGhsMultiTargetGenerator::DetermineIfDynamicDownload( { std::vector options; bool output = false; - this->Target->GetCompileOptions(options, config, language); + this->GeneratorTarget->GetCompileOptions(options, config, language); for (std::vector::const_iterator options_i = options.begin(); options_i != options.end(); ++options_i) { diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index edb644de7..89515ffa0 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1094,6 +1094,10 @@ void cmLocalGenerator::AddCompileOptions( ) { std::string langFlagRegexVar = std::string("CMAKE_")+lang+"_FLAG_REGEX"; + + cmGeneratorTarget* gtgt = + this->GlobalGenerator->GetGeneratorTarget(target); + if(const char* langFlagRegexStr = this->Makefile->GetDefinition(langFlagRegexVar)) { @@ -1104,7 +1108,7 @@ void cmLocalGenerator::AddCompileOptions( { cmSystemTools::ParseWindowsCommandLine(targetFlags, opts); } - target->GetCompileOptions(opts, config, lang); + gtgt->GetCompileOptions(opts, config, lang); for(std::vector::const_iterator i = opts.begin(); i != opts.end(); ++i) { @@ -1125,7 +1129,7 @@ void cmLocalGenerator::AddCompileOptions( this->AppendFlags(flags, targetFlags); } std::vector opts; - target->GetCompileOptions(opts, config, lang); + gtgt->GetCompileOptions(opts, config, lang); for(std::vector::const_iterator i = opts.begin(); i != opts.end(); ++i) { diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 06d21cc6e..9e13ea04f 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -141,7 +141,6 @@ public: std::vector IncludeDirectoriesBacktraces; std::vector CompileOptionsEntries; std::vector CompileOptionsBacktraces; - std::vector CompileOptionsItems; std::vector CompileFeaturesEntries; std::vector CompileFeaturesBacktraces; std::vector CompileFeaturesItems; @@ -176,7 +175,6 @@ cmTarget::cmTarget() this->IsApple = false; this->IsImportedTarget = false; this->BuildInterfaceIncludesAppended = false; - this->DebugCompileOptionsDone = false; this->DebugCompileFeaturesDone = false; this->DebugCompileDefinitionsDone = false; this->DebugSourcesDone = false; @@ -423,11 +421,6 @@ void CreatePropertyGeneratorExpressions( void cmTarget::Compute() { - CreatePropertyGeneratorExpressions( - this->Internal->CompileOptionsEntries, - this->Internal->CompileOptionsBacktraces, - this->Internal->CompileOptionsItems); - CreatePropertyGeneratorExpressions( this->Internal->CompileFeaturesEntries, this->Internal->CompileFeaturesBacktraces, @@ -1322,6 +1315,16 @@ cmBacktraceRange cmTarget::GetIncludeDirectoriesBacktraces() const return cmMakeRange(this->Internal->IncludeDirectoriesBacktraces); } +cmStringRange cmTarget::GetCompileOptionsEntries() const +{ + return cmMakeRange(this->Internal->CompileOptionsEntries); +} + +cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const +{ + return cmMakeRange(this->Internal->CompileOptionsBacktraces); +} + #if defined(_WIN32) && !defined(__CYGWIN__) //---------------------------------------------------------------------------- void @@ -1966,77 +1969,6 @@ static void processCompileOptionsInternal(cmTarget const* tgt, } } -//---------------------------------------------------------------------------- -static void processCompileOptions(cmTarget const* tgt, - const std::vector &entries, - std::vector &options, - UNORDERED_SET &uniqueOptions, - cmGeneratorExpressionDAGChecker *dagChecker, - const std::string& config, bool debugOptions, - std::string const& language) -{ - processCompileOptionsInternal(tgt, entries, options, uniqueOptions, - dagChecker, config, debugOptions, "options", - language); -} - -//---------------------------------------------------------------------------- -void cmTarget::GetCompileOptions(std::vector &result, - const std::string& config, - const std::string& language) const -{ - UNORDERED_SET uniqueOptions; - - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), - "COMPILE_OPTIONS", 0, 0); - - std::vector debugProperties; - const char *debugProp = - this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); - if (debugProp) - { - cmSystemTools::ExpandListArgument(debugProp, debugProperties); - } - - bool debugOptions = !this->DebugCompileOptionsDone - && std::find(debugProperties.begin(), - debugProperties.end(), - "COMPILE_OPTIONS") - != debugProperties.end(); - - if (this->Makefile->IsConfigured()) - { - this->DebugCompileOptionsDone = true; - } - - processCompileOptions(this, - this->Internal->CompileOptionsItems, - result, - uniqueOptions, - &dagChecker, - config, - debugOptions, - language); - - std::vector - linkInterfaceCompileOptionsEntries; - - this->Internal->AddInterfaceEntries( - this, config, "INTERFACE_COMPILE_OPTIONS", - linkInterfaceCompileOptionsEntries); - - processCompileOptions(this, - linkInterfaceCompileOptionsEntries, - result, - uniqueOptions, - &dagChecker, - config, - debugOptions, - language); - - cmDeleteAll(linkInterfaceCompileOptionsEntries); -} - //---------------------------------------------------------------------------- static void processCompileDefinitions(cmTarget const* tgt, const std::vector &entries, @@ -4166,7 +4098,6 @@ cmTargetInternalPointer //---------------------------------------------------------------------------- cmTargetInternalPointer::~cmTargetInternalPointer() { - cmDeleteAll(this->Pointer->CompileOptionsItems); cmDeleteAll(this->Pointer->CompileFeaturesItems); cmDeleteAll(this->Pointer->CompileDefinitionsItems); cmDeleteAll(this->Pointer->SourceEntries); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 13e4f2de0..05b6aec6d 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -375,9 +375,6 @@ public: void AppendBuildInterfaceIncludes(); - void GetCompileOptions(std::vector &result, - const std::string& config, - const std::string& language) const; void GetCompileFeatures(std::vector &features, const std::string& config) const; @@ -402,6 +399,9 @@ public: cmStringRange GetIncludeDirectoriesEntries() const; cmBacktraceRange GetIncludeDirectoriesBacktraces() const; + cmStringRange GetCompileOptionsEntries() const; + cmBacktraceRange GetCompileOptionsBacktraces() const; + #if defined(_WIN32) && !defined(__CYGWIN__) const LinkLibraryVectorType &GetLinkLibrariesForVS6() const { return this->LinkLibrariesForVS6;} @@ -516,7 +516,6 @@ private: bool IsApple; bool IsImportedTarget; bool BuildInterfaceIncludesAppended; - mutable bool DebugCompileOptionsDone; mutable bool DebugCompileDefinitionsDone; mutable bool DebugSourcesDone; mutable bool DebugCompileFeaturesDone; From d051086ccec5cd4b381cf47afb0e7fe962ed4c0b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 4 Aug 2015 23:48:58 +0200 Subject: [PATCH 13/22] cmGeneratorTarget: Move compile features processing from cmTarget. --- Source/cmGeneratorTarget.cxx | 76 +++++++++++++++++++++++++++++++- Source/cmGeneratorTarget.h | 5 +++ Source/cmLocalGenerator.cxx | 2 +- Source/cmTarget.cxx | 85 +++++------------------------------- Source/cmTarget.h | 7 ++- 5 files changed, 94 insertions(+), 81 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 77e352f56..5a67c1590 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -262,7 +262,8 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) SourceFileFlagsConstructed(false), PolicyWarnedCMP0022(false), DebugIncludesDone(false), - DebugCompileOptionsDone(false) + DebugCompileOptionsDone(false), + DebugCompileFeaturesDone(false) { this->Makefile = this->Target->GetMakefile(); this->LocalGenerator = lg; @@ -277,12 +278,18 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) t->GetCompileOptionsEntries(), t->GetCompileOptionsBacktraces(), this->CompileOptionsEntries); + + CreatePropertyGeneratorExpressions( + t->GetCompileFeaturesEntries(), + t->GetCompileFeaturesBacktraces(), + this->CompileFeaturesEntries); } cmGeneratorTarget::~cmGeneratorTarget() { cmDeleteAll(this->IncludeDirectoriesEntries); cmDeleteAll(this->CompileOptionsEntries); + cmDeleteAll(this->CompileFeaturesEntries); cmDeleteAll(this->LinkInformation); this->LinkInformation.clear(); } @@ -2370,6 +2377,73 @@ void cmGeneratorTarget::GetCompileOptions(std::vector &result, cmDeleteAll(linkInterfaceCompileOptionsEntries); } +//---------------------------------------------------------------------------- +static void processCompileFeatures(cmGeneratorTarget const* tgt, + const std::vector &entries, + std::vector &options, + UNORDERED_SET &uniqueOptions, + cmGeneratorExpressionDAGChecker *dagChecker, + const std::string& config, bool debugOptions) +{ + processCompileOptionsInternal(tgt, entries, options, uniqueOptions, + dagChecker, config, debugOptions, "features", + std::string()); +} + +//---------------------------------------------------------------------------- +void cmGeneratorTarget::GetCompileFeatures(std::vector &result, + const std::string& config) const +{ + UNORDERED_SET uniqueFeatures; + + cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), + "COMPILE_FEATURES", + 0, 0); + + std::vector debugProperties; + const char *debugProp = + this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); + if (debugProp) + { + cmSystemTools::ExpandListArgument(debugProp, debugProperties); + } + + bool debugFeatures = !this->DebugCompileFeaturesDone + && std::find(debugProperties.begin(), + debugProperties.end(), + "COMPILE_FEATURES") + != debugProperties.end(); + + if (this->Makefile->IsConfigured()) + { + this->DebugCompileFeaturesDone = true; + } + + processCompileFeatures(this, + this->CompileFeaturesEntries, + result, + uniqueFeatures, + &dagChecker, + config, + debugFeatures); + + std::vector + linkInterfaceCompileFeaturesEntries; + AddInterfaceEntries( + this, config, "INTERFACE_COMPILE_FEATURES", + linkInterfaceCompileFeaturesEntries); + + processCompileFeatures(this, + linkInterfaceCompileFeaturesEntries, + result, + uniqueFeatures, + &dagChecker, + config, + debugFeatures); + + cmDeleteAll(linkInterfaceCompileFeaturesEntries); +} + //---------------------------------------------------------------------------- void cmGeneratorTarget::GenerateTargetManifest( const std::string& config) const diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 1fb8cfe05..7e718af7d 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -221,6 +221,9 @@ public: const std::string& config, const std::string& language) const; + void GetCompileFeatures(std::vector &features, + const std::string& config) const; + bool IsSystemIncludeDirectory(const std::string& dir, const std::string& config) const; @@ -412,6 +415,7 @@ private: std::vector IncludeDirectoriesEntries; std::vector CompileOptionsEntries; + std::vector CompileFeaturesEntries; void ExpandLinkItems(std::string const& prop, std::string const& value, std::string const& config, cmTarget const* headTarget, @@ -427,6 +431,7 @@ private: mutable bool PolicyWarnedCMP0022; mutable bool DebugIncludesDone; mutable bool DebugCompileOptionsDone; + mutable bool DebugCompileFeaturesDone; public: std::vector const& diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 89515ffa0..a7e41912a 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1138,7 +1138,7 @@ void cmLocalGenerator::AddCompileOptions( } } std::vector features; - target->GetCompileFeatures(features, config); + gtgt->GetCompileFeatures(features, config); for(std::vector::const_iterator it = features.begin(); it != features.end(); ++it) { diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 9e13ea04f..4ddbcb368 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -143,7 +143,6 @@ public: std::vector CompileOptionsBacktraces; std::vector CompileFeaturesEntries; std::vector CompileFeaturesBacktraces; - std::vector CompileFeaturesItems; std::vector CompileDefinitionsEntries; std::vector CompileDefinitionsBacktraces; std::vector CompileDefinitionsItems; @@ -175,7 +174,6 @@ cmTarget::cmTarget() this->IsApple = false; this->IsImportedTarget = false; this->BuildInterfaceIncludesAppended = false; - this->DebugCompileFeaturesDone = false; this->DebugCompileDefinitionsDone = false; this->DebugSourcesDone = false; this->LinkImplementationLanguageIsContextDependent = true; @@ -421,11 +419,6 @@ void CreatePropertyGeneratorExpressions( void cmTarget::Compute() { - CreatePropertyGeneratorExpressions( - this->Internal->CompileFeaturesEntries, - this->Internal->CompileFeaturesBacktraces, - this->Internal->CompileFeaturesItems); - CreatePropertyGeneratorExpressions( this->Internal->CompileDefinitionsEntries, this->Internal->CompileDefinitionsBacktraces, @@ -1325,6 +1318,16 @@ cmBacktraceRange cmTarget::GetCompileOptionsBacktraces() const return cmMakeRange(this->Internal->CompileOptionsBacktraces); } +cmStringRange cmTarget::GetCompileFeaturesEntries() const +{ + return cmMakeRange(this->Internal->CompileFeaturesEntries); +} + +cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const +{ + return cmMakeRange(this->Internal->CompileFeaturesBacktraces); +} + #if defined(_WIN32) && !defined(__CYGWIN__) //---------------------------------------------------------------------------- void @@ -2071,73 +2074,6 @@ void cmTarget::GetCompileDefinitions(std::vector &list, cmDeleteAll(linkInterfaceCompileDefinitionsEntries); } -//---------------------------------------------------------------------------- -static void processCompileFeatures(cmTarget const* tgt, - const std::vector &entries, - std::vector &options, - UNORDERED_SET &uniqueOptions, - cmGeneratorExpressionDAGChecker *dagChecker, - const std::string& config, bool debugOptions) -{ - processCompileOptionsInternal(tgt, entries, options, uniqueOptions, - dagChecker, config, debugOptions, "features", - std::string()); -} - -//---------------------------------------------------------------------------- -void cmTarget::GetCompileFeatures(std::vector &result, - const std::string& config) const -{ - UNORDERED_SET uniqueFeatures; - - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), - "COMPILE_FEATURES", - 0, 0); - - std::vector debugProperties; - const char *debugProp = - this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); - if (debugProp) - { - cmSystemTools::ExpandListArgument(debugProp, debugProperties); - } - - bool debugFeatures = !this->DebugCompileFeaturesDone - && std::find(debugProperties.begin(), - debugProperties.end(), - "COMPILE_FEATURES") - != debugProperties.end(); - - if (this->Makefile->IsConfigured()) - { - this->DebugCompileFeaturesDone = true; - } - - processCompileFeatures(this, - this->Internal->CompileFeaturesItems, - result, - uniqueFeatures, - &dagChecker, - config, - debugFeatures); - - std::vector - linkInterfaceCompileFeaturesEntries; - this->Internal->AddInterfaceEntries( - this, config, "INTERFACE_COMPILE_FEATURES", - linkInterfaceCompileFeaturesEntries); - - processCompileFeatures(this, - linkInterfaceCompileFeaturesEntries, - result, - uniqueFeatures, - &dagChecker, - config, - debugFeatures); - - cmDeleteAll(linkInterfaceCompileFeaturesEntries); -} - //---------------------------------------------------------------------------- void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop) { @@ -4098,7 +4034,6 @@ cmTargetInternalPointer //---------------------------------------------------------------------------- cmTargetInternalPointer::~cmTargetInternalPointer() { - cmDeleteAll(this->Pointer->CompileFeaturesItems); cmDeleteAll(this->Pointer->CompileDefinitionsItems); cmDeleteAll(this->Pointer->SourceEntries); delete this->Pointer; diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 05b6aec6d..aae558e74 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -375,9 +375,6 @@ public: void AppendBuildInterfaceIncludes(); - void GetCompileFeatures(std::vector &features, - const std::string& config) const; - bool IsNullImpliedByLinkLibraries(const std::string &p) const; std::string GetDebugGeneratorExpressions(const std::string &value, @@ -402,6 +399,9 @@ public: cmStringRange GetCompileOptionsEntries() const; cmBacktraceRange GetCompileOptionsBacktraces() const; + cmStringRange GetCompileFeaturesEntries() const; + cmBacktraceRange GetCompileFeaturesBacktraces() const; + #if defined(_WIN32) && !defined(__CYGWIN__) const LinkLibraryVectorType &GetLinkLibrariesForVS6() const { return this->LinkLibrariesForVS6;} @@ -518,7 +518,6 @@ private: bool BuildInterfaceIncludesAppended; mutable bool DebugCompileDefinitionsDone; mutable bool DebugSourcesDone; - mutable bool DebugCompileFeaturesDone; mutable bool LinkImplementationLanguageIsContextDependent; #if defined(_WIN32) && !defined(__CYGWIN__) bool LinkLibrariesForVS6Analyzed; From a7f5d70dde50ac74726f3c23d276d2fdac70d659 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 00:00:53 +0200 Subject: [PATCH 14/22] cmGeneratorTarget: Move compile defintions processing from cmTarget. --- Source/cmExtraCodeBlocksGenerator.cxx | 2 +- Source/cmGeneratorTarget.cxx | 111 ++++++++++++- Source/cmGeneratorTarget.h | 6 + Source/cmGhsMultiTargetGenerator.cxx | 3 +- Source/cmGlobalGenerator.cxx | 1 - Source/cmGlobalVisualStudio8Generator.cxx | 2 +- Source/cmGlobalVisualStudioGenerator.cxx | 2 +- Source/cmGlobalXCodeGenerator.cxx | 6 +- Source/cmLocalGenerator.cxx | 3 +- Source/cmLocalVisualStudio7Generator.cxx | 2 +- Source/cmQtAutoGenerators.cxx | 2 - Source/cmTarget.cxx | 171 ++------------------- Source/cmTarget.h | 10 +- Source/cmVisualStudio10TargetGenerator.cxx | 2 +- 14 files changed, 141 insertions(+), 182 deletions(-) diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index 933a256af..dfd51c754 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -609,7 +609,7 @@ void cmExtraCodeBlocksGenerator::AppendTarget(cmGeneratedFileStream& fout, // the compilerdefines for this target std::vector cdefs; - target->GetCompileDefinitions(cdefs, buildType, "C"); + gtgt->GetCompileDefinitions(cdefs, buildType, "C"); // Expand the list. for(std::vector::const_iterator di = cdefs.begin(); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 5a67c1590..c499cd9d0 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -263,7 +263,8 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) PolicyWarnedCMP0022(false), DebugIncludesDone(false), DebugCompileOptionsDone(false), - DebugCompileFeaturesDone(false) + DebugCompileFeaturesDone(false), + DebugCompileDefinitionsDone(false) { this->Makefile = this->Target->GetMakefile(); this->LocalGenerator = lg; @@ -283,6 +284,11 @@ cmGeneratorTarget::cmGeneratorTarget(cmTarget* t, cmLocalGenerator* lg) t->GetCompileFeaturesEntries(), t->GetCompileFeaturesBacktraces(), this->CompileFeaturesEntries); + + CreatePropertyGeneratorExpressions( + t->GetCompileDefinitionsEntries(), + t->GetCompileDefinitionsBacktraces(), + this->CompileDefinitionsEntries); } cmGeneratorTarget::~cmGeneratorTarget() @@ -290,6 +296,7 @@ cmGeneratorTarget::~cmGeneratorTarget() cmDeleteAll(this->IncludeDirectoriesEntries); cmDeleteAll(this->CompileOptionsEntries); cmDeleteAll(this->CompileFeaturesEntries); + cmDeleteAll(this->CompileDefinitionsEntries); cmDeleteAll(this->LinkInformation); this->LinkInformation.clear(); } @@ -2444,6 +2451,108 @@ void cmGeneratorTarget::GetCompileFeatures(std::vector &result, cmDeleteAll(linkInterfaceCompileFeaturesEntries); } +//---------------------------------------------------------------------------- +static void processCompileDefinitions(cmGeneratorTarget const* tgt, + const std::vector &entries, + std::vector &options, + UNORDERED_SET &uniqueOptions, + cmGeneratorExpressionDAGChecker *dagChecker, + const std::string& config, bool debugOptions, + std::string const& language) +{ + processCompileOptionsInternal(tgt, entries, options, uniqueOptions, + dagChecker, config, debugOptions, + "definitions", language); +} + +//---------------------------------------------------------------------------- +void cmGeneratorTarget::GetCompileDefinitions(std::vector &list, + const std::string& config, + const std::string& language) const +{ + UNORDERED_SET uniqueOptions; + + cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), + "COMPILE_DEFINITIONS", 0, 0); + + std::vector debugProperties; + const char *debugProp = + this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); + if (debugProp) + { + cmSystemTools::ExpandListArgument(debugProp, debugProperties); + } + + bool debugDefines = !this->DebugCompileDefinitionsDone + && std::find(debugProperties.begin(), + debugProperties.end(), + "COMPILE_DEFINITIONS") + != debugProperties.end(); + + if (this->Makefile->IsConfigured()) + { + this->DebugCompileDefinitionsDone = true; + } + + processCompileDefinitions(this, + this->CompileDefinitionsEntries, + list, + uniqueOptions, + &dagChecker, + config, + debugDefines, + language); + + std::vector + linkInterfaceCompileDefinitionsEntries; + AddInterfaceEntries( + this, config, "INTERFACE_COMPILE_DEFINITIONS", + linkInterfaceCompileDefinitionsEntries); + if (!config.empty()) + { + std::string configPropName = "COMPILE_DEFINITIONS_" + + cmSystemTools::UpperCase(config); + const char *configProp = this->Target->GetProperty(configPropName); + if (configProp) + { + switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) + { + case cmPolicies::WARN: + { + std::ostringstream e; + e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043); + this->LocalGenerator->IssueMessage(cmake::AUTHOR_WARNING, + e.str()); + } + case cmPolicies::OLD: + { + cmGeneratorExpression ge; + cmsys::auto_ptr cge = + ge.Parse(configProp); + linkInterfaceCompileDefinitionsEntries + .push_back(new cmGeneratorTarget::TargetPropertyEntry(cge)); + } + break; + case cmPolicies::NEW: + case cmPolicies::REQUIRED_ALWAYS: + case cmPolicies::REQUIRED_IF_USED: + break; + } + } + } + + processCompileDefinitions(this, + linkInterfaceCompileDefinitionsEntries, + list, + uniqueOptions, + &dagChecker, + config, + debugDefines, + language); + + cmDeleteAll(linkInterfaceCompileDefinitionsEntries); +} + //---------------------------------------------------------------------------- void cmGeneratorTarget::GenerateTargetManifest( const std::string& config) const diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 7e718af7d..557eb1782 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -224,6 +224,10 @@ public: void GetCompileFeatures(std::vector &features, const std::string& config) const; + void GetCompileDefinitions(std::vector &result, + const std::string& config, + const std::string& language) const; + bool IsSystemIncludeDirectory(const std::string& dir, const std::string& config) const; @@ -416,6 +420,7 @@ private: std::vector IncludeDirectoriesEntries; std::vector CompileOptionsEntries; std::vector CompileFeaturesEntries; + std::vector CompileDefinitionsEntries; void ExpandLinkItems(std::string const& prop, std::string const& value, std::string const& config, cmTarget const* headTarget, @@ -432,6 +437,7 @@ private: mutable bool DebugIncludesDone; mutable bool DebugCompileOptionsDone; mutable bool DebugCompileFeaturesDone; + mutable bool DebugCompileDefinitionsDone; public: std::vector const& diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 790e68b2a..846b6e2f8 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -330,7 +330,8 @@ void cmGhsMultiTargetGenerator::WriteCompilerDefinitions( const std::string &config, const std::string &language) { std::vector compileDefinitions; - this->Target->GetCompileDefinitions(compileDefinitions, config, language); + this->GeneratorTarget->GetCompileDefinitions(compileDefinitions, + config, language); for (std::vector::const_iterator cdI = compileDefinitions.begin(); cdI != compileDefinitions.end(); ++cdI) diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 503c455f9..c0f1817a5 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -1550,7 +1550,6 @@ void cmGlobalGenerator::CreateGeneratorTargets(TargetTypes targetTypes, ti != targets.end(); ++ti) { cmTarget* t = &ti->second; - t->Compute(); cmGeneratorTarget* gt = new cmGeneratorTarget(t, lg); this->GeneratorTargets[t] = gt; generatorTargets[t] = gt; diff --git a/Source/cmGlobalVisualStudio8Generator.cxx b/Source/cmGlobalVisualStudio8Generator.cxx index 51dcab06b..28f0425d0 100644 --- a/Source/cmGlobalVisualStudio8Generator.cxx +++ b/Source/cmGlobalVisualStudio8Generator.cxx @@ -254,7 +254,7 @@ bool cmGlobalVisualStudio8Generator::AddCheckTarget() mf->AddUtilityCommand(CMAKE_CHECK_BUILD_SYSTEM_TARGET, false, no_working_directory, no_depends, noCommandLines); - tgt->Compute(); + cmGeneratorTarget* gt = new cmGeneratorTarget(tgt, lg); mf->AddGeneratorTarget(tgt, gt); diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index b0aa243dc..634366e12 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -90,7 +90,7 @@ bool cmGlobalVisualStudioGenerator::Compute() AddUtilityCommand("ALL_BUILD", true, no_working_dir, no_depends, no_commands, false, "Build all projects"); - allBuild->Compute(); + cmGeneratorTarget* gt = new cmGeneratorTarget(allBuild, gen[0]); allBuild->GetMakefile()->AddGeneratorTarget(allBuild, gt); diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 4ba29f50f..87c61dd25 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -463,7 +463,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root, cmTarget* allbuild = mf->AddUtilityCommand("ALL_BUILD", true, no_depends, no_working_directory, "echo", "Build all projects"); - allbuild->Compute(); + cmGeneratorTarget* allBuildGt = new cmGeneratorTarget(allbuild, root); mf->AddGeneratorTarget(allbuild, allBuildGt); @@ -498,7 +498,7 @@ cmGlobalXCodeGenerator::AddExtraTargets(cmLocalGenerator* root, true, no_depends, no_working_directory, "make", "-f", file.c_str()); - check->Compute(); + cmGeneratorTarget* checkGt = new cmGeneratorTarget(check, root); mf->AddGeneratorTarget(check, checkGt); } @@ -1855,7 +1855,7 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, this->AppendDefines(ppDefs, exportMacro); } std::vector targetDefines; - target.GetCompileDefinitions(targetDefines, configName, "C"); + gtgt->GetCompileDefinitions(targetDefines, configName, "C"); this->AppendDefines(ppDefs, targetDefines); buildSettings->AddAttribute ("GCC_PREPROCESSOR_DEFINITIONS", ppDefs.CreateList()); diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index a7e41912a..c1cc241d1 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1083,7 +1083,8 @@ void cmLocalGenerator::AddCompileDefinitions(std::set& defines, const std::string& lang) { std::vector targetDefines; - target->GetCompileDefinitions(targetDefines, config, lang); + cmGeneratorTarget* gtgt = this->GlobalGenerator->GetGeneratorTarget(target); + gtgt->GetCompileDefinitions(targetDefines, config, lang); this->AppendDefines(defines, targetDefines); } diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 5de6d37a2..f17c9a4c6 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -763,7 +763,7 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, targetOptions.Parse(defineFlags.c_str()); targetOptions.ParseFinish(); std::vector targetDefines; - target.GetCompileDefinitions(targetDefines, configName, "CXX"); + gt->GetCompileDefinitions(targetDefines, configName, "CXX"); targetOptions.AddDefines(targetDefines); targetOptions.SetVerboseMakefile( this->Makefile->IsOn("CMAKE_VERBOSE_MAKEFILE")); diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index f85e70e64..c58e7e4f3 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -474,8 +474,6 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmLocalGenerator* lg, /*byproducts=*/rcc_output, depends, commandLines, false, autogenComment.c_str()); - autogenTarget->Compute(); - cmGeneratorTarget* gt = new cmGeneratorTarget(autogenTarget, lg); makefile->AddGeneratorTarget(autogenTarget, gt); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 4ddbcb368..ea03ffe20 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -145,7 +145,6 @@ public: std::vector CompileFeaturesBacktraces; std::vector CompileDefinitionsEntries; std::vector CompileDefinitionsBacktraces; - std::vector CompileDefinitionsItems; std::vector SourceEntries; std::vector LinkImplementationPropertyEntries; @@ -174,7 +173,6 @@ cmTarget::cmTarget() this->IsApple = false; this->IsImportedTarget = false; this->BuildInterfaceIncludesAppended = false; - this->DebugCompileDefinitionsDone = false; this->DebugSourcesDone = false; this->LinkImplementationLanguageIsContextDependent = true; } @@ -417,14 +415,6 @@ void CreatePropertyGeneratorExpressions( } } -void cmTarget::Compute() -{ - CreatePropertyGeneratorExpressions( - this->Internal->CompileDefinitionsEntries, - this->Internal->CompileDefinitionsBacktraces, - this->Internal->CompileDefinitionsItems); -} - //---------------------------------------------------------------------------- void cmTarget::AddUtility(const std::string& u, cmMakefile *makefile) { @@ -1328,6 +1318,16 @@ cmBacktraceRange cmTarget::GetCompileFeaturesBacktraces() const return cmMakeRange(this->Internal->CompileFeaturesBacktraces); } +cmStringRange cmTarget::GetCompileDefinitionsEntries() const +{ + return cmMakeRange(this->Internal->CompileDefinitionsEntries); +} + +cmBacktraceRange cmTarget::GetCompileDefinitionsBacktraces() const +{ + return cmMakeRange(this->Internal->CompileDefinitionsBacktraces); +} + #if defined(_WIN32) && !defined(__CYGWIN__) //---------------------------------------------------------------------------- void @@ -1924,156 +1924,6 @@ void cmTarget::InsertCompileDefinition(std::string const& entry, this->Internal->CompileDefinitionsBacktraces.push_back(bt); } -//---------------------------------------------------------------------------- -static void processCompileOptionsInternal(cmTarget const* tgt, - const std::vector &entries, - std::vector &options, - UNORDERED_SET &uniqueOptions, - cmGeneratorExpressionDAGChecker *dagChecker, - const std::string& config, bool debugOptions, const char *logName, - std::string const& language) -{ - cmMakefile *mf = tgt->GetMakefile(); - - for (std::vector::const_iterator - it = entries.begin(), end = entries.end(); it != end; ++it) - { - std::vector entryOptions; - cmSystemTools::ExpandListArgument((*it)->ge->Evaluate(mf, - config, - false, - tgt, - dagChecker, - language), - entryOptions); - std::string usedOptions; - for(std::vector::iterator - li = entryOptions.begin(); li != entryOptions.end(); ++li) - { - std::string const& opt = *li; - - if(uniqueOptions.insert(opt).second) - { - options.push_back(opt); - if (debugOptions) - { - usedOptions += " * " + opt + "\n"; - } - } - } - if (!usedOptions.empty()) - { - mf->GetCMakeInstance()->IssueMessage(cmake::LOG, - std::string("Used compile ") + logName - + std::string(" for target ") - + tgt->GetName() + ":\n" - + usedOptions, (*it)->ge->GetBacktrace()); - } - } -} - -//---------------------------------------------------------------------------- -static void processCompileDefinitions(cmTarget const* tgt, - const std::vector &entries, - std::vector &options, - UNORDERED_SET &uniqueOptions, - cmGeneratorExpressionDAGChecker *dagChecker, - const std::string& config, bool debugOptions, - std::string const& language) -{ - processCompileOptionsInternal(tgt, entries, options, uniqueOptions, - dagChecker, config, debugOptions, - "definitions", language); -} - -//---------------------------------------------------------------------------- -void cmTarget::GetCompileDefinitions(std::vector &list, - const std::string& config, - const std::string& language) const -{ - UNORDERED_SET uniqueOptions; - - cmGeneratorExpressionDAGChecker dagChecker(this->GetName(), - "COMPILE_DEFINITIONS", 0, 0); - - std::vector debugProperties; - const char *debugProp = - this->Makefile->GetDefinition("CMAKE_DEBUG_TARGET_PROPERTIES"); - if (debugProp) - { - cmSystemTools::ExpandListArgument(debugProp, debugProperties); - } - - bool debugDefines = !this->DebugCompileDefinitionsDone - && std::find(debugProperties.begin(), - debugProperties.end(), - "COMPILE_DEFINITIONS") - != debugProperties.end(); - - if (this->Makefile->IsConfigured()) - { - this->DebugCompileDefinitionsDone = true; - } - - processCompileDefinitions(this, - this->Internal->CompileDefinitionsItems, - list, - uniqueOptions, - &dagChecker, - config, - debugDefines, - language); - - std::vector - linkInterfaceCompileDefinitionsEntries; - this->Internal->AddInterfaceEntries( - this, config, "INTERFACE_COMPILE_DEFINITIONS", - linkInterfaceCompileDefinitionsEntries); - if (!config.empty()) - { - std::string configPropName = "COMPILE_DEFINITIONS_" - + cmSystemTools::UpperCase(config); - const char *configProp = this->GetProperty(configPropName); - if (configProp) - { - switch(this->Makefile->GetPolicyStatus(cmPolicies::CMP0043)) - { - case cmPolicies::WARN: - { - std::ostringstream e; - e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0043); - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, - e.str()); - } - case cmPolicies::OLD: - { - cmGeneratorExpression ge; - cmsys::auto_ptr cge = - ge.Parse(configProp); - linkInterfaceCompileDefinitionsEntries - .push_back(new cmTargetInternals::TargetPropertyEntry(cge)); - } - break; - case cmPolicies::NEW: - case cmPolicies::REQUIRED_ALWAYS: - case cmPolicies::REQUIRED_IF_USED: - break; - } - } - } - - processCompileDefinitions(this, - linkInterfaceCompileDefinitionsEntries, - list, - uniqueOptions, - &dagChecker, - config, - debugDefines, - language); - - cmDeleteAll(linkInterfaceCompileDefinitionsEntries); -} - //---------------------------------------------------------------------------- void cmTarget::MaybeInvalidatePropertyCache(const std::string& prop) { @@ -4034,7 +3884,6 @@ cmTargetInternalPointer //---------------------------------------------------------------------------- cmTargetInternalPointer::~cmTargetInternalPointer() { - cmDeleteAll(this->Pointer->CompileDefinitionsItems); cmDeleteAll(this->Pointer->SourceEntries); delete this->Pointer; } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index aae558e74..34a75eac8 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -132,8 +132,6 @@ public: void AddPostBuildCommand(cmCustomCommand const &cmd) {this->PostBuildCommands.push_back(cmd);} - void Compute(); - /** * Get the list of the source files used by this target */ @@ -309,10 +307,6 @@ public: If no macro should be defined null is returned. */ const char* GetExportMacro() const; - void GetCompileDefinitions(std::vector &result, - const std::string& config, - const std::string& language) const; - // Compute the set of languages compiled by the target. This is // computed every time it is called because the languages can change // when source file properties are changed and we do not have enough @@ -402,6 +396,9 @@ public: cmStringRange GetCompileFeaturesEntries() const; cmBacktraceRange GetCompileFeaturesBacktraces() const; + cmStringRange GetCompileDefinitionsEntries() const; + cmBacktraceRange GetCompileDefinitionsBacktraces() const; + #if defined(_WIN32) && !defined(__CYGWIN__) const LinkLibraryVectorType &GetLinkLibrariesForVS6() const { return this->LinkLibrariesForVS6;} @@ -516,7 +513,6 @@ private: bool IsApple; bool IsImportedTarget; bool BuildInterfaceIncludesAppended; - mutable bool DebugCompileDefinitionsDone; mutable bool DebugSourcesDone; mutable bool LinkImplementationLanguageIsContextDependent; #if defined(_WIN32) && !defined(__CYGWIN__) diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 823b550ad..464a83a19 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -1934,7 +1934,7 @@ bool cmVisualStudio10TargetGenerator::ComputeClOptions( clOptions.Parse(flags.c_str()); clOptions.Parse(defineFlags.c_str()); std::vector targetDefines; - this->Target->GetCompileDefinitions(targetDefines, + this->GeneratorTarget->GetCompileDefinitions(targetDefines, configName.c_str(), "CXX"); clOptions.AddDefines(targetDefines); if(this->MSTools) From 3846ebcf2b60b73e3eec848bd3dd41711eac5dc4 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 17:37:48 +0200 Subject: [PATCH 15/22] cmLinkItem: Add cmLinkImplementation type. --- Source/cmComputeLinkDepends.cxx | 2 +- Source/cmComputeTargetDepends.cxx | 2 +- Source/cmGeneratorTarget.cxx | 6 +++--- Source/cmGlobalXCodeGenerator.cxx | 2 +- Source/cmLinkItem.h | 6 ++++++ Source/cmTarget.cxx | 4 ++-- Source/cmTarget.h | 7 +------ 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 5e9627bd4..4b7faa7be 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -554,7 +554,7 @@ void cmComputeLinkDepends::AddVarLinkEntries(int depender_index, void cmComputeLinkDepends::AddDirectLinkEntries() { // Add direct link dependencies in this configuration. - cmTarget::LinkImplementation const* impl = + cmLinkImplementation const* impl = this->Target->Target->GetLinkImplementation(this->Config); this->AddLinkEntries(-1, impl->Libraries); for(std::vector::const_iterator diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index 83b2a0ede..8ed4ddb30 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -252,7 +252,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) } } - cmTarget::LinkImplementation const* impl = + cmLinkImplementation const* impl = depender->Target->GetLinkImplementation(*it); // A target should not depend on itself. diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index c499cd9d0..057aa07a0 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1335,7 +1335,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config, { // Get languages built in this target. UNORDERED_SET languages; - cmTarget::LinkImplementation const* impl = + cmLinkImplementation const* impl = this->Target->GetLinkImplementation(config); assert(impl); for(std::vector::const_iterator li = impl->Languages.begin(); @@ -4057,7 +4057,7 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config, } if (this->GetType() != cmTarget::INTERFACE_LIBRARY) { - cmTarget::LinkImplementation const* impl = + cmLinkImplementation const* impl = this->Target->GetLinkImplementation(config); for(std::vector::const_iterator li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li) @@ -4098,7 +4098,7 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config, if(this->Target->LinkLanguagePropagatesToDependents()) { // Targets using this archive need its language runtime libraries. - if(cmTarget::LinkImplementation const* impl = + if(cmLinkImplementation const* impl = this->Target->GetLinkImplementation(config)) { iface.Languages = impl->Languages; diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 87c61dd25..f78a8a194 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1383,7 +1383,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget) if(llang.empty()) { return; } // If the language is compiled as a source trust Xcode to link with it. - cmTarget::LinkImplementation const* impl = + cmLinkImplementation const* impl = cmtarget.GetLinkImplementation("NOCONFIG"); for(std::vector::const_iterator li = impl->Languages.begin(); li != impl->Languages.end(); ++li) diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h index 91220b8c7..b2336f0d7 100644 --- a/Source/cmLinkItem.h +++ b/Source/cmLinkItem.h @@ -101,4 +101,10 @@ struct cmHeadToLinkInterfaceMap: { }; +struct cmLinkImplementation: public cmLinkImplementationLibraries +{ + // Languages whose runtime libraries must be linked. + std::vector Languages; +}; + #endif diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ea03ffe20..c007994cf 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -96,7 +96,7 @@ public: ImportInfoMapType ImportInfoMap; // Cache link implementation computation from each configuration. - struct OptionalLinkImplementation: public cmTarget::LinkImplementation + struct OptionalLinkImplementation: public cmLinkImplementation { OptionalLinkImplementation(): LibrariesDone(false), LanguagesDone(false), @@ -3584,7 +3584,7 @@ void cmTargetInternals::AddInterfaceEntries( } //---------------------------------------------------------------------------- -cmTarget::LinkImplementation const* +const cmLinkImplementation * cmTarget::GetLinkImplementation(const std::string& config) const { // There is no link implementation for imported targets. diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 34a75eac8..19cc220ff 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -231,12 +231,7 @@ public: void GetObjectLibrariesCMP0026(std::vector& objlibs) const; - struct LinkImplementation: public cmLinkImplementationLibraries - { - // Languages whose runtime libraries must be linked. - std::vector Languages; - }; - LinkImplementation const* + cmLinkImplementation const* GetLinkImplementation(const std::string& config) const; cmLinkImplementationLibraries const* From 771e79a2bf97e2e5de40106396358adc773014f1 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 17:37:48 +0200 Subject: [PATCH 16/22] cmLinkItem: Add cmOptionalLinkImplementation type. Move the associated Compute* methods to the cmTarget class. --- Source/cmLinkItem.h | 11 ++++++ Source/cmTarget.cxx | 87 ++++++++++++++++----------------------------- Source/cmTarget.h | 7 ++++ 3 files changed, 49 insertions(+), 56 deletions(-) diff --git a/Source/cmLinkItem.h b/Source/cmLinkItem.h index b2336f0d7..10dd465f8 100644 --- a/Source/cmLinkItem.h +++ b/Source/cmLinkItem.h @@ -107,4 +107,15 @@ struct cmLinkImplementation: public cmLinkImplementationLibraries std::vector Languages; }; +// Cache link implementation computation from each configuration. +struct cmOptionalLinkImplementation: public cmLinkImplementation +{ + cmOptionalLinkImplementation(): + LibrariesDone(false), LanguagesDone(false), + HadHeadSensitiveCondition(false) {} + bool LibrariesDone; + bool LanguagesDone; + bool HadHeadSensitiveCondition; +}; + #endif diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index c007994cf..0be3eb16c 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -95,27 +95,8 @@ public: typedef std::map ImportInfoMapType; ImportInfoMapType ImportInfoMap; - // Cache link implementation computation from each configuration. - struct OptionalLinkImplementation: public cmLinkImplementation - { - OptionalLinkImplementation(): - LibrariesDone(false), LanguagesDone(false), - HadHeadSensitiveCondition(false) {} - bool LibrariesDone; - bool LanguagesDone; - bool HadHeadSensitiveCondition; - }; - void ComputeLinkImplementationLibraries(cmTarget const* thisTarget, - const std::string& config, - OptionalLinkImplementation& impl, - cmTarget const* head) const; - void ComputeLinkImplementationLanguages(cmTarget const* thisTarget, - const std::string& config, - OptionalLinkImplementation& impl - ) const; - struct HeadToLinkImplementationMap: - public std::map {}; + public std::map {}; typedef std::map LinkImplMapType; LinkImplMapType LinkImplMap; @@ -3595,18 +3576,17 @@ cmTarget::GetLinkImplementation(const std::string& config) const // Populate the link implementation for this configuration. std::string CONFIG = cmSystemTools::UpperCase(config); - cmTargetInternals::OptionalLinkImplementation& + cmOptionalLinkImplementation& impl = this->Internal->LinkImplMap[CONFIG][this]; if(!impl.LibrariesDone) { impl.LibrariesDone = true; - this->Internal - ->ComputeLinkImplementationLibraries(this, config, impl, this); + this->ComputeLinkImplementationLibraries(config, impl, this); } if(!impl.LanguagesDone) { impl.LanguagesDone = true; - this->Internal->ComputeLinkImplementationLanguages(this, config, impl); + this->ComputeLinkImplementationLanguages(config, impl); } return &impl; } @@ -3641,39 +3621,36 @@ cmTarget::GetLinkImplementationLibrariesInternal(const std::string& config, return &hm.begin()->second; } - cmTargetInternals::OptionalLinkImplementation& impl = hm[head]; + cmOptionalLinkImplementation& impl = hm[head]; if(!impl.LibrariesDone) { impl.LibrariesDone = true; - this->Internal - ->ComputeLinkImplementationLibraries(this, config, impl, head); + this->ComputeLinkImplementationLibraries(config, impl, head); } return &impl; } //---------------------------------------------------------------------------- -void -cmTargetInternals::ComputeLinkImplementationLibraries( - cmTarget const* thisTarget, +void cmTarget::ComputeLinkImplementationLibraries( const std::string& config, - OptionalLinkImplementation& impl, + cmOptionalLinkImplementation& impl, cmTarget const* head) const { // Collect libraries directly linked in this configuration. for (std::vector::const_iterator - le = this->LinkImplementationPropertyEntries.begin(), - end = this->LinkImplementationPropertyEntries.end(); + le = this->Internal->LinkImplementationPropertyEntries.begin(), + end = this->Internal->LinkImplementationPropertyEntries.end(); le != end; ++le) { std::vector llibs; cmGeneratorExpressionDAGChecker dagChecker( - thisTarget->GetName(), + this->GetName(), "LINK_LIBRARIES", 0, 0); cmGeneratorExpression ge(le->Backtrace); cmsys::auto_ptr const cge = ge.Parse(le->Value); std::string const evaluated = - cge->Evaluate(thisTarget->Makefile, config, false, head, &dagChecker); + cge->Evaluate(this->Makefile, config, false, head, &dagChecker); cmSystemTools::ExpandListArgument(evaluated, llibs); if(cge->GetHadHeadSensitiveCondition()) { @@ -3684,15 +3661,15 @@ cmTargetInternals::ComputeLinkImplementationLibraries( li != llibs.end(); ++li) { // Skip entries that resolve to the target itself or are empty. - std::string name = thisTarget->CheckCMP0004(*li); - if(name == thisTarget->GetName() || name.empty()) + std::string name = this->CheckCMP0004(*li); + if(name == this->GetName() || name.empty()) { - if(name == thisTarget->GetName()) + if(name == this->GetName()) { bool noMessage = false; cmake::MessageType messageType = cmake::FATAL_ERROR; std::ostringstream e; - switch(thisTarget->GetPolicyStatusCMP0038()) + switch(this->GetPolicyStatusCMP0038()) { case cmPolicies::WARN: { @@ -3711,9 +3688,9 @@ cmTargetInternals::ComputeLinkImplementationLibraries( if(!noMessage) { - e << "Target \"" << thisTarget->GetName() << "\" links to itself."; - thisTarget->Makefile->GetCMakeInstance()->IssueMessage( - messageType, e.str(), thisTarget->GetBacktrace()); + e << "Target \"" << this->GetName() << "\" links to itself."; + this->Makefile->GetCMakeInstance()->IssueMessage( + messageType, e.str(), this->GetBacktrace()); if (messageType == cmake::FATAL_ERROR) { return; @@ -3725,7 +3702,7 @@ cmTargetInternals::ComputeLinkImplementationLibraries( // The entry is meant for this configuration. impl.Libraries.push_back( - cmLinkImplItem(name, thisTarget->FindTargetToLink(name), + cmLinkImplItem(name, this->FindTargetToLink(name), le->Backtrace, evaluated != le->Value)); } @@ -3733,45 +3710,43 @@ cmTargetInternals::ComputeLinkImplementationLibraries( for (std::set::const_iterator it = seenProps.begin(); it != seenProps.end(); ++it) { - if (!thisTarget->GetProperty(*it)) + if (!this->GetProperty(*it)) { - thisTarget->LinkImplicitNullProperties.insert(*it); + this->LinkImplicitNullProperties.insert(*it); } } - cge->GetMaxLanguageStandard(thisTarget, thisTarget->MaxLanguageStandards); + cge->GetMaxLanguageStandard(this, this->MaxLanguageStandards); } - cmTarget::LinkLibraryType linkType = thisTarget->ComputeLinkType(config); + cmTarget::LinkLibraryType linkType = this->ComputeLinkType(config); cmTarget::LinkLibraryVectorType const& oldllibs = - thisTarget->GetOriginalLinkLibraries(); + this->GetOriginalLinkLibraries(); for(cmTarget::LinkLibraryVectorType::const_iterator li = oldllibs.begin(); li != oldllibs.end(); ++li) { if(li->second != cmTarget::GENERAL && li->second != linkType) { - std::string name = thisTarget->CheckCMP0004(li->first); - if(name == thisTarget->GetName() || name.empty()) + std::string name = this->CheckCMP0004(li->first); + if(name == this->GetName() || name.empty()) { continue; } // Support OLD behavior for CMP0003. impl.WrongConfigLibraries.push_back( - cmLinkItem(name, thisTarget->FindTargetToLink(name))); + cmLinkItem(name, this->FindTargetToLink(name))); } } } //---------------------------------------------------------------------------- -void -cmTargetInternals::ComputeLinkImplementationLanguages( - cmTarget const* thisTarget, +void cmTarget::ComputeLinkImplementationLanguages( const std::string& config, - OptionalLinkImplementation& impl) const + cmOptionalLinkImplementation& impl) const { // This target needs runtime libraries for its source languages. std::set languages; // Get languages used in our source files. - thisTarget->GetLanguages(languages, config); + this->GetLanguages(languages, config); // Copy the set of langauges to the link implementation. impl.Languages.insert(impl.Languages.begin(), languages.begin(), languages.end()); diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 19cc220ff..d49b23e15 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -237,6 +237,13 @@ public: cmLinkImplementationLibraries const* GetLinkImplementationLibraries(const std::string& config) const; + void ComputeLinkImplementationLibraries(const std::string& config, + cmOptionalLinkImplementation& impl, + cmTarget const* head) const; + void ComputeLinkImplementationLanguages(const std::string& config, + cmOptionalLinkImplementation& impl + ) const; + cmTarget const* FindTargetToLink(std::string const& name) const; /** Strip off leading and trailing whitespace from an item named in From 83981cf5931aaa2d9bbf4f99ea55c99736173fdf Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 17:37:49 +0200 Subject: [PATCH 17/22] cmTarget: Add GetLinkImplMap method. This is a temporary refactoring artifact. --- Source/cmTarget.cxx | 13 +++++++++---- Source/cmTarget.h | 3 +++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 0be3eb16c..2e37c086f 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3574,10 +3574,7 @@ cmTarget::GetLinkImplementation(const std::string& config) const return 0; } - // Populate the link implementation for this configuration. - std::string CONFIG = cmSystemTools::UpperCase(config); - cmOptionalLinkImplementation& - impl = this->Internal->LinkImplMap[CONFIG][this]; + cmOptionalLinkImplementation& impl = this->GetLinkImplMap(config); if(!impl.LibrariesDone) { impl.LibrariesDone = true; @@ -3591,6 +3588,14 @@ cmTarget::GetLinkImplementation(const std::string& config) const return &impl; } +cmOptionalLinkImplementation& +cmTarget::GetLinkImplMap(std::string const& config) const +{ + // Populate the link implementation for this configuration. + std::string CONFIG = cmSystemTools::UpperCase(config); + return Internal->LinkImplMap[CONFIG][this]; +} + //---------------------------------------------------------------------------- cmLinkImplementationLibraries const* cmTarget::GetLinkImplementationLibraries(const std::string& config) const diff --git a/Source/cmTarget.h b/Source/cmTarget.h index d49b23e15..6411d12ba 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -244,6 +244,9 @@ public: cmOptionalLinkImplementation& impl ) const; + cmOptionalLinkImplementation& + GetLinkImplMap(std::string const& config) const; + cmTarget const* FindTargetToLink(std::string const& name) const; /** Strip off leading and trailing whitespace from an item named in From d4a24c0e953e0032a2e483917850b7f8f387bbb2 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 17:37:49 +0200 Subject: [PATCH 18/22] cmGeneratorTarget: Move GetLinkImplementation from cmTarget. --- Source/cmComputeLinkDepends.cxx | 2 +- Source/cmComputeTargetDepends.cxx | 3 +-- Source/cmGeneratorTarget.cxx | 31 ++++++++++++++++++++++++++++--- Source/cmGeneratorTarget.h | 3 +++ Source/cmGlobalXCodeGenerator.cxx | 2 +- Source/cmTarget.cxx | 24 ------------------------ Source/cmTarget.h | 3 --- 7 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx index 4b7faa7be..e774e1658 100644 --- a/Source/cmComputeLinkDepends.cxx +++ b/Source/cmComputeLinkDepends.cxx @@ -555,7 +555,7 @@ void cmComputeLinkDepends::AddDirectLinkEntries() { // Add direct link dependencies in this configuration. cmLinkImplementation const* impl = - this->Target->Target->GetLinkImplementation(this->Config); + this->Target->GetLinkImplementation(this->Config); this->AddLinkEntries(-1, impl->Libraries); for(std::vector::const_iterator wi = impl->WrongConfigLibraries.begin(); diff --git a/Source/cmComputeTargetDepends.cxx b/Source/cmComputeTargetDepends.cxx index 8ed4ddb30..9e37c3512 100644 --- a/Source/cmComputeTargetDepends.cxx +++ b/Source/cmComputeTargetDepends.cxx @@ -252,8 +252,7 @@ void cmComputeTargetDepends::CollectTargetDepends(int depender_index) } } - cmLinkImplementation const* impl = - depender->Target->GetLinkImplementation(*it); + cmLinkImplementation const* impl = depender->GetLinkImplementation(*it); // A target should not depend on itself. emitted.insert(depender->GetName()); diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 057aa07a0..44fac1d02 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1336,7 +1336,7 @@ void cmGeneratorTarget::ComputeLinkClosure(const std::string& config, // Get languages built in this target. UNORDERED_SET languages; cmLinkImplementation const* impl = - this->Target->GetLinkImplementation(config); + this->GetLinkImplementation(config); assert(impl); for(std::vector::const_iterator li = impl->Languages.begin(); li != impl->Languages.end(); ++li) @@ -4058,7 +4058,7 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config, if (this->GetType() != cmTarget::INTERFACE_LIBRARY) { cmLinkImplementation const* impl = - this->Target->GetLinkImplementation(config); + this->GetLinkImplementation(config); for(std::vector::const_iterator li = impl->Libraries.begin(); li != impl->Libraries.end(); ++li) { @@ -4099,7 +4099,7 @@ void cmGeneratorTarget::ComputeLinkInterface(const std::string& config, { // Targets using this archive need its language runtime libraries. if(cmLinkImplementation const* impl = - this->Target->GetLinkImplementation(config)) + this->GetLinkImplementation(config)) { iface.Languages = impl->Languages; } @@ -4389,3 +4389,28 @@ cmGeneratorTarget::GetHeadToLinkInterfaceUsageRequirementsMap( std::string CONFIG = cmSystemTools::UpperCase(config); return this->LinkInterfaceUsageRequirementsOnlyMap[CONFIG]; } + +//---------------------------------------------------------------------------- +const cmLinkImplementation * +cmGeneratorTarget::GetLinkImplementation(const std::string& config) const +{ + // There is no link implementation for imported targets. + if(this->Target->IsImported()) + { + return 0; + } + + cmOptionalLinkImplementation& impl = this->Target->GetLinkImplMap(config); + if(!impl.LibrariesDone) + { + impl.LibrariesDone = true; + this->Target->ComputeLinkImplementationLibraries(config, impl, + this->Target); + } + if(!impl.LanguagesDone) + { + impl.LanguagesDone = true; + this->Target->ComputeLinkImplementationLanguages(config, impl); + } + return &impl; +} diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 557eb1782..58f5f6b15 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -198,6 +198,9 @@ public: LinkClosure const* GetLinkClosure(const std::string& config) const; void ComputeLinkClosure(const std::string& config, LinkClosure& lc) const; + cmLinkImplementation const* + GetLinkImplementation(const std::string& config) const; + /** Full path with trailing slash to the top-level directory holding object files for this target. Includes the build time config name placeholder if needed for the generator. */ diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index f78a8a194..68fd06bd0 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1384,7 +1384,7 @@ void cmGlobalXCodeGenerator::ForceLinkerLanguage(cmTarget& cmtarget) // If the language is compiled as a source trust Xcode to link with it. cmLinkImplementation const* impl = - cmtarget.GetLinkImplementation("NOCONFIG"); + gtgt->GetLinkImplementation("NOCONFIG"); for(std::vector::const_iterator li = impl->Languages.begin(); li != impl->Languages.end(); ++li) { diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 2e37c086f..a8ea0b85c 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3564,30 +3564,6 @@ void cmTargetInternals::AddInterfaceEntries( } } -//---------------------------------------------------------------------------- -const cmLinkImplementation * -cmTarget::GetLinkImplementation(const std::string& config) const -{ - // There is no link implementation for imported targets. - if(this->IsImported()) - { - return 0; - } - - cmOptionalLinkImplementation& impl = this->GetLinkImplMap(config); - if(!impl.LibrariesDone) - { - impl.LibrariesDone = true; - this->ComputeLinkImplementationLibraries(config, impl, this); - } - if(!impl.LanguagesDone) - { - impl.LanguagesDone = true; - this->ComputeLinkImplementationLanguages(config, impl); - } - return &impl; -} - cmOptionalLinkImplementation& cmTarget::GetLinkImplMap(std::string const& config) const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 6411d12ba..1d353abe5 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -231,9 +231,6 @@ public: void GetObjectLibrariesCMP0026(std::vector& objlibs) const; - cmLinkImplementation const* - GetLinkImplementation(const std::string& config) const; - cmLinkImplementationLibraries const* GetLinkImplementationLibraries(const std::string& config) const; From abe9505df94e9a1511238c41f9d4459064148c94 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 17:37:49 +0200 Subject: [PATCH 19/22] cmGeneratorTarget: Move HaveBuildTreeRPath from cmTarget. --- Source/cmComputeLinkInformation.cxx | 2 +- Source/cmGeneratorTarget.cxx | 17 ++++++++++++++++- Source/cmGeneratorTarget.h | 2 ++ Source/cmTarget.cxx | 15 --------------- Source/cmTarget.h | 1 - 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx index 6ba0eedcd..192ad5f2b 100644 --- a/Source/cmComputeLinkInformation.cxx +++ b/Source/cmComputeLinkInformation.cxx @@ -1925,7 +1925,7 @@ void cmComputeLinkInformation::GetRPath(std::vector& runtimeDirs, (outputRuntime && this->Target->Target->HaveInstallTreeRPATH() && linking_for_install); bool use_build_rpath = - (outputRuntime && this->Target->Target->HaveBuildTreeRPATH(this->Config) && + (outputRuntime && this->Target->HaveBuildTreeRPATH(this->Config) && !linking_for_install); bool use_link_rpath = outputRuntime && linking_for_install && diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 44fac1d02..9dc045ca0 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -909,7 +909,7 @@ cmGeneratorTarget::NeedRelinkBeforeInstall(const std::string& config) const // If either a build or install tree rpath is set then the rpath // will likely change between the build tree and install tree and // this target must be relinked. - return this->Target->HaveBuildTreeRPATH(config) + return this->HaveBuildTreeRPATH(config) || this->Target->HaveInstallTreeRPATH(); } @@ -4414,3 +4414,18 @@ cmGeneratorTarget::GetLinkImplementation(const std::string& config) const } return &impl; } + +//---------------------------------------------------------------------------- +bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const +{ + if (this->Target->GetPropertyAsBool("SKIP_BUILD_RPATH")) + { + return false; + } + if(cmLinkImplementationLibraries const* impl = + this->Target->GetLinkImplementationLibraries(config)) + { + return !impl->Libraries.empty(); + } + return false; +} diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 58f5f6b15..99463c79b 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -201,6 +201,8 @@ public: cmLinkImplementation const* GetLinkImplementation(const std::string& config) const; + bool HaveBuildTreeRPATH(const std::string& config) const; + /** Full path with trailing slash to the top-level directory holding object files for this target. Includes the build time config name placeholder if needed for the generator. */ diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index a8ea0b85c..9073f8276 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2809,21 +2809,6 @@ void cmTarget::SetPropertyDefault(const std::string& property, } } -//---------------------------------------------------------------------------- -bool cmTarget::HaveBuildTreeRPATH(const std::string& config) const -{ - if (this->GetPropertyAsBool("SKIP_BUILD_RPATH")) - { - return false; - } - if(cmLinkImplementationLibraries const* impl = - this->GetLinkImplementationLibraries(config)) - { - return !impl->Libraries.empty(); - } - return false; -} - //---------------------------------------------------------------------------- bool cmTarget::HaveInstallTreeRPATH() const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 1d353abe5..8866e65c4 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -294,7 +294,6 @@ public: bool GetImplibGNUtoMS(std::string const& gnuName, std::string& out, const char* newExt = 0) const; - bool HaveBuildTreeRPATH(const std::string& config) const; bool HaveInstallTreeRPATH() const; // Get the properties From 0431f2c4d7cbfcd873bc34caee9ed09253e8c8ad Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 17:37:50 +0200 Subject: [PATCH 20/22] cmGeneratorTarget: Move ComputeLinkImplementationLanguages from cmTarget. --- Source/cmGeneratorTarget.cxx | 16 +++++++++++++++- Source/cmGeneratorTarget.h | 4 ++++ Source/cmTarget.cxx | 14 -------------- Source/cmTarget.h | 3 --- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 9dc045ca0..22b1baf35 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -4410,11 +4410,25 @@ cmGeneratorTarget::GetLinkImplementation(const std::string& config) const if(!impl.LanguagesDone) { impl.LanguagesDone = true; - this->Target->ComputeLinkImplementationLanguages(config, impl); + this->ComputeLinkImplementationLanguages(config, impl); } return &impl; } +//---------------------------------------------------------------------------- +void cmGeneratorTarget::ComputeLinkImplementationLanguages( + const std::string& config, + cmOptionalLinkImplementation& impl) const +{ + // This target needs runtime libraries for its source languages. + std::set languages; + // Get languages used in our source files. + this->Target->GetLanguages(languages, config); + // Copy the set of langauges to the link implementation. + impl.Languages.insert(impl.Languages.begin(), + languages.begin(), languages.end()); +} + //---------------------------------------------------------------------------- bool cmGeneratorTarget::HaveBuildTreeRPATH(const std::string& config) const { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 99463c79b..f5dc20d9d 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -201,6 +201,10 @@ public: cmLinkImplementation const* GetLinkImplementation(const std::string& config) const; + void ComputeLinkImplementationLanguages(const std::string& config, + cmOptionalLinkImplementation& impl + ) const; + bool HaveBuildTreeRPATH(const std::string& config) const; /** Full path with trailing slash to the top-level directory diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 9073f8276..f395c452e 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3704,20 +3704,6 @@ void cmTarget::ComputeLinkImplementationLibraries( } } -//---------------------------------------------------------------------------- -void cmTarget::ComputeLinkImplementationLanguages( - const std::string& config, - cmOptionalLinkImplementation& impl) const -{ - // This target needs runtime libraries for its source languages. - std::set languages; - // Get languages used in our source files. - this->GetLanguages(languages, config); - // Copy the set of langauges to the link implementation. - impl.Languages.insert(impl.Languages.begin(), - languages.begin(), languages.end()); -} - //---------------------------------------------------------------------------- cmTarget const* cmTarget::FindTargetToLink(std::string const& name) const { diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 8866e65c4..1db4ba1af 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -237,9 +237,6 @@ public: void ComputeLinkImplementationLibraries(const std::string& config, cmOptionalLinkImplementation& impl, cmTarget const* head) const; - void ComputeLinkImplementationLanguages(const std::string& config, - cmOptionalLinkImplementation& impl - ) const; cmOptionalLinkImplementation& GetLinkImplMap(std::string const& config) const; From 69329fff70300debf10b62ac08a6bcee9ae7bc3c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 17:37:50 +0200 Subject: [PATCH 21/22] cmGeneratorTarget: Move GetLanguages from cmTarget. --- Source/cmGeneratorTarget.cxx | 53 ++++++++++++++++++++++- Source/cmGeneratorTarget.h | 8 ++++ Source/cmGlobalUnixMakefileGenerator3.cxx | 3 +- Source/cmGlobalVisualStudioGenerator.cxx | 4 +- Source/cmGlobalXCodeGenerator.cxx | 4 +- Source/cmLocalUnixMakefileGenerator3.cxx | 4 +- Source/cmMakefileTargetGenerator.cxx | 2 +- Source/cmTarget.cxx | 44 ------------------- Source/cmTarget.h | 8 ---- 9 files changed, 71 insertions(+), 59 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 22b1baf35..4ada0299d 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -4415,6 +4415,57 @@ cmGeneratorTarget::GetLinkImplementation(const std::string& config) const return &impl; } +//---------------------------------------------------------------------------- +void cmGeneratorTarget::GetLanguages(std::set& languages, + const std::string& config) const +{ + std::vector sourceFiles; + this->Target->GetSourceFiles(sourceFiles, config); + for(std::vector::const_iterator + i = sourceFiles.begin(); i != sourceFiles.end(); ++i) + { + const std::string& lang = (*i)->GetLanguage(); + if(!lang.empty()) + { + languages.insert(lang); + } + } + + std::vector objectLibraries; + std::vector externalObjects; + if (!this->Makefile->IsConfigured()) + { + std::vector objectTargets; + this->Target->GetObjectLibrariesCMP0026(objectTargets); + objectLibraries.reserve(objectTargets.size()); + for (std::vector::const_iterator it = objectTargets.begin(); + it != objectTargets.end(); ++it) + { + objectLibraries.push_back(this->GlobalGenerator + ->GetGeneratorTarget(*it)); + } + } + else + { + this->GetExternalObjects(externalObjects, config); + for(std::vector::const_iterator + i = externalObjects.begin(); i != externalObjects.end(); ++i) + { + std::string objLib = (*i)->GetObjectLibrary(); + if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib)) + { + objectLibraries.push_back(this->GlobalGenerator + ->GetGeneratorTarget(tgt)); + } + } + } + for(std::vector::const_iterator + i = objectLibraries.begin(); i != objectLibraries.end(); ++i) + { + (*i)->GetLanguages(languages, config); + } +} + //---------------------------------------------------------------------------- void cmGeneratorTarget::ComputeLinkImplementationLanguages( const std::string& config, @@ -4423,7 +4474,7 @@ void cmGeneratorTarget::ComputeLinkImplementationLanguages( // This target needs runtime libraries for its source languages. std::set languages; // Get languages used in our source files. - this->Target->GetLanguages(languages, config); + this->GetLanguages(languages, config); // Copy the set of langauges to the link implementation. impl.Languages.insert(impl.Languages.begin(), languages.begin(), languages.end()); diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index f5dc20d9d..5f96f2a94 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -205,6 +205,14 @@ public: cmOptionalLinkImplementation& impl ) const; + // Compute the set of languages compiled by the target. This is + // computed every time it is called because the languages can change + // when source file properties are changed and we do not have enough + // information to forward these property changes to the targets + // until we have per-target object file properties. + void GetLanguages(std::set& languages, + std::string const& config) const; + bool HaveBuildTreeRPATH(const std::string& config) const; /** Full path with trailing slash to the top-level directory diff --git a/Source/cmGlobalUnixMakefileGenerator3.cxx b/Source/cmGlobalUnixMakefileGenerator3.cxx index b240924b6..331caad9a 100644 --- a/Source/cmGlobalUnixMakefileGenerator3.cxx +++ b/Source/cmGlobalUnixMakefileGenerator3.cxx @@ -1134,7 +1134,8 @@ bool cmGlobalUnixMakefileGenerator3 ::NeedRequiresStep(cmTarget const& target) { std::set languages; - target.GetLanguages(languages, + cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&target); + gtgt->GetLanguages(languages, target.GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE")); for(std::set::const_iterator l = languages.begin(); l != languages.end(); ++l) diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 634366e12..9b1f4c2d1 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -836,6 +836,8 @@ void RegisterVisualStudioMacros(const std::string& macrosFile, bool cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmTarget const& target) { + cmGeneratorTarget* gt = this->GetGeneratorTarget(&target); + // check to see if this is a fortran build std::set languages; { @@ -846,7 +848,7 @@ cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmTarget const& target) return false; } } - target.GetLanguages(languages, ""); + gt->GetLanguages(languages, ""); if(languages.size() == 1) { if(*languages.begin() == "Fortran") diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 68fd06bd0..4511de5ef 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1805,7 +1805,8 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, // Compute the compilation flags for each language. std::set languages; - target.GetLanguages(languages, configName); + cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target); + gtgt->GetLanguages(languages, configName); std::map cflags; for (std::set::iterator li = languages.begin(); li != languages.end(); ++li) @@ -1827,7 +1828,6 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target, AddCompileOptions(flags, &target, lang, configName); } - cmGeneratorTarget *gtgt = this->GetGeneratorTarget(&target); std::string llang = gtgt->GetLinkerLanguage(configName); if(binary && llang.empty()) { diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index ce370bcc2..589105ea2 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1257,7 +1257,9 @@ cmLocalUnixMakefileGenerator3 { // Get the set of source languages in the target. std::set languages; - target.GetLanguages(languages, + cmGeneratorTarget *gtgt = + this->GlobalGenerator->GetGeneratorTarget(&target); + gtgt->GetLanguages(languages, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); fout << "\n" << "# Per-language clean rules from dependency scanning.\n" diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 0b3df90de..cf88a749c 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -276,7 +276,7 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags() { // write language flags for target std::set languages; - this->Target->GetLanguages(languages, + this->GeneratorTarget->GetLanguages(languages, this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE")); // put the compiler in the rules.make file so that if it changes // things rebuild diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index f395c452e..8a212695e 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -3130,50 +3130,6 @@ cmTarget::GetObjectLibrariesCMP0026(std::vector& objlibs) const } } -//---------------------------------------------------------------------------- -void cmTarget::GetLanguages(std::set& languages, - const std::string& config) const -{ - std::vector sourceFiles; - this->GetSourceFiles(sourceFiles, config); - for(std::vector::const_iterator - i = sourceFiles.begin(); i != sourceFiles.end(); ++i) - { - const std::string& lang = (*i)->GetLanguage(); - if(!lang.empty()) - { - languages.insert(lang); - } - } - - std::vector objectLibraries; - std::vector externalObjects; - if (!this->Makefile->IsConfigured()) - { - this->GetObjectLibrariesCMP0026(objectLibraries); - } - else - { - cmGeneratorTarget* gt = this->Makefile->GetGlobalGenerator() - ->GetGeneratorTarget(this); - gt->GetExternalObjects(externalObjects, config); - for(std::vector::const_iterator - i = externalObjects.begin(); i != externalObjects.end(); ++i) - { - std::string objLib = (*i)->GetObjectLibrary(); - if (cmTarget* tgt = this->Makefile->FindTargetToUse(objLib)) - { - objectLibraries.push_back(tgt); - } - } - } - for(std::vector::const_iterator - i = objectLibraries.begin(); i != objectLibraries.end(); ++i) - { - (*i)->GetLanguages(languages, config); - } -} - //---------------------------------------------------------------------------- cmTarget::ImportInfo const* cmTarget::GetImportInfo(const std::string& config) const diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 1db4ba1af..8dee56066 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -305,14 +305,6 @@ public: If no macro should be defined null is returned. */ const char* GetExportMacro() const; - // Compute the set of languages compiled by the target. This is - // computed every time it is called because the languages can change - // when source file properties are changed and we do not have enough - // information to forward these property changes to the targets - // until we have per-target object file properties. - void GetLanguages(std::set& languages, - std::string const& config) const; - /** Return whether this target is an executable with symbol exports enabled. */ bool IsExecutableWithExports() const; From c2b7336ff3122c57a235aeaa1699ba5627ecf3ce Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 5 Aug 2015 17:37:50 +0200 Subject: [PATCH 22/22] cmGeneratorTarget: Move GetConfigCommonSourceFiles from cmTarget. --- Source/cmGeneratorTarget.cxx | 59 +++++++++++++++++++++- Source/cmGeneratorTarget.h | 2 + Source/cmGlobalVisualStudioGenerator.cxx | 2 +- Source/cmGlobalXCodeGenerator.cxx | 11 ++-- Source/cmLocalVisualStudio6Generator.cxx | 5 +- Source/cmLocalVisualStudio7Generator.cxx | 7 +-- Source/cmQtAutoGenerators.cxx | 14 +++-- Source/cmTarget.cxx | 56 -------------------- Source/cmTarget.h | 2 - Source/cmVisualStudio10TargetGenerator.cxx | 2 +- 10 files changed, 88 insertions(+), 72 deletions(-) diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 4ada0299d..cd7671db6 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -4415,12 +4415,69 @@ cmGeneratorTarget::GetLinkImplementation(const std::string& config) const return &impl; } +//---------------------------------------------------------------------------- +bool cmGeneratorTarget::GetConfigCommonSourceFiles( + std::vector& files) const +{ + std::vector configs; + this->Makefile->GetConfigurations(configs); + if (configs.empty()) + { + configs.push_back(""); + } + + std::vector::const_iterator it = configs.begin(); + const std::string& firstConfig = *it; + this->Target->GetSourceFiles(files, firstConfig); + + for ( ; it != configs.end(); ++it) + { + std::vector configFiles; + this->Target->GetSourceFiles(configFiles, *it); + if (configFiles != files) + { + std::string firstConfigFiles; + const char* sep = ""; + for (std::vector::const_iterator fi = files.begin(); + fi != files.end(); ++fi) + { + firstConfigFiles += sep; + firstConfigFiles += (*fi)->GetFullPath(); + sep = "\n "; + } + + std::string thisConfigFiles; + sep = ""; + for (std::vector::const_iterator fi = configFiles.begin(); + fi != configFiles.end(); ++fi) + { + thisConfigFiles += sep; + thisConfigFiles += (*fi)->GetFullPath(); + sep = "\n "; + } + std::ostringstream e; + e << "Target \"" << this->GetName() + << "\" has source files which vary by " + "configuration. This is not supported by the \"" + << this->GlobalGenerator->GetName() + << "\" generator.\n" + "Config \"" << firstConfig << "\":\n" + " " << firstConfigFiles << "\n" + "Config \"" << *it << "\":\n" + " " << thisConfigFiles << "\n"; + this->LocalGenerator->IssueMessage(cmake::FATAL_ERROR, e.str()); + return false; + } + } + return true; +} + //---------------------------------------------------------------------------- void cmGeneratorTarget::GetLanguages(std::set& languages, const std::string& config) const { std::vector sourceFiles; - this->Target->GetSourceFiles(sourceFiles, config); + this->GetSourceFiles(sourceFiles, config); for(std::vector::const_iterator i = sourceFiles.begin(); i != sourceFiles.end(); ++i) { diff --git a/Source/cmGeneratorTarget.h b/Source/cmGeneratorTarget.h index 5f96f2a94..2c8467f30 100644 --- a/Source/cmGeneratorTarget.h +++ b/Source/cmGeneratorTarget.h @@ -213,6 +213,8 @@ public: void GetLanguages(std::set& languages, std::string const& config) const; + bool GetConfigCommonSourceFiles(std::vector& files) const; + bool HaveBuildTreeRPATH(const std::string& config) const; /** Full path with trailing slash to the top-level directory diff --git a/Source/cmGlobalVisualStudioGenerator.cxx b/Source/cmGlobalVisualStudioGenerator.cxx index 9b1f4c2d1..2bf04b4c0 100644 --- a/Source/cmGlobalVisualStudioGenerator.cxx +++ b/Source/cmGlobalVisualStudioGenerator.cxx @@ -843,7 +843,7 @@ cmGlobalVisualStudioGenerator::TargetIsFortranOnly(cmTarget const& target) { // Issue diagnostic if the source files depend on the config. std::vector sources; - if (!target.GetConfigCommonSourceFiles(sources)) + if (!gt->GetConfigCommonSourceFiles(sources)) { return false; } diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 4511de5ef..eb547bd0f 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -1124,7 +1124,7 @@ cmGlobalXCodeGenerator::CreateXCodeTargets(cmLocalGenerator* gen, // organize the sources std::vector classes; - if (!cmtarget.GetConfigCommonSourceFiles(classes)) + if (!gtgt->GetConfigCommonSourceFiles(classes)) { return false; } @@ -1505,7 +1505,8 @@ void cmGlobalXCodeGenerator::CreateCustomCommands(cmXCodeObject* buildPhases, } std::vector classes; - if (!cmtarget.GetConfigCommonSourceFiles(classes)) + cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget); + if (!gtgt->GetConfigCommonSourceFiles(classes)) { return; } @@ -2557,7 +2558,8 @@ cmGlobalXCodeGenerator::CreateUtilityTarget(cmTarget& cmtarget) if(cmtarget.GetType() == cmTarget::UTILITY) { std::vector sources; - if (!cmtarget.GetConfigCommonSourceFiles(sources)) + cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget); + if (!gtgt->GetConfigCommonSourceFiles(sources)) { return 0; } @@ -3085,7 +3087,8 @@ bool cmGlobalXCodeGenerator::CreateGroups(cmLocalGenerator* root, } std::vector classes; - if (!cmtarget.GetConfigCommonSourceFiles(classes)) + cmGeneratorTarget* gtgt = this->GetGeneratorTarget(&cmtarget); + if (!gtgt->GetConfigCommonSourceFiles(classes)) { return false; } diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index 0d0753651..3a44367f4 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -305,9 +305,12 @@ void cmLocalVisualStudio6Generator::WriteDSPFile(std::ostream& fout, // We may be modifying the source groups temporarily, so make a copy. std::vector sourceGroups = this->Makefile->GetSourceGroups(); + cmGeneratorTarget* gt = + this->GlobalGenerator->GetGeneratorTarget(&target); + // get the classes from the source lists then add them to the groups std::vector classes; - if (!target.GetConfigCommonSourceFiles(classes)) + if (!gt->GetConfigCommonSourceFiles(classes)) { return; } diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index f17c9a4c6..55ad8525f 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1469,10 +1469,13 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, // We may be modifying the source groups temporarily, so make a copy. std::vector sourceGroups = this->Makefile->GetSourceGroups(); + cmGeneratorTarget* gt = + this->GlobalGenerator->GetGeneratorTarget(&target); + // get the classes from the source lists then add them to the groups this->ModuleDefinitionFile = ""; std::vector classes; - if (!target.GetConfigCommonSourceFiles(classes)) + if (!gt->GetConfigCommonSourceFiles(classes)) { return; } @@ -1514,8 +1517,6 @@ void cmLocalVisualStudio7Generator::WriteVCProjFile(std::ostream& fout, { // VS >= 8 support per-config source locations so we // list object library content as external objects. - cmGeneratorTarget* gt = - this->GlobalGenerator->GetGeneratorTarget(&target); std::vector objs; gt->UseObjectLibraries(objs, ""); if(!objs.empty()) diff --git a/Source/cmQtAutoGenerators.cxx b/Source/cmQtAutoGenerators.cxx index c58e7e4f3..0a4b5469a 100644 --- a/Source/cmQtAutoGenerators.cxx +++ b/Source/cmQtAutoGenerators.cxx @@ -403,7 +403,9 @@ bool cmQtAutoGenerators::InitializeAutogenTarget(cmLocalGenerator* lg, ) { std::vector srcFiles; - target->GetConfigCommonSourceFiles(srcFiles); + cmGeneratorTarget* gtgt = + lg->GetGlobalGenerator()->GetGeneratorTarget(target); + gtgt->GetConfigCommonSourceFiles(srcFiles); for(std::vector::const_iterator fileIt = srcFiles.begin(); fileIt != srcFiles.end(); ++fileIt) @@ -661,7 +663,10 @@ void cmQtAutoGenerators::SetupSourceFiles(cmTarget const* target) const char* sepHeaders = ""; std::vector srcFiles; - target->GetConfigCommonSourceFiles(srcFiles); + cmGeneratorTarget *gtgt = target->GetMakefile() + ->GetGlobalGenerator() + ->GetGeneratorTarget(target); + gtgt->GetConfigCommonSourceFiles(srcFiles); const char *skipMocSep = ""; const char *skipUicSep = ""; @@ -1046,7 +1051,10 @@ void cmQtAutoGenerators::SetupAutoRccTarget(cmTarget const* target) cmMakefile *makefile = target->GetMakefile(); std::vector srcFiles; - target->GetConfigCommonSourceFiles(srcFiles); + cmGeneratorTarget *gtgt = target->GetMakefile() + ->GetGlobalGenerator() + ->GetGeneratorTarget(target); + gtgt->GetConfigCommonSourceFiles(srcFiles); std::string qrcInputs; const char* qrcInputsSep = ""; diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 8a212695e..b2c70f014 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -724,62 +724,6 @@ void cmTarget::GetSourceFiles(std::vector &files, cmDeleteAll(linkInterfaceSourcesEntries); } -//---------------------------------------------------------------------------- -bool -cmTarget::GetConfigCommonSourceFiles(std::vector& files) const -{ - std::vector configs; - this->Makefile->GetConfigurations(configs); - if (configs.empty()) - { - configs.push_back(""); - } - - std::vector::const_iterator it = configs.begin(); - const std::string& firstConfig = *it; - this->GetSourceFiles(files, firstConfig); - - for ( ; it != configs.end(); ++it) - { - std::vector configFiles; - this->GetSourceFiles(configFiles, *it); - if (configFiles != files) - { - std::string firstConfigFiles; - const char* sep = ""; - for (std::vector::const_iterator fi = files.begin(); - fi != files.end(); ++fi) - { - firstConfigFiles += sep; - firstConfigFiles += (*fi)->GetFullPath(); - sep = "\n "; - } - - std::string thisConfigFiles; - sep = ""; - for (std::vector::const_iterator fi = configFiles.begin(); - fi != configFiles.end(); ++fi) - { - thisConfigFiles += sep; - thisConfigFiles += (*fi)->GetFullPath(); - sep = "\n "; - } - std::ostringstream e; - e << "Target \"" << this->Name << "\" has source files which vary by " - "configuration. This is not supported by the \"" - << this->Makefile->GetGlobalGenerator()->GetName() - << "\" generator.\n" - "Config \"" << firstConfig << "\":\n" - " " << firstConfigFiles << "\n" - "Config \"" << *it << "\":\n" - " " << thisConfigFiles << "\n"; - this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str()); - return false; - } - } - return true; -} - //---------------------------------------------------------------------------- void cmTarget::GetSourceFiles(std::vector &files, const std::string& config) const diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 8dee56066..d03238027 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -137,8 +137,6 @@ public: */ void GetSourceFiles(std::vector &files, const std::string& config) const; - bool GetConfigCommonSourceFiles(std::vector& files) const; - /** * Add sources to the target. */ diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 464a83a19..e7716d859 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -965,7 +965,7 @@ void cmVisualStudio10TargetGenerator::WriteGroups() std::vector sourceGroups = this->Makefile->GetSourceGroups(); std::vector classes; - if (!this->Target->GetConfigCommonSourceFiles(classes)) + if (!this->GeneratorTarget->GetConfigCommonSourceFiles(classes)) { return; }