ENH: Define RULE_LAUNCH_* properties

This defines global, directory, and target properties
RULE_LAUNCH_COMPILE, RULE_LAUNCH_LINK, and RULE_LAUNCH_CUSTOM.  Their
values specify 'launcher' command lines which are prefixed to compile,
link, and custom build rules by Makefile generators.
This commit is contained in:
Brad King 2009-02-10 08:51:15 -05:00
parent c895d9f2e0
commit b604b98c56
11 changed files with 143 additions and 3 deletions

View File

@ -50,6 +50,7 @@ IF(NOT _CTEST_TARGETS_ADDED)
ADD_CUSTOM_TARGET(${mode}
${CMAKE_CTEST_COMMAND} ${__conf_types} -D ${mode}
)
SET_PROPERTY(TARGET ${mode} PROPERTY RULE_LAUNCH_CUSTOM "")
ENDFOREACH(mode)
# For Makefile generators add more granular targets.
@ -63,6 +64,7 @@ IF(NOT _CTEST_TARGETS_ADDED)
ADD_CUSTOM_TARGET(${mode}${testtype}
${CMAKE_CTEST_COMMAND} ${__conf_types} -D ${mode}${testtype}
)
SET_PROPERTY(TARGET ${mode}${testtype} PROPERTY RULE_LAUNCH_CUSTOM "")
ENDFOREACH(testtype)
ENDFOREACH(mode)
ENDIF("${CMAKE_GENERATOR}" MATCHES Make)

View File

@ -1034,6 +1034,8 @@ cmLocalGenerator::ExpandRuleVariables(std::string& s,
{
std::vector<std::string> enabledLanguages;
this->GlobalGenerator->GetEnabledLanguages(enabledLanguages);
this->InsertRuleLauncher(s, replaceValues.CMTarget,
replaceValues.RuleLauncher);
std::string::size_type start = s.find('<');
// no variables to expand
if(start == s.npos)
@ -1075,6 +1077,32 @@ cmLocalGenerator::ExpandRuleVariables(std::string& s,
s = expandedInput;
}
//----------------------------------------------------------------------------
const char* cmLocalGenerator::GetRuleLauncher(cmTarget* target,
const char* prop)
{
if(target)
{
return target->GetProperty(prop);
}
else
{
return this->Makefile->GetProperty(prop);
}
}
//----------------------------------------------------------------------------
void cmLocalGenerator::InsertRuleLauncher(std::string& s, cmTarget* target,
const char* prop)
{
if(const char* val = this->GetRuleLauncher(target, prop))
{
cmOStringStream wrapped;
wrapped << val << " " << s;
s = wrapped.str();
}
}
//----------------------------------------------------------------------------
std::string
cmLocalGenerator::ConvertToOutputForExistingCommon(const char* remote,

View File

@ -203,6 +203,7 @@ public:
{
memset(this, 0, sizeof(*this));
}
cmTarget* CMTarget;
const char* TargetPDB;
const char* TargetVersionMajor;
const char* TargetVersionMinor;
@ -222,6 +223,7 @@ public:
const char* LinkFlags;
const char* LanguageCompileFlags;
const char* Defines;
const char* RuleLauncher;
};
/** Set whether to treat conversions to SHELL as a link script shell. */
@ -318,6 +320,11 @@ protected:
std::string ExpandRuleVariable(std::string const& variable,
const RuleVariables& replaceValues);
const char* GetRuleLauncher(cmTarget* target, const char* prop);
void InsertRuleLauncher(std::string& s, cmTarget* target,
const char* prop);
/** Convert a target to a utility target for unsupported
* languages of a generator */
void AddBuildTargetRule(const char* llang, cmTarget& target);

View File

@ -974,7 +974,6 @@ cmLocalUnixMakefileGenerator3
cmLocalGenerator::RelativeRoot relative,
std::ostream* content)
{
static_cast<void>(target); // Future use
// Optionally create a command to display the custom command's
// comment text. This is used for pre-build, pre-link, and
// post-build command comments. Custom build step commands have
@ -1043,7 +1042,9 @@ cmLocalUnixMakefileGenerator3
cmd = scmd;
}
}
cmd = this->Convert(cmd.c_str(),NONE,SHELL);
std::string launcher =
this->MakeLauncher(cc, target, workingDir? NONE : START_OUTPUT);
cmd = launcher + this->Convert(cmd.c_str(),NONE,SHELL);
for(unsigned int j=1; j < commandLine.size(); ++j)
{
cmd += " ";
@ -1059,7 +1060,8 @@ cmLocalUnixMakefileGenerator3
}
if(content)
{
*content << cmd;
// Rule content does not include the launcher.
*content << (cmd.c_str()+launcher.size());
}
if(this->BorlandMakeCurlyHack)
{
@ -1093,6 +1095,35 @@ cmLocalUnixMakefileGenerator3
commands.insert(commands.end(), commands1.begin(), commands1.end());
}
//----------------------------------------------------------------------------
std::string
cmLocalUnixMakefileGenerator3::MakeLauncher(const cmCustomCommand& cc,
cmTarget* target,
RelativeRoot relative)
{
// Short-circuit if there is no launcher.
const char* prop = "RULE_LAUNCH_CUSTOM";
const char* val = this->GetRuleLauncher(target, prop);
if(!(val && *val))
{
return "";
}
// Expand rules in the empty string. It may insert the launcher and
// perform replacements.
RuleVariables vars;
vars.RuleLauncher = prop;
vars.CMTarget = target;
std::string launcher;
this->ExpandRuleVariables(launcher, vars);
if(!launcher.empty())
{
launcher += " ";
}
return launcher;
}
//----------------------------------------------------------------------------
void
cmLocalUnixMakefileGenerator3

View File

@ -347,6 +347,9 @@ protected:
void CheckMultipleOutputs(bool verbose);
private:
std::string MakeLauncher(const cmCustomCommand& cc, cmTarget* target,
RelativeRoot relative);
friend class cmMakefileTargetGenerator;
friend class cmMakefileExecutableTargetGenerator;
friend class cmMakefileLibraryTargetGenerator;

View File

@ -3564,6 +3564,25 @@ void cmMakefile::DefineProperties(cmake *cm)
"This read-only property specifies the list of directories given "
"so far to the link_directories command. "
"It is intended for debugging purposes.", false);
cm->DefineProperty
("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
"Specify a launcher for compile rules.",
"See the global property of the same name for details. "
"This overrides the global property for a directory.",
true);
cm->DefineProperty
("RULE_LAUNCH_LINK", cmProperty::DIRECTORY,
"Specify a launcher for link rules.",
"See the global property of the same name for details. "
"This overrides the global property for a directory.",
true);
cm->DefineProperty
("RULE_LAUNCH_CUSTOM", cmProperty::DIRECTORY,
"Specify a launcher for custom rules.",
"See the global property of the same name for details. "
"This overrides the global property for a directory.",
true);
}
//----------------------------------------------------------------------------

View File

@ -360,6 +360,8 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
buildObjs, depends);
cmLocalGenerator::RuleVariables vars;
vars.RuleLauncher = "RULE_LAUNCH_LINK";
vars.CMTarget = this->Target;
vars.Language = linkLanguage;
vars.Objects = buildObjs.c_str();
vars.Target = targetOutPathReal.c_str();

View File

@ -713,6 +713,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules
vars.TargetVersionMajor = targetVersionMajor.c_str();
vars.TargetVersionMinor = targetVersionMinor.c_str();
vars.RuleLauncher = "RULE_LAUNCH_LINK";
vars.CMTarget = this->Target;
vars.Language = linkLanguage;
vars.Objects = buildObjs.c_str();
std::string objdir = cmake::GetCMakeFilesDirectoryPostSlash();

View File

@ -619,6 +619,8 @@ cmMakefileTargetGenerator
cmLocalGenerator::SHELL);
}
cmLocalGenerator::RuleVariables vars;
vars.RuleLauncher = "RULE_LAUNCH_COMPILE";
vars.CMTarget = this->Target;
vars.Language = lang;
vars.TargetPDB = targetOutPathPDB.c_str();
vars.Source = sourceFile.c_str();

View File

@ -522,6 +522,25 @@ void cmTarget::DefineProperties(cmake *cm)
"On non-Apple platforms these files may be installed using the "
"RESOURCE option to the install(TARGETS) command.");
cm->DefineProperty
("RULE_LAUNCH_COMPILE", cmProperty::TARGET,
"Specify a launcher for compile rules.",
"See the global property of the same name for details. "
"This overrides the global and directory property for a target.",
true);
cm->DefineProperty
("RULE_LAUNCH_LINK", cmProperty::TARGET,
"Specify a launcher for link rules.",
"See the global property of the same name for details. "
"This overrides the global and directory property for a target.",
true);
cm->DefineProperty
("RULE_LAUNCH_CUSTOM", cmProperty::TARGET,
"Specify a launcher for custom rules.",
"See the global property of the same name for details. "
"This overrides the global and directory property for a target.",
true);
cm->DefineProperty
("SKIP_BUILD_RPATH", cmProperty::TARGET,
"Should rpaths be used for the build tree.",

View File

@ -3444,6 +3444,31 @@ void cmake::DefineProperties(cmake *cm)
"enabled languages",
"Set to list of currently enabled lanauges.");
cm->DefineProperty
("RULE_LAUNCH_COMPILE", cmProperty::GLOBAL,
"Specify a launcher for compile rules.",
"Makefile generators prefix compiler commands with the given "
"launcher command line. "
"This is intended to allow launchers to intercept build problems "
"with high granularity. "
"Non-Makefile generators currently ignore this property.");
cm->DefineProperty
("RULE_LAUNCH_LINK", cmProperty::GLOBAL,
"Specify a launcher for link rules.",
"Makefile generators prefix link and archive commands with the given "
"launcher command line. "
"This is intended to allow launchers to intercept build problems "
"with high granularity. "
"Non-Makefile generators currently ignore this property.");
cm->DefineProperty
("RULE_LAUNCH_CUSTOM", cmProperty::GLOBAL,
"Specify a launcher for custom rules.",
"Makefile generators prefix custom commands with the given "
"launcher command line. "
"This is intended to allow launchers to intercept build problems "
"with high granularity. "
"Non-Makefile generators currently ignore this property.");
// ================================================================
// define variables as well
// ================================================================