ENH: change expand stuff to pass a struct for all the args
This commit is contained in:
parent
e20c007181
commit
39e636a4a4
|
@ -387,17 +387,15 @@ void cmLocalGenerator::AddCustomCommandToCreateObject(const char* ofname,
|
||||||
flags += this->GetIncludeFlags(lang);
|
flags += this->GetIncludeFlags(lang);
|
||||||
std::vector<std::string> commands;
|
std::vector<std::string> commands;
|
||||||
cmSystemTools::ExpandList(rules, commands);
|
cmSystemTools::ExpandList(rules, commands);
|
||||||
|
cmLocalGenerator::RuleVariables vars;
|
||||||
|
vars.Language = lang;
|
||||||
|
vars.Source = sourceFile.c_str();
|
||||||
|
vars.Object = objectFile.c_str();
|
||||||
|
vars.Flags = flags.c_str();
|
||||||
for(std::vector<std::string>::iterator i = commands.begin();
|
for(std::vector<std::string>::iterator i = commands.begin();
|
||||||
i != commands.end(); ++i)
|
i != commands.end(); ++i)
|
||||||
{
|
{
|
||||||
this->ExpandRuleVariables(*i,
|
this->ExpandRuleVariables(*i, vars);
|
||||||
lang,
|
|
||||||
0, // no objects
|
|
||||||
0, // no target
|
|
||||||
0, // no link libs
|
|
||||||
sourceFile.c_str(),
|
|
||||||
objectFile.c_str(),
|
|
||||||
flags.c_str());
|
|
||||||
}
|
}
|
||||||
std::vector<std::string> sourceAndDeps;
|
std::vector<std::string> sourceAndDeps;
|
||||||
sourceAndDeps.push_back(sourceFile);
|
sourceAndDeps.push_back(sourceFile);
|
||||||
|
@ -472,28 +470,14 @@ void cmLocalGenerator::AddBuildTargetRule(const char* llang, cmTarget& target)
|
||||||
std::string linkFlags; // should be set
|
std::string linkFlags; // should be set
|
||||||
this->GetTargetFlags(linkLibs, flags, linkFlags, target);
|
this->GetTargetFlags(linkLibs, flags, linkFlags, target);
|
||||||
std::string rule = m_Makefile->GetRequiredDefinition(createRule.c_str());
|
std::string rule = m_Makefile->GetRequiredDefinition(createRule.c_str());
|
||||||
this->ExpandRuleVariables(rule,
|
cmLocalGenerator::RuleVariables vars;
|
||||||
llang, // language
|
vars.Language = llang;
|
||||||
objs.c_str(), // objects
|
vars.Objects = objs.c_str();
|
||||||
targetName.c_str(), // target
|
vars.Target = targetName.c_str();
|
||||||
linkLibs.c_str(), // link libs
|
vars.LinkLibraries = linkLibs.c_str();
|
||||||
0, // source
|
vars.Flags = flags.c_str();
|
||||||
0, // object
|
vars.LinkFlags = linkFlags.c_str();
|
||||||
flags.c_str(), // flags
|
this->ExpandRuleVariables(rule, vars);
|
||||||
0, // objects quoted
|
|
||||||
0, // target so name,
|
|
||||||
linkFlags.c_str() // link flags
|
|
||||||
);
|
|
||||||
#if 0
|
|
||||||
std::string command;
|
|
||||||
std::string args;
|
|
||||||
cmSystemTools::SplitProgramFromArgs(rule.c_str(), command, args);
|
|
||||||
// Just like ADD_CUSTOM_TARGET(foo ALL DEPENDS a.o b.o)
|
|
||||||
// Add a custom command for generating each .o file
|
|
||||||
cmCustomCommand cc(command.c_str(), args.c_str(), objVector,
|
|
||||||
targetName.c_str(), 0);
|
|
||||||
target.GetPostBuildCommands().push_back(cc);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -560,76 +544,67 @@ static const char* ruleReplaceVars[] =
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
|
cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
|
||||||
const char* lang,
|
const RuleVariables& replaceValues)
|
||||||
const char* objects,
|
|
||||||
const char* target,
|
|
||||||
const char* linkLibs,
|
|
||||||
const char* source,
|
|
||||||
const char* object,
|
|
||||||
const char* flags,
|
|
||||||
const char* objectsquoted,
|
|
||||||
const char* targetSOName,
|
|
||||||
const char* linkFlags)
|
|
||||||
{
|
{
|
||||||
if(linkFlags)
|
if(replaceValues.LinkFlags)
|
||||||
{
|
{
|
||||||
if(variable == "LINK_FLAGS")
|
if(variable == "LINK_FLAGS")
|
||||||
{
|
{
|
||||||
return linkFlags;
|
return replaceValues.LinkFlags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(flags)
|
if(replaceValues.Flags)
|
||||||
{
|
{
|
||||||
if(variable == "FLAGS")
|
if(variable == "FLAGS")
|
||||||
{
|
{
|
||||||
return flags;
|
return replaceValues.Flags;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(source)
|
if(replaceValues.Source)
|
||||||
{
|
{
|
||||||
if(variable == "SOURCE")
|
if(variable == "SOURCE")
|
||||||
{
|
{
|
||||||
return source;
|
return replaceValues.Source;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(object)
|
if(replaceValues.Object)
|
||||||
{
|
{
|
||||||
if(variable == "OBJECT")
|
if(variable == "OBJECT")
|
||||||
{
|
{
|
||||||
return object;
|
return replaceValues.Object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(objects)
|
if(replaceValues.Objects)
|
||||||
{
|
{
|
||||||
if(variable == "OBJECTS")
|
if(variable == "OBJECTS")
|
||||||
{
|
{
|
||||||
return objects;
|
return replaceValues.Objects;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(objectsquoted)
|
if(replaceValues.ObjectsQuoted)
|
||||||
{
|
{
|
||||||
if(variable == "OBJECTS_QUOTED")
|
if(variable == "OBJECTS_QUOTED")
|
||||||
{
|
{
|
||||||
return objectsquoted;
|
return replaceValues.ObjectsQuoted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(target)
|
if(replaceValues.Target)
|
||||||
{
|
{
|
||||||
if(variable == "TARGET_QUOTED")
|
if(variable == "TARGET_QUOTED")
|
||||||
{
|
{
|
||||||
std::string targetQuoted = target;
|
std::string targetQuoted = replaceValues.Target;
|
||||||
if(targetQuoted.size() && targetQuoted[0] != '\"')
|
if(targetQuoted.size() && targetQuoted[0] != '\"')
|
||||||
{
|
{
|
||||||
targetQuoted = '\"';
|
targetQuoted = '\"';
|
||||||
targetQuoted += target;
|
targetQuoted += replaceValues.Target;
|
||||||
targetQuoted += '\"';
|
targetQuoted += '\"';
|
||||||
return targetQuoted;
|
return targetQuoted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(variable == "TARGET")
|
if(variable == "TARGET")
|
||||||
{
|
{
|
||||||
return target;
|
return replaceValues.Target;
|
||||||
}
|
}
|
||||||
if(variable == "TARGET_IMPLIB")
|
if(variable == "TARGET_IMPLIB")
|
||||||
{
|
{
|
||||||
|
@ -638,7 +613,7 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
|
||||||
if(variable == "TARGET_BASE")
|
if(variable == "TARGET_BASE")
|
||||||
{
|
{
|
||||||
// Strip the last extension off the target name.
|
// Strip the last extension off the target name.
|
||||||
std::string targetBase = target;
|
std::string targetBase = replaceValues.Target;
|
||||||
std::string::size_type pos = targetBase.rfind(".");
|
std::string::size_type pos = targetBase.rfind(".");
|
||||||
if(pos != targetBase.npos)
|
if(pos != targetBase.npos)
|
||||||
{
|
{
|
||||||
|
@ -650,28 +625,28 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(targetSOName)
|
if(replaceValues.TargetSOName)
|
||||||
{
|
{
|
||||||
if(variable == "TARGET_SONAME")
|
if(variable == "TARGET_SONAME")
|
||||||
{
|
{
|
||||||
if(lang)
|
if(replaceValues.Language)
|
||||||
{
|
{
|
||||||
std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
|
std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
|
||||||
name += lang;
|
name += replaceValues.Language;
|
||||||
name += "_FLAG";
|
name += "_FLAG";
|
||||||
if(m_Makefile->GetDefinition(name.c_str()))
|
if(m_Makefile->GetDefinition(name.c_str()))
|
||||||
{
|
{
|
||||||
return targetSOName;
|
return replaceValues.TargetSOName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(linkLibs)
|
if(replaceValues.LinkLibraries)
|
||||||
{
|
{
|
||||||
if(variable == "LINK_LIBRARIES")
|
if(variable == "LINK_LIBRARIES")
|
||||||
{
|
{
|
||||||
return linkLibs;
|
return replaceValues.LinkLibraries;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::vector<std::string> enabledLanguages;
|
std::vector<std::string> enabledLanguages;
|
||||||
|
@ -683,7 +658,7 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
|
||||||
for(std::vector<std::string>::iterator i = enabledLanguages.begin();
|
for(std::vector<std::string>::iterator i = enabledLanguages.begin();
|
||||||
i != enabledLanguages.end(); ++i)
|
i != enabledLanguages.end(); ++i)
|
||||||
{
|
{
|
||||||
lang = i->c_str();
|
const char* lang = i->c_str();
|
||||||
std::string actualReplace = ruleReplaceVars[pos];
|
std::string actualReplace = ruleReplaceVars[pos];
|
||||||
// If this is the compiler then look for the extra variable
|
// If this is the compiler then look for the extra variable
|
||||||
// _COMPILER_ARG1 which must be the first argument to the compiler
|
// _COMPILER_ARG1 which must be the first argument to the compiler
|
||||||
|
@ -724,16 +699,7 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
|
||||||
|
|
||||||
void
|
void
|
||||||
cmLocalGenerator::ExpandRuleVariables(std::string& s,
|
cmLocalGenerator::ExpandRuleVariables(std::string& s,
|
||||||
const char* lang,
|
const RuleVariables& replaceValues)
|
||||||
const char* objects,
|
|
||||||
const char* target,
|
|
||||||
const char* linkLibs,
|
|
||||||
const char* source,
|
|
||||||
const char* object,
|
|
||||||
const char* flags,
|
|
||||||
const char* objectsquoted,
|
|
||||||
const char* targetSOName,
|
|
||||||
const char* linkFlags)
|
|
||||||
{
|
{
|
||||||
std::vector<std::string> enabledLanguages;
|
std::vector<std::string> enabledLanguages;
|
||||||
m_GlobalGenerator->GetEnabledLanguages(enabledLanguages);
|
m_GlobalGenerator->GetEnabledLanguages(enabledLanguages);
|
||||||
|
@ -764,12 +730,8 @@ cmLocalGenerator::ExpandRuleVariables(std::string& s,
|
||||||
{
|
{
|
||||||
// extract the var
|
// extract the var
|
||||||
std::string var = s.substr(start+1, end - start-1);
|
std::string var = s.substr(start+1, end - start-1);
|
||||||
std::string replace = this->ExpandRuleVariable(var, lang, objects,
|
std::string replace = this->ExpandRuleVariable(var,
|
||||||
target, linkLibs,
|
replaceValues);
|
||||||
source, object, flags,
|
|
||||||
objectsquoted,
|
|
||||||
targetSOName,
|
|
||||||
linkFlags);
|
|
||||||
expandedInput += s.substr(pos, start-pos);
|
expandedInput += s.substr(pos, start-pos);
|
||||||
expandedInput += replace;
|
expandedInput += replace;
|
||||||
// move to next one
|
// move to next one
|
||||||
|
|
|
@ -180,30 +180,42 @@ protected:
|
||||||
///! put all the libraries for a target on into the given stream
|
///! put all the libraries for a target on into the given stream
|
||||||
virtual void OutputLinkLibraries(std::ostream&, cmTarget&, bool relink);
|
virtual void OutputLinkLibraries(std::ostream&, cmTarget&, bool relink);
|
||||||
|
|
||||||
|
// Create a struct to hold the varibles passed into
|
||||||
|
// ExpandRuleVariables
|
||||||
|
struct RuleVariables
|
||||||
|
{
|
||||||
|
RuleVariables()
|
||||||
|
{
|
||||||
|
this->Language= 0;
|
||||||
|
this->Objects= 0;
|
||||||
|
this->Target= 0;
|
||||||
|
this->LinkLibraries= 0;
|
||||||
|
this->Source= 0;
|
||||||
|
this->Object= 0;
|
||||||
|
this->Flags= 0;
|
||||||
|
this->ObjectsQuoted= 0;
|
||||||
|
this->TargetSOName= 0;
|
||||||
|
this->LinkFlags= 0;
|
||||||
|
}
|
||||||
|
const char* Language;
|
||||||
|
const char* Objects;
|
||||||
|
const char* Target;
|
||||||
|
const char* LinkLibraries;
|
||||||
|
const char* Source;
|
||||||
|
const char* Object;
|
||||||
|
const char* Flags;
|
||||||
|
const char* ObjectsQuoted;
|
||||||
|
const char* TargetSOName;
|
||||||
|
const char* LinkFlags;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Expand rule variables in CMake of the type found in language rules
|
// Expand rule variables in CMake of the type found in language rules
|
||||||
void ExpandRuleVariables(std::string& string,
|
void ExpandRuleVariables(std::string& string,
|
||||||
const char* language,
|
const RuleVariables& replaceValues);
|
||||||
const char* objects=0,
|
|
||||||
const char* target=0,
|
|
||||||
const char* linkLibs=0,
|
|
||||||
const char* source=0,
|
|
||||||
const char* object =0,
|
|
||||||
const char* flags = 0,
|
|
||||||
const char* objectsquoted = 0,
|
|
||||||
const char* targetSOName = 0,
|
|
||||||
const char* linkFlags = 0);
|
|
||||||
// Expand rule variables in a single string
|
// Expand rule variables in a single string
|
||||||
std::string ExpandRuleVariable(std::string const& variable,
|
std::string ExpandRuleVariable(std::string const& variable,
|
||||||
const char* lang,
|
const RuleVariables& replaceValues);
|
||||||
const char* objects,
|
|
||||||
const char* target,
|
|
||||||
const char* linkLibs,
|
|
||||||
const char* source,
|
|
||||||
const char* object,
|
|
||||||
const char* flags,
|
|
||||||
const char* objectsquoted,
|
|
||||||
const char* targetSOName,
|
|
||||||
const char* linkFlags);
|
|
||||||
|
|
||||||
///! Convert a target to a utility target for unsupported languages of a generator
|
///! Convert a target to a utility target for unsupported languages of a generator
|
||||||
void AddBuildTargetRule(const char* llang, cmTarget& target);
|
void AddBuildTargetRule(const char* llang, cmTarget& target);
|
||||||
|
|
|
@ -294,21 +294,19 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
|
||||||
cleanObjs += variableName;
|
cleanObjs += variableName;
|
||||||
cleanObjs += ")";
|
cleanObjs += ")";
|
||||||
|
|
||||||
|
cmLocalGenerator::RuleVariables vars;
|
||||||
|
vars.Language = linkLanguage;
|
||||||
|
vars.Objects = buildObjs.c_str();
|
||||||
|
vars.Target = targetOutPathReal.c_str();
|
||||||
|
std::string linkString = linklibs.str();
|
||||||
|
vars.LinkLibraries = linkString.c_str();
|
||||||
|
vars.Flags = flags.c_str();
|
||||||
|
vars.LinkFlags = linkFlags.c_str();
|
||||||
// Expand placeholders in the commands.
|
// Expand placeholders in the commands.
|
||||||
for(std::vector<std::string>::iterator i = commands.begin();
|
for(std::vector<std::string>::iterator i = commands.begin();
|
||||||
i != commands.end(); ++i)
|
i != commands.end(); ++i)
|
||||||
{
|
{
|
||||||
this->LocalGenerator->ExpandRuleVariables(*i,
|
this->LocalGenerator->ExpandRuleVariables(*i, vars);
|
||||||
linkLanguage,
|
|
||||||
buildObjs.c_str(),
|
|
||||||
targetOutPathReal.c_str(),
|
|
||||||
linklibs.str().c_str(),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
flags.c_str(),
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
linkFlags.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the build rule.
|
// Write the build rule.
|
||||||
|
|
|
@ -381,20 +381,22 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
|
||||||
std::string cleanObjs = "$(";
|
std::string cleanObjs = "$(";
|
||||||
cleanObjs += variableName;
|
cleanObjs += variableName;
|
||||||
cleanObjs += ")";
|
cleanObjs += ")";
|
||||||
|
cmLocalGenerator::RuleVariables vars;
|
||||||
|
vars.Language = linkLanguage;
|
||||||
|
vars.Objects = buildObjs.c_str();
|
||||||
|
vars.Target = targetOutPathReal.c_str();
|
||||||
|
std::string linkString = linklibs.str();
|
||||||
|
vars.LinkLibraries = linkString.c_str();
|
||||||
|
vars.ObjectsQuoted = buildObjs.c_str();
|
||||||
|
vars.TargetSOName= targetNameSO.c_str();
|
||||||
|
vars.LinkFlags = linkFlags.c_str();
|
||||||
|
|
||||||
// Expand placeholders in the commands.
|
// Expand placeholders in the commands.
|
||||||
this->LocalGenerator->m_TargetImplib = targetOutPathImport;
|
this->LocalGenerator->m_TargetImplib = targetOutPathImport;
|
||||||
for(std::vector<std::string>::iterator i = commands.begin();
|
for(std::vector<std::string>::iterator i = commands.begin();
|
||||||
i != commands.end(); ++i)
|
i != commands.end(); ++i)
|
||||||
{
|
{
|
||||||
this->LocalGenerator->ExpandRuleVariables(*i,
|
this->LocalGenerator->ExpandRuleVariables(*i, vars);
|
||||||
linkLanguage,
|
|
||||||
buildObjs.c_str(),
|
|
||||||
targetOutPathReal.c_str(),
|
|
||||||
linklibs.str().c_str(),
|
|
||||||
0, 0, 0, buildObjs.c_str(),
|
|
||||||
targetNameSO.c_str(),
|
|
||||||
linkFlags.c_str());
|
|
||||||
}
|
}
|
||||||
this->LocalGenerator->m_TargetImplib = "";
|
this->LocalGenerator->m_TargetImplib = "";
|
||||||
|
|
||||||
|
|
|
@ -379,19 +379,17 @@ cmMakefileTargetGenerator
|
||||||
std::string compileRule =
|
std::string compileRule =
|
||||||
this->Makefile->GetRequiredDefinition(compileRuleVar.c_str());
|
this->Makefile->GetRequiredDefinition(compileRuleVar.c_str());
|
||||||
cmSystemTools::ExpandListArgument(compileRule, commands);
|
cmSystemTools::ExpandListArgument(compileRule, commands);
|
||||||
|
cmLocalGenerator::RuleVariables vars;
|
||||||
|
vars.Language = lang;
|
||||||
|
vars.Source = sourceFile.c_str();
|
||||||
|
vars.Object = relativeObj.c_str();
|
||||||
|
vars.Flags = flags.c_str();
|
||||||
|
|
||||||
// Expand placeholders in the commands.
|
// Expand placeholders in the commands.
|
||||||
for(std::vector<std::string>::iterator i = commands.begin();
|
for(std::vector<std::string>::iterator i = commands.begin();
|
||||||
i != commands.end(); ++i)
|
i != commands.end(); ++i)
|
||||||
{
|
{
|
||||||
this->LocalGenerator->ExpandRuleVariables(*i,
|
this->LocalGenerator->ExpandRuleVariables(*i, vars);
|
||||||
lang,
|
|
||||||
0, // no objects
|
|
||||||
0, // no target
|
|
||||||
0, // no link libs
|
|
||||||
sourceFile.c_str(),
|
|
||||||
relativeObj.c_str(),
|
|
||||||
flags.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the target dependency scanning rule include cmake-time-known
|
// Make the target dependency scanning rule include cmake-time-known
|
||||||
|
|
Loading…
Reference in New Issue