| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064 |
- /*============================================================================
- CMake - Cross Platform Makefile Generator
- Copyright 2012 Stephen Kelly <[email protected]>
- Distributed under the OSI-approved BSD License (the "License");
- see accompanying file Copyright.txt for details.
- This software is distributed WITHOUT ANY WARRANTY; without even the
- implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the License for more information.
- ============================================================================*/
- #include "cmMakefile.h"
- #include "cmGeneratorExpressionEvaluator.h"
- #include "cmGeneratorExpressionParser.h"
- #include "cmGeneratorExpressionDAGChecker.h"
- #include "cmGeneratorExpression.h"
- #include <cmsys/String.h>
- #include <assert.h>
- //----------------------------------------------------------------------------
- #if !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x510
- static
- #endif
- void reportError(cmGeneratorExpressionContext *context,
- const std::string &expr, const std::string &result)
- {
- context->HadError = true;
- if (context->Quiet)
- {
- return;
- }
- cmOStringStream e;
- e << "Error evaluating generator expression:\n"
- << " " << expr << "\n"
- << result;
- context->Makefile->GetCMakeInstance()
- ->IssueMessage(cmake::FATAL_ERROR, e.str().c_str(),
- context->Backtrace);
- }
- //----------------------------------------------------------------------------
- struct cmGeneratorExpressionNode
- {
- virtual ~cmGeneratorExpressionNode() {}
- virtual bool GeneratesContent() const { return true; }
- virtual bool RequiresLiteralInput() const { return false; }
- virtual bool AcceptsSingleArbitraryContentParameter() const
- { return false; }
- virtual int NumExpectedParameters() const { return 1; }
- virtual std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *content,
- cmGeneratorExpressionDAGChecker *dagChecker
- ) const = 0;
- };
- //----------------------------------------------------------------------------
- static const struct ZeroNode : public cmGeneratorExpressionNode
- {
- ZeroNode() {}
- virtual bool GeneratesContent() const { return false; }
- virtual bool AcceptsSingleArbitraryContentParameter() const { return true; }
- std::string Evaluate(const std::vector<std::string> &,
- cmGeneratorExpressionContext *,
- const GeneratorExpressionContent *,
- cmGeneratorExpressionDAGChecker *) const
- {
- // Unreachable
- return std::string();
- }
- } zeroNode;
- //----------------------------------------------------------------------------
- static const struct OneNode : public cmGeneratorExpressionNode
- {
- OneNode() {}
- virtual bool AcceptsSingleArbitraryContentParameter() const { return true; }
- std::string Evaluate(const std::vector<std::string> &,
- cmGeneratorExpressionContext *,
- const GeneratorExpressionContent *,
- cmGeneratorExpressionDAGChecker *) const
- {
- // Unreachable
- return std::string();
- }
- } oneNode;
- //----------------------------------------------------------------------------
- static const struct OneNode buildInterfaceNode;
- //----------------------------------------------------------------------------
- static const struct ZeroNode installInterfaceNode;
- //----------------------------------------------------------------------------
- #define BOOLEAN_OP_NODE(OPNAME, OP, SUCCESS_VALUE, FAILURE_VALUE) \
- static const struct OP ## Node : public cmGeneratorExpressionNode \
- { \
- OP ## Node () {} \
- /* We let -1 carry the meaning 'at least one' */ \
- virtual int NumExpectedParameters() const { return -1; } \
- \
- std::string Evaluate(const std::vector<std::string> ¶meters, \
- cmGeneratorExpressionContext *context, \
- const GeneratorExpressionContent *content, \
- cmGeneratorExpressionDAGChecker *) const \
- { \
- std::vector<std::string>::const_iterator it = parameters.begin(); \
- const std::vector<std::string>::const_iterator end = parameters.end(); \
- for ( ; it != end; ++it) \
- { \
- if (*it == #FAILURE_VALUE) \
- { \
- return #FAILURE_VALUE; \
- } \
- else if (*it != #SUCCESS_VALUE) \
- { \
- reportError(context, content->GetOriginalExpression(), \
- "Parameters to $<" #OP "> must resolve to either '0' or '1'."); \
- return std::string(); \
- } \
- } \
- return #SUCCESS_VALUE; \
- } \
- } OPNAME;
- BOOLEAN_OP_NODE(andNode, AND, 1, 0)
- BOOLEAN_OP_NODE(orNode, OR, 0, 1)
- #undef BOOLEAN_OP_NODE
- //----------------------------------------------------------------------------
- static const struct NotNode : public cmGeneratorExpressionNode
- {
- NotNode() {}
- std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *content,
- cmGeneratorExpressionDAGChecker *) const
- {
- if (*parameters.begin() != "0" && *parameters.begin() != "1")
- {
- reportError(context, content->GetOriginalExpression(),
- "$<NOT> parameter must resolve to exactly one '0' or '1' value.");
- return std::string();
- }
- return *parameters.begin() == "0" ? "1" : "0";
- }
- } notNode;
- //----------------------------------------------------------------------------
- static const struct BoolNode : public cmGeneratorExpressionNode
- {
- BoolNode() {}
- virtual int NumExpectedParameters() const { return 1; }
- std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *,
- const GeneratorExpressionContent *,
- cmGeneratorExpressionDAGChecker *) const
- {
- return !cmSystemTools::IsOff(parameters.begin()->c_str()) ? "1" : "0";
- }
- } boolNode;
- //----------------------------------------------------------------------------
- static const struct StrEqualNode : public cmGeneratorExpressionNode
- {
- StrEqualNode() {}
- virtual int NumExpectedParameters() const { return 2; }
- std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *,
- const GeneratorExpressionContent *,
- cmGeneratorExpressionDAGChecker *) const
- {
- return *parameters.begin() == parameters[1] ? "1" : "0";
- }
- } strEqualNode;
- //----------------------------------------------------------------------------
- static const struct Angle_RNode : public cmGeneratorExpressionNode
- {
- Angle_RNode() {}
- virtual int NumExpectedParameters() const { return 0; }
- std::string Evaluate(const std::vector<std::string> &,
- cmGeneratorExpressionContext *,
- const GeneratorExpressionContent *,
- cmGeneratorExpressionDAGChecker *) const
- {
- return ">";
- }
- } angle_rNode;
- //----------------------------------------------------------------------------
- static const struct CommaNode : public cmGeneratorExpressionNode
- {
- CommaNode() {}
- virtual int NumExpectedParameters() const { return 0; }
- std::string Evaluate(const std::vector<std::string> &,
- cmGeneratorExpressionContext *,
- const GeneratorExpressionContent *,
- cmGeneratorExpressionDAGChecker *) const
- {
- return ",";
- }
- } commaNode;
- //----------------------------------------------------------------------------
- static const struct ConfigurationNode : public cmGeneratorExpressionNode
- {
- ConfigurationNode() {}
- virtual int NumExpectedParameters() const { return 0; }
- std::string Evaluate(const std::vector<std::string> &,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *,
- cmGeneratorExpressionDAGChecker *) const
- {
- return context->Config ? context->Config : "";
- }
- } configurationNode;
- //----------------------------------------------------------------------------
- static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
- {
- ConfigurationTestNode() {}
- virtual int NumExpectedParameters() const { return 1; }
- std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *content,
- cmGeneratorExpressionDAGChecker *) const
- {
- cmsys::RegularExpression configValidator;
- configValidator.compile("^[A-Za-z0-9_]*$");
- if (!configValidator.find(parameters.begin()->c_str()))
- {
- reportError(context, content->GetOriginalExpression(),
- "Expression syntax not recognized.");
- return std::string();
- }
- if (!context->Config)
- {
- return parameters.front().empty() ? "1" : "0";
- }
- if (cmsysString_strcasecmp(parameters.begin()->c_str(),
- context->Config) == 0)
- {
- return "1";
- }
- if (context->CurrentTarget
- && context->CurrentTarget->IsImported())
- {
- const char* loc = 0;
- const char* imp = 0;
- std::string suffix;
- return context->CurrentTarget->GetMappedConfig(context->Config,
- &loc,
- &imp,
- suffix) ? "1" : "0";
- }
- return "0";
- }
- } configurationTestNode;
- static const struct TargetDefinedNode : public cmGeneratorExpressionNode
- {
- TargetDefinedNode() {}
- virtual int NumExpectedParameters() const { return 1; }
- std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *,
- cmGeneratorExpressionDAGChecker *) const
- {
- return context->Makefile->FindTargetToUse(parameters.front().c_str())
- ? "1" : "0";
- }
- } targetDefinedNode;
- //----------------------------------------------------------------------------
- static const char* targetPropertyTransitiveWhitelist[] = {
- "INTERFACE_INCLUDE_DIRECTORIES"
- , "INTERFACE_COMPILE_DEFINITIONS"
- };
- //----------------------------------------------------------------------------
- static const struct TargetPropertyNode : public cmGeneratorExpressionNode
- {
- TargetPropertyNode() {}
- // This node handles errors on parameter count itself.
- virtual int NumExpectedParameters() const { return -1; }
- std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *content,
- cmGeneratorExpressionDAGChecker *dagCheckerParent
- ) const
- {
- if (parameters.size() != 1 && parameters.size() != 2)
- {
- reportError(context, content->GetOriginalExpression(),
- "$<TARGET_PROPERTY:...> expression requires one or two parameters");
- return std::string();
- }
- cmsys::RegularExpression targetNameValidator;
- // The ':' is supported to allow use with IMPORTED targets. At least
- // Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter.
- targetNameValidator.compile("^[A-Za-z0-9_.:-]+$");
- cmsys::RegularExpression propertyNameValidator;
- propertyNameValidator.compile("^[A-Za-z0-9_]+$");
- cmTarget* target = context->HeadTarget;
- std::string propertyName = *parameters.begin();
- if (!target && parameters.size() == 1)
- {
- reportError(context, content->GetOriginalExpression(),
- "$<TARGET_PROPERTY:prop> may only be used with targets. It may not "
- "be used with add_custom_command. Specify the target to read a "
- "property from using the $<TARGET_PROPERTY:tgt,prop> signature "
- "instead.");
- return std::string();
- }
- if (parameters.size() == 2)
- {
- if (parameters.begin()->empty() && parameters[1].empty())
- {
- reportError(context, content->GetOriginalExpression(),
- "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
- "target name and property name.");
- return std::string();
- }
- if (parameters.begin()->empty())
- {
- reportError(context, content->GetOriginalExpression(),
- "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
- "target name.");
- return std::string();
- }
- std::string targetName = parameters.front();
- propertyName = parameters[1];
- if (!targetNameValidator.find(targetName.c_str()))
- {
- if (!propertyNameValidator.find(propertyName.c_str()))
- {
- ::reportError(context, content->GetOriginalExpression(),
- "Target name and property name not supported.");
- return std::string();
- }
- ::reportError(context, content->GetOriginalExpression(),
- "Target name not supported.");
- return std::string();
- }
- target = context->Makefile->FindTargetToUse(
- targetName.c_str());
- if (!target)
- {
- cmOStringStream e;
- e << "Target \""
- << targetName
- << "\" not found.";
- reportError(context, content->GetOriginalExpression(), e.str());
- return std::string();
- }
- }
- if (target == context->HeadTarget)
- {
- // Keep track of the properties seen while processing.
- // The evaluation of the LINK_LIBRARIES generator expressions
- // will check this to ensure that properties form a DAG.
- context->SeenTargetProperties.insert(propertyName);
- }
- if (propertyName.empty())
- {
- reportError(context, content->GetOriginalExpression(),
- "$<TARGET_PROPERTY:...> expression requires a non-empty property "
- "name.");
- return std::string();
- }
- if (!propertyNameValidator.find(propertyName.c_str()))
- {
- ::reportError(context, content->GetOriginalExpression(),
- "Property name not supported.");
- return std::string();
- }
- assert(target);
- cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
- target->GetName(),
- propertyName,
- content,
- dagCheckerParent);
- switch (dagChecker.check())
- {
- case cmGeneratorExpressionDAGChecker::SELF_REFERENCE:
- dagChecker.reportError(context, content->GetOriginalExpression());
- return std::string();
- case cmGeneratorExpressionDAGChecker::CYCLIC_REFERENCE:
- // No error. We just skip cyclic references.
- return std::string();
- case cmGeneratorExpressionDAGChecker::DAG:
- break;
- }
- const char *prop = target->GetProperty(propertyName.c_str());
- if (!prop)
- {
- if (target->IsImported())
- {
- return std::string();
- }
- if (dagCheckerParent && dagCheckerParent->EvaluatingLinkLibraries())
- {
- return std::string();
- }
- if (propertyName == "POSITION_INDEPENDENT_CODE")
- {
- return target->GetLinkInterfaceDependentBoolProperty(
- "POSITION_INDEPENDENT_CODE", context->Config) ? "1" : "0";
- }
- if (target->IsLinkInterfaceDependentBoolProperty(propertyName,
- context->Config))
- {
- return target->GetLinkInterfaceDependentBoolProperty(
- propertyName,
- context->Config) ? "1" : "0";
- }
- return std::string();
- }
- for (size_t i = 0;
- i < (sizeof(targetPropertyTransitiveWhitelist) /
- sizeof(*targetPropertyTransitiveWhitelist));
- ++i)
- {
- if (targetPropertyTransitiveWhitelist[i] == propertyName)
- {
- cmGeneratorExpression ge(context->Backtrace);
- return ge.Parse(prop)->Evaluate(context->Makefile,
- context->Config,
- context->Quiet,
- context->HeadTarget,
- target,
- &dagChecker);
- }
- }
- return prop;
- }
- } targetPropertyNode;
- //----------------------------------------------------------------------------
- static const struct TargetNameNode : public cmGeneratorExpressionNode
- {
- TargetNameNode() {}
- virtual bool GeneratesContent() const { return true; }
- virtual bool AcceptsSingleArbitraryContentParameter() const { return true; }
- virtual bool RequiresLiteralInput() const { return true; }
- std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *,
- const GeneratorExpressionContent *,
- cmGeneratorExpressionDAGChecker *) const
- {
- return parameters.front();
- }
- virtual int NumExpectedParameters() const { return 1; }
- } targetNameNode;
- //----------------------------------------------------------------------------
- static const char* targetPolicyWhitelist[] = {
- "CMP0003"
- , "CMP0004"
- , "CMP0008"
- , "CMP0020"
- };
- cmPolicies::PolicyStatus statusForTarget(cmTarget *tgt, const char *policy)
- {
- #define RETURN_POLICY(POLICY) \
- if (strcmp(policy, #POLICY) == 0) \
- { \
- return tgt->GetPolicyStatus ## POLICY (); \
- } \
- RETURN_POLICY(CMP0003)
- RETURN_POLICY(CMP0004)
- RETURN_POLICY(CMP0008)
- RETURN_POLICY(CMP0020)
- #undef RETURN_POLICY
- assert("!Unreachable code. Not a valid policy");
- return cmPolicies::WARN;
- }
- cmPolicies::PolicyID policyForString(const char *policy_id)
- {
- #define RETURN_POLICY_ID(POLICY_ID) \
- if (strcmp(policy_id, #POLICY_ID) == 0) \
- { \
- return cmPolicies:: POLICY_ID; \
- } \
- RETURN_POLICY_ID(CMP0003)
- RETURN_POLICY_ID(CMP0004)
- RETURN_POLICY_ID(CMP0008)
- RETURN_POLICY_ID(CMP0020)
- #undef RETURN_POLICY_ID
- assert("!Unreachable code. Not a valid policy");
- return cmPolicies::CMP0002;
- }
- //----------------------------------------------------------------------------
- static const struct TargetPolicyNode : public cmGeneratorExpressionNode
- {
- TargetPolicyNode() {}
- virtual int NumExpectedParameters() const { return 1; }
- std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *context ,
- const GeneratorExpressionContent *content,
- cmGeneratorExpressionDAGChecker *) const
- {
- if (!context->HeadTarget)
- {
- reportError(context, content->GetOriginalExpression(),
- "$<TARGET_POLICY:prop> may only be used with targets. It may not "
- "be used with add_custom_command.");
- return std::string();
- }
- for (size_t i = 0;
- i < (sizeof(targetPolicyWhitelist) /
- sizeof(*targetPolicyWhitelist));
- ++i)
- {
- const char *policy = targetPolicyWhitelist[i];
- if (parameters.front() == policy)
- {
- cmMakefile *mf = context->HeadTarget->GetMakefile();
- switch(statusForTarget(context->HeadTarget, policy))
- {
- case cmPolicies::WARN:
- mf->IssueMessage(cmake::AUTHOR_WARNING,
- mf->GetPolicies()->
- GetPolicyWarning(policyForString(policy)));
- case cmPolicies::REQUIRED_IF_USED:
- case cmPolicies::REQUIRED_ALWAYS:
- case cmPolicies::OLD:
- return "0";
- case cmPolicies::NEW:
- return "1";
- }
- }
- }
- reportError(context, content->GetOriginalExpression(),
- "$<TARGET_POLICY:prop> may only be used with a limited number of "
- "policies. Currently it may be used with policies CMP0003, CMP0004, "
- "CMP0008 and CMP0020."
- );
- return std::string();
- }
- } targetPolicyNode;
- //----------------------------------------------------------------------------
- template<bool linker, bool soname>
- struct TargetFilesystemArtifactResultCreator
- {
- static std::string Create(cmTarget* target,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *content);
- };
- //----------------------------------------------------------------------------
- template<>
- struct TargetFilesystemArtifactResultCreator<false, true>
- {
- static std::string Create(cmTarget* target,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *content)
- {
- // The target soname file (.so.1).
- if(target->IsDLLPlatform())
- {
- ::reportError(context, content->GetOriginalExpression(),
- "TARGET_SONAME_FILE is not allowed "
- "for DLL target platforms.");
- return std::string();
- }
- if(target->GetType() != cmTarget::SHARED_LIBRARY)
- {
- ::reportError(context, content->GetOriginalExpression(),
- "TARGET_SONAME_FILE is allowed only for "
- "SHARED libraries.");
- return std::string();
- }
- std::string result = target->GetDirectory(context->Config);
- result += "/";
- result += target->GetSOName(context->Config);
- return result;
- }
- };
- //----------------------------------------------------------------------------
- template<>
- struct TargetFilesystemArtifactResultCreator<true, false>
- {
- static std::string Create(cmTarget* target,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *content)
- {
- // The file used to link to the target (.so, .lib, .a).
- if(!target->IsLinkable())
- {
- ::reportError(context, content->GetOriginalExpression(),
- "TARGET_LINKER_FILE is allowed only for libraries and "
- "executables with ENABLE_EXPORTS.");
- return std::string();
- }
- return target->GetFullPath(context->Config,
- target->HasImportLibrary());
- }
- };
- //----------------------------------------------------------------------------
- template<>
- struct TargetFilesystemArtifactResultCreator<false, false>
- {
- static std::string Create(cmTarget* target,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *)
- {
- return target->GetFullPath(context->Config, false, true);
- }
- };
- //----------------------------------------------------------------------------
- template<bool dirQual, bool nameQual>
- struct TargetFilesystemArtifactResultGetter
- {
- static std::string Get(const std::string &result);
- };
- //----------------------------------------------------------------------------
- template<>
- struct TargetFilesystemArtifactResultGetter<false, true>
- {
- static std::string Get(const std::string &result)
- { return cmSystemTools::GetFilenameName(result); }
- };
- //----------------------------------------------------------------------------
- template<>
- struct TargetFilesystemArtifactResultGetter<true, false>
- {
- static std::string Get(const std::string &result)
- { return cmSystemTools::GetFilenamePath(result); }
- };
- //----------------------------------------------------------------------------
- template<>
- struct TargetFilesystemArtifactResultGetter<false, false>
- {
- static std::string Get(const std::string &result)
- { return result; }
- };
- //----------------------------------------------------------------------------
- template<bool linker, bool soname, bool dirQual, bool nameQual>
- struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
- {
- TargetFilesystemArtifact() {}
- virtual int NumExpectedParameters() const { return 1; }
- std::string Evaluate(const std::vector<std::string> ¶meters,
- cmGeneratorExpressionContext *context,
- const GeneratorExpressionContent *content,
- cmGeneratorExpressionDAGChecker *) const
- {
- // Lookup the referenced target.
- std::string name = *parameters.begin();
- cmsys::RegularExpression targetValidator;
- // The ':' is supported to allow use with IMPORTED targets.
- targetValidator.compile("^[A-Za-z0-9_.:-]+$");
- if (!targetValidator.find(name.c_str()))
- {
- ::reportError(context, content->GetOriginalExpression(),
- "Expression syntax not recognized.");
- return std::string();
- }
- cmTarget* target = context->Makefile->FindTargetToUse(name.c_str());
- if(!target)
- {
- ::reportError(context, content->GetOriginalExpression(),
- "No target \"" + name + "\"");
- return std::string();
- }
- if(target->GetType() >= cmTarget::UTILITY &&
- target->GetType() != cmTarget::UNKNOWN_LIBRARY)
- {
- ::reportError(context, content->GetOriginalExpression(),
- "Target \"" + name + "\" is not an executable or library.");
- return std::string();
- }
- context->Targets.insert(target);
- std::string result =
- TargetFilesystemArtifactResultCreator<linker, soname>::Create(
- target,
- context,
- content);
- if (context->HadError)
- {
- return std::string();
- }
- return
- TargetFilesystemArtifactResultGetter<dirQual, nameQual>::Get(result);
- }
- };
- //----------------------------------------------------------------------------
- static const
- TargetFilesystemArtifact<false, false, false, false> targetFileNode;
- static const
- TargetFilesystemArtifact<true, false, false, false> targetLinkerFileNode;
- static const
- TargetFilesystemArtifact<false, true, false, false> targetSoNameFileNode;
- static const
- TargetFilesystemArtifact<false, false, false, true> targetFileNameNode;
- static const
- TargetFilesystemArtifact<true, false, false, true> targetLinkerFileNameNode;
- static const
- TargetFilesystemArtifact<false, true, false, true> targetSoNameFileNameNode;
- static const
- TargetFilesystemArtifact<false, false, true, false> targetFileDirNode;
- static const
- TargetFilesystemArtifact<true, false, true, false> targetLinkerFileDirNode;
- static const
- TargetFilesystemArtifact<false, true, true, false> targetSoNameFileDirNode;
- //----------------------------------------------------------------------------
- static const
- cmGeneratorExpressionNode* GetNode(const std::string &identifier)
- {
- if (identifier == "0")
- return &zeroNode;
- else if (identifier == "1")
- return &oneNode;
- else if (identifier == "AND")
- return &andNode;
- else if (identifier == "OR")
- return &orNode;
- else if (identifier == "NOT")
- return ¬Node;
- else if (identifier == "CONFIGURATION")
- return &configurationNode;
- else if (identifier == "CONFIG")
- return &configurationTestNode;
- else if (identifier == "TARGET_FILE")
- return &targetFileNode;
- else if (identifier == "TARGET_LINKER_FILE")
- return &targetLinkerFileNode;
- else if (identifier == "TARGET_SONAME_FILE")
- return &targetSoNameFileNode;
- else if (identifier == "TARGET_FILE_NAME")
- return &targetFileNameNode;
- else if (identifier == "TARGET_LINKER_FILE_NAME")
- return &targetLinkerFileNameNode;
- else if (identifier == "TARGET_SONAME_FILE_NAME")
- return &targetSoNameFileNameNode;
- else if (identifier == "TARGET_FILE_DIR")
- return &targetFileDirNode;
- else if (identifier == "TARGET_LINKER_FILE_DIR")
- return &targetLinkerFileDirNode;
- else if (identifier == "TARGET_SONAME_FILE_DIR")
- return &targetSoNameFileDirNode;
- else if (identifier == "STREQUAL")
- return &strEqualNode;
- else if (identifier == "BOOL")
- return &boolNode;
- else if (identifier == "ANGLE-R")
- return &angle_rNode;
- else if (identifier == "COMMA")
- return &commaNode;
- else if (identifier == "TARGET_PROPERTY")
- return &targetPropertyNode;
- else if (identifier == "TARGET_NAME")
- return &targetNameNode;
- else if (identifier == "TARGET_POLICY")
- return &targetPolicyNode;
- else if (identifier == "BUILD_INTERFACE")
- return &buildInterfaceNode;
- else if (identifier == "INSTALL_INTERFACE")
- return &installInterfaceNode;
- else if (identifier == "TARGET_DEFINED")
- return &targetDefinedNode;
- return 0;
- }
- //----------------------------------------------------------------------------
- GeneratorExpressionContent::GeneratorExpressionContent(
- const char *startContent,
- unsigned int length)
- : StartContent(startContent), ContentLength(length)
- {
- }
- //----------------------------------------------------------------------------
- std::string GeneratorExpressionContent::GetOriginalExpression() const
- {
- return std::string(this->StartContent, this->ContentLength);
- }
- //----------------------------------------------------------------------------
- std::string GeneratorExpressionContent::Evaluate(
- cmGeneratorExpressionContext *context,
- cmGeneratorExpressionDAGChecker *dagChecker) const
- {
- std::string identifier;
- {
- std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
- = this->IdentifierChildren.begin();
- const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
- = this->IdentifierChildren.end();
- for ( ; it != end; ++it)
- {
- identifier += (*it)->Evaluate(context, dagChecker);
- if (context->HadError)
- {
- return std::string();
- }
- }
- }
- const cmGeneratorExpressionNode *node = GetNode(identifier);
- if (!node)
- {
- reportError(context, this->GetOriginalExpression(),
- "Expression did not evaluate to a known generator expression");
- return std::string();
- }
- if (!node->GeneratesContent())
- {
- if (node->AcceptsSingleArbitraryContentParameter())
- {
- if (this->ParamChildren.empty())
- {
- reportError(context, this->GetOriginalExpression(),
- "$<" + identifier + "> expression requires a parameter.");
- }
- }
- else
- {
- std::vector<std::string> parameters;
- this->EvaluateParameters(node, identifier, context, dagChecker,
- parameters);
- }
- return std::string();
- }
- if (node->AcceptsSingleArbitraryContentParameter())
- {
- std::string result;
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
- pit = this->ParamChildren.begin();
- const
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
- pend = this->ParamChildren.end();
- for ( ; pit != pend; ++pit)
- {
- if (!result.empty())
- {
- result += ",";
- }
- std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
- = pit->begin();
- const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
- = pit->end();
- for ( ; it != end; ++it)
- {
- if (node->RequiresLiteralInput())
- {
- if ((*it)->GetType() != cmGeneratorExpressionEvaluator::Text)
- {
- reportError(context, this->GetOriginalExpression(),
- "$<" + identifier + "> expression requires literal input.");
- return std::string();
- }
- }
- result += (*it)->Evaluate(context, dagChecker);
- if (context->HadError)
- {
- return std::string();
- }
- }
- }
- if (node->RequiresLiteralInput())
- {
- std::vector<std::string> parameters;
- parameters.push_back(result);
- return node->Evaluate(parameters, context, this, dagChecker);
- }
- return result;
- }
- std::vector<std::string> parameters;
- this->EvaluateParameters(node, identifier, context, dagChecker, parameters);
- if (context->HadError)
- {
- return std::string();
- }
- return node->Evaluate(parameters, context, this, dagChecker);
- }
- //----------------------------------------------------------------------------
- std::string GeneratorExpressionContent::EvaluateParameters(
- const cmGeneratorExpressionNode *node,
- const std::string &identifier,
- cmGeneratorExpressionContext *context,
- cmGeneratorExpressionDAGChecker *dagChecker,
- std::vector<std::string> ¶meters) const
- {
- {
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
- pit = this->ParamChildren.begin();
- const
- std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
- pend = this->ParamChildren.end();
- for ( ; pit != pend; ++pit)
- {
- std::string parameter;
- std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it =
- pit->begin();
- const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end =
- pit->end();
- for ( ; it != end; ++it)
- {
- parameter += (*it)->Evaluate(context, dagChecker);
- if (context->HadError)
- {
- return std::string();
- }
- }
- parameters.push_back(parameter);
- }
- }
- int numExpected = node->NumExpectedParameters();
- if ((numExpected != -1 && (unsigned int)numExpected != parameters.size()))
- {
- if (numExpected == 0)
- {
- reportError(context, this->GetOriginalExpression(),
- "$<" + identifier + "> expression requires no parameters.");
- }
- else if (numExpected == 1)
- {
- reportError(context, this->GetOriginalExpression(),
- "$<" + identifier + "> expression requires "
- "exactly one parameter.");
- }
- else
- {
- cmOStringStream e;
- e << "$<" + identifier + "> expression requires "
- << numExpected
- << " comma separated parameters, but got "
- << parameters.size() << " instead.";
- reportError(context, this->GetOriginalExpression(), e.str());
- }
- return std::string();
- }
- if (numExpected == -1 && parameters.empty())
- {
- reportError(context, this->GetOriginalExpression(), "$<" + identifier
- + "> expression requires at least one parameter.");
- }
- return std::string();
- }
- //----------------------------------------------------------------------------
- static void deleteAll(const std::vector<cmGeneratorExpressionEvaluator*> &c)
- {
- std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
- = c.begin();
- const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
- = c.end();
- for ( ; it != end; ++it)
- {
- delete *it;
- }
- }
- //----------------------------------------------------------------------------
- GeneratorExpressionContent::~GeneratorExpressionContent()
- {
- deleteAll(this->IdentifierChildren);
- typedef std::vector<cmGeneratorExpressionEvaluator*> EvaluatorVector;
- typedef std::vector<cmGeneratorExpressionToken> TokenVector;
- std::vector<EvaluatorVector>::const_iterator pit =
- this->ParamChildren.begin();
- const std::vector<EvaluatorVector>::const_iterator pend =
- this->ParamChildren.end();
- for ( ; pit != pend; ++pit)
- {
- deleteAll(*pit);
- }
- }
|