From b604b98c5690c49109ad464190c1b8a7562410b0 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 10 Feb 2009 08:51:15 -0500 Subject: 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. --- Modules/CTestTargets.cmake | 2 ++ Source/cmLocalGenerator.cxx | 28 +++++++++++++++++++ Source/cmLocalGenerator.h | 7 +++++ Source/cmLocalUnixMakefileGenerator3.cxx | 37 +++++++++++++++++++++++--- Source/cmLocalUnixMakefileGenerator3.h | 3 +++ Source/cmMakefile.cxx | 19 +++++++++++++ Source/cmMakefileExecutableTargetGenerator.cxx | 2 ++ Source/cmMakefileLibraryTargetGenerator.cxx | 2 ++ Source/cmMakefileTargetGenerator.cxx | 2 ++ Source/cmTarget.cxx | 19 +++++++++++++ Source/cmake.cxx | 25 +++++++++++++++++ 11 files changed, 143 insertions(+), 3 deletions(-) diff --git a/Modules/CTestTargets.cmake b/Modules/CTestTargets.cmake index 87f5819..05ada72 100644 --- a/Modules/CTestTargets.cmake +++ b/Modules/CTestTargets.cmake @@ -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) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index c496686..8555064 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1034,6 +1034,8 @@ cmLocalGenerator::ExpandRuleVariables(std::string& s, { std::vector 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) @@ -1076,6 +1078,32 @@ cmLocalGenerator::ExpandRuleVariables(std::string& s, } //---------------------------------------------------------------------------- +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, std::string const& result) diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index 5f962ad..a624e66 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -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. */ @@ -317,6 +319,11 @@ protected: // Expand rule variables in a single string 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 */ diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index 099ea98..3910bc1 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -974,7 +974,6 @@ cmLocalUnixMakefileGenerator3 cmLocalGenerator::RelativeRoot relative, std::ostream* content) { - static_cast(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) { @@ -1094,6 +1096,35 @@ cmLocalUnixMakefileGenerator3 } //---------------------------------------------------------------------------- +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 ::AppendCleanCommand(std::vector& commands, diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index 3025078..15fafa5 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -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; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 870fd6f..3a8ab2a 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -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); } //---------------------------------------------------------------------------- diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx index 6a75902..a96d297 100644 --- a/Source/cmMakefileExecutableTargetGenerator.cxx +++ b/Source/cmMakefileExecutableTargetGenerator.cxx @@ -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(); diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx index 7e5edc4..285a565 100644 --- a/Source/cmMakefileLibraryTargetGenerator.cxx +++ b/Source/cmMakefileLibraryTargetGenerator.cxx @@ -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(); diff --git a/Source/cmMakefileTargetGenerator.cxx b/Source/cmMakefileTargetGenerator.cxx index 6bc5bd2..3f41a99 100644 --- a/Source/cmMakefileTargetGenerator.cxx +++ b/Source/cmMakefileTargetGenerator.cxx @@ -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(); diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index f07d143..5bd141d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -523,6 +523,25 @@ void cmTarget::DefineProperties(cmake *cm) "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.", "SKIP_BUILD_RPATH is a boolean specifying whether to skip automatic " diff --git a/Source/cmake.cxx b/Source/cmake.cxx index eda91a3..1df573e 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -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 // ================================================================ -- cgit v0.12