|
@@ -592,11 +592,6 @@ void cmLocalGenerator::CreateCustomTargetsAndCommands(std::set<cmStdString> cons
|
|
|
}
|
|
|
|
|
|
|
|
|
-struct RuleVariables
|
|
|
-{
|
|
|
- const char* variable;
|
|
|
-};
|
|
|
-
|
|
|
|
|
|
// List of variables that are replaced when
|
|
|
// rules are expanced. These variables are
|
|
@@ -605,6 +600,7 @@ struct RuleVariables
|
|
|
// languages.
|
|
|
static const char* ruleReplaceVars[] =
|
|
|
{
|
|
|
+ "CMAKE_${LANG}_COMPILER",
|
|
|
"CMAKE_SHARED_LIBRARY_CREATE_${LANG}_FLAGS",
|
|
|
"CMAKE_SHARED_MODULE_CREATE_${LANG}_FLAGS",
|
|
|
"CMAKE_SHARED_MODULE_${LANG}_FLAGS",
|
|
@@ -612,7 +608,6 @@ static const char* ruleReplaceVars[] =
|
|
|
"CMAKE_${LANG}_LINK_FLAGS",
|
|
|
"CMAKE_SHARED_LIBRARY_SONAME_${LANG}_FLAG",
|
|
|
"CMAKE_${LANG}_ARCHIVE",
|
|
|
- "CMAKE_${LANG}_COMPILER",
|
|
|
"CMAKE_AR",
|
|
|
"CMAKE_CURRENT_SOURCE_DIR",
|
|
|
"CMAKE_CURRENT_BINARY_DIR",
|
|
@@ -620,103 +615,135 @@ static const char* ruleReplaceVars[] =
|
|
|
0
|
|
|
};
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-void
|
|
|
-cmLocalGenerator::ExpandRuleVariables(std::string& s,
|
|
|
- const char* lang,
|
|
|
- const char* objects,
|
|
|
- const char* target,
|
|
|
- const char* linkLibs,
|
|
|
- const char* source,
|
|
|
- const char* object,
|
|
|
- const char* flags,
|
|
|
- const char* objectsquoted,
|
|
|
- const char* targetBase,
|
|
|
- const char* targetSOName,
|
|
|
- const char* linkFlags)
|
|
|
+std::string
|
|
|
+cmLocalGenerator::ExpandRuleVariable(std::string const& variable,
|
|
|
+ const char* lang,
|
|
|
+ const char* objects,
|
|
|
+ const char* target,
|
|
|
+ const char* linkLibs,
|
|
|
+ const char* source,
|
|
|
+ const char* object,
|
|
|
+ const char* flags,
|
|
|
+ const char* objectsquoted,
|
|
|
+ const char* targetBase,
|
|
|
+ const char* targetSOName,
|
|
|
+ const char* linkFlags)
|
|
|
{
|
|
|
- std::vector<std::string> enabledLanguages;
|
|
|
- m_GlobalGenerator->GetEnabledLanguages(enabledLanguages);
|
|
|
-
|
|
|
if(linkFlags)
|
|
|
{
|
|
|
- cmSystemTools::ReplaceString(s, "<LINK_FLAGS>", linkFlags);
|
|
|
+ if(variable == "LINK_FLAGS")
|
|
|
+ {
|
|
|
+ return linkFlags;
|
|
|
+ }
|
|
|
}
|
|
|
if(flags)
|
|
|
{
|
|
|
- cmSystemTools::ReplaceString(s, "<FLAGS>", flags);
|
|
|
+ if(variable == "FLAGS")
|
|
|
+ {
|
|
|
+ return flags;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(source)
|
|
|
{
|
|
|
- cmSystemTools::ReplaceString(s, "<SOURCE>", source);
|
|
|
+ if(variable == "SOURCE")
|
|
|
+ {
|
|
|
+ return source;
|
|
|
+ }
|
|
|
}
|
|
|
if(object)
|
|
|
{
|
|
|
- cmSystemTools::ReplaceString(s, "<OBJECT>", object);
|
|
|
+ if(variable == "OBJECT")
|
|
|
+ {
|
|
|
+ return object;
|
|
|
+ }
|
|
|
}
|
|
|
if(objects)
|
|
|
{
|
|
|
- cmSystemTools::ReplaceString(s, "<OBJECTS>", objects);
|
|
|
+ if(variable == "OBJECTS")
|
|
|
+ {
|
|
|
+ return objects;
|
|
|
+ }
|
|
|
}
|
|
|
if(objectsquoted)
|
|
|
{
|
|
|
- cmSystemTools::ReplaceString(s, "<OBJECTS_QUOTED>", objectsquoted);
|
|
|
+ if(variable == "OBJECTS_QUOTED")
|
|
|
+ {
|
|
|
+ return objectsquoted;
|
|
|
+ }
|
|
|
}
|
|
|
if(target)
|
|
|
{
|
|
|
- std::string targetQuoted = target;
|
|
|
- if(targetQuoted.size() && targetQuoted[0] != '\"')
|
|
|
+ if(variable == "TARGET_QUOTED")
|
|
|
+ {
|
|
|
+ std::string targetQuoted = target;
|
|
|
+ if(targetQuoted.size() && targetQuoted[0] != '\"')
|
|
|
+ {
|
|
|
+ targetQuoted = '\"';
|
|
|
+ targetQuoted += target;
|
|
|
+ targetQuoted += '\"';
|
|
|
+ return targetQuoted;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(variable == "TARGET")
|
|
|
{
|
|
|
- targetQuoted = '\"';
|
|
|
- targetQuoted += target;
|
|
|
- targetQuoted += '\"';
|
|
|
+ return target;
|
|
|
}
|
|
|
- cmSystemTools::ReplaceString(s, "<TARGET_QUOTED>", targetQuoted.c_str());
|
|
|
- cmSystemTools::ReplaceString(s, "<TARGET>", target);
|
|
|
}
|
|
|
if(targetBase)
|
|
|
{
|
|
|
- // special case for quoted paths with spaces
|
|
|
- // if you see <TARGET_BASE>.lib then put the .lib inside
|
|
|
- // the quotes, same for .dll
|
|
|
- if((strlen(targetBase) > 1) && targetBase[0] == '\"')
|
|
|
+ if(variable == "TARGET_BASE.lib" || variable == "TARGET_BASE.dll")
|
|
|
+ {
|
|
|
+ // special case for quoted paths with spaces
|
|
|
+ // if you see <TARGET_BASE>.lib then put the .lib inside
|
|
|
+ // the quotes, same for .dll
|
|
|
+ if((strlen(targetBase) > 1) && targetBase[0] == '\"')
|
|
|
+ {
|
|
|
+ std::string base = targetBase;
|
|
|
+ base[base.size()-1] = '.';
|
|
|
+ std::string baseLib = base + "lib\"";
|
|
|
+ std::string baseDll = base + "dll\"";
|
|
|
+ if(variable == "TARGET_BASE.lib" )
|
|
|
+ {
|
|
|
+ return baseLib;
|
|
|
+ }
|
|
|
+ if(variable == "TARGET_BASE.dll" )
|
|
|
+ {
|
|
|
+ return baseDll;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(variable == "TARGET_BASE")
|
|
|
{
|
|
|
- std::string base = targetBase;
|
|
|
- base[base.size()-1] = '.';
|
|
|
- std::string baseLib = base + "lib\"";
|
|
|
- std::string baseDll = base + "dll\"";
|
|
|
- cmSystemTools::ReplaceString(s, "<TARGET_BASE>.lib", baseLib.c_str());
|
|
|
- cmSystemTools::ReplaceString(s, "<TARGET_BASE>.dll", baseDll.c_str());
|
|
|
+ return targetBase;
|
|
|
}
|
|
|
- cmSystemTools::ReplaceString(s, "<TARGET_BASE>", targetBase);
|
|
|
}
|
|
|
if(targetSOName)
|
|
|
{
|
|
|
- bool replaced = false;
|
|
|
- if(lang)
|
|
|
+ if(variable == "TARGET_SONAME")
|
|
|
{
|
|
|
- std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
|
|
|
- name += lang;
|
|
|
- name += "_FLAG";
|
|
|
- if(m_Makefile->GetDefinition(name.c_str()))
|
|
|
+ if(lang)
|
|
|
{
|
|
|
- replaced = true;
|
|
|
- cmSystemTools::ReplaceString(s, "<TARGET_SONAME>", targetSOName);
|
|
|
+ std::string name = "CMAKE_SHARED_LIBRARY_SONAME_";
|
|
|
+ name += lang;
|
|
|
+ name += "_FLAG";
|
|
|
+ if(m_Makefile->GetDefinition(name.c_str()))
|
|
|
+ {
|
|
|
+ return targetSOName;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if(!replaced)
|
|
|
- {
|
|
|
- cmSystemTools::ReplaceString(s, "<TARGET_SONAME>", "");
|
|
|
+ return "";
|
|
|
}
|
|
|
}
|
|
|
if(linkLibs)
|
|
|
{
|
|
|
- cmSystemTools::ReplaceString(s, "<LINK_LIBRARIES>", linkLibs);
|
|
|
+ if(variable == "LINK_LIBRARIES")
|
|
|
+ {
|
|
|
+ return linkLibs;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+ std::vector<std::string> enabledLanguages;
|
|
|
+ m_GlobalGenerator->GetEnabledLanguages(enabledLanguages);
|
|
|
// loop over language specific replace variables
|
|
|
int pos = 0;
|
|
|
while(ruleReplaceVars[pos])
|
|
@@ -725,27 +752,87 @@ cmLocalGenerator::ExpandRuleVariables(std::string& s,
|
|
|
i != enabledLanguages.end(); ++i)
|
|
|
{
|
|
|
lang = i->c_str();
|
|
|
- std::string replace = "<";
|
|
|
- replace += ruleReplaceVars[pos];
|
|
|
- replace += ">";
|
|
|
- std::string replaceWith = ruleReplaceVars[pos];
|
|
|
- std::string actualReplace = replace;
|
|
|
- cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
|
|
|
- std::string actualReplaceWith = replaceWith;
|
|
|
- cmSystemTools::ReplaceString(actualReplaceWith, "${LANG}", lang);
|
|
|
- replace = m_Makefile->GetSafeDefinition(actualReplaceWith.c_str());
|
|
|
- // if the variable is not a FLAG then treat it like a path
|
|
|
- if(actualReplaceWith.find("_FLAG") == actualReplaceWith.npos)
|
|
|
+ std::string actualReplace = ruleReplaceVars[pos];
|
|
|
+ if(actualReplace.find("${LANG}") != actualReplace.npos)
|
|
|
{
|
|
|
- replace = this->ConvertToOutputForExisting(replace.c_str());
|
|
|
+ cmSystemTools::ReplaceString(actualReplace, "${LANG}", lang);
|
|
|
}
|
|
|
- if(actualReplace.size())
|
|
|
+ if(actualReplace == variable)
|
|
|
{
|
|
|
- cmSystemTools::ReplaceString(s, actualReplace.c_str(), replace.c_str());
|
|
|
+ std::string replace = m_Makefile->GetSafeDefinition(variable.c_str());
|
|
|
+ // if the variable is not a FLAG then treat it like a path
|
|
|
+ if(variable.find("_FLAG") == variable.npos)
|
|
|
+ {
|
|
|
+ return this->ConvertToOutputForExisting(replace.c_str());
|
|
|
+ }
|
|
|
+ return replace;
|
|
|
}
|
|
|
}
|
|
|
pos++;
|
|
|
}
|
|
|
+ return variable;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+void
|
|
|
+cmLocalGenerator::ExpandRuleVariables(std::string& s,
|
|
|
+ const char* lang,
|
|
|
+ const char* objects,
|
|
|
+ const char* target,
|
|
|
+ const char* linkLibs,
|
|
|
+ const char* source,
|
|
|
+ const char* object,
|
|
|
+ const char* flags,
|
|
|
+ const char* objectsquoted,
|
|
|
+ const char* targetBase,
|
|
|
+ const char* targetSOName,
|
|
|
+ const char* linkFlags)
|
|
|
+{
|
|
|
+ std::vector<std::string> enabledLanguages;
|
|
|
+ m_GlobalGenerator->GetEnabledLanguages(enabledLanguages);
|
|
|
+ std::string::size_type start = s.find('<');
|
|
|
+ // no variables to expand
|
|
|
+ if(start == s.npos)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ std::string::size_type pos = 0;
|
|
|
+ std::string expandedInput;
|
|
|
+ while(start != s.npos && start < s.size()-2)
|
|
|
+ {
|
|
|
+ std::string::size_type end = s.find('>', start);
|
|
|
+ // if we find a < with no > we are done
|
|
|
+ if(end == s.npos)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ char c = s[start+1];
|
|
|
+ // if the next char after the < is not A-Za-z then
|
|
|
+ // skip it and try to find the next < in the string
|
|
|
+ if(!isalpha(c))
|
|
|
+ {
|
|
|
+ start = s.find('<', start+1);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // extract the var
|
|
|
+ std::string var = s.substr(start+1, end - start-1);
|
|
|
+ std::string replace = this->ExpandRuleVariable(var, lang, objects,
|
|
|
+ target, linkLibs,
|
|
|
+ source, object, flags,
|
|
|
+ objectsquoted,
|
|
|
+ targetBase, targetSOName,
|
|
|
+ linkFlags);
|
|
|
+ expandedInput += s.substr(pos, start-pos);
|
|
|
+ expandedInput += replace;
|
|
|
+ // move to next one
|
|
|
+ start = s.find('<', start+var.size()+2);
|
|
|
+ pos = end+1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // add the rest of the input
|
|
|
+ expandedInput += s.substr(pos, s.size()-pos);
|
|
|
+ s = expandedInput;
|
|
|
}
|
|
|
|
|
|
|