diff options
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 105 |
1 files changed, 69 insertions, 36 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 46a6161..a220cd8 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -2,10 +2,20 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmNinjaTargetGenerator.h" +#include <algorithm> +#include <assert.h> +#include <cm_jsoncpp_value.h> +#include <cm_jsoncpp_writer.h> +#include <iterator> +#include <map> +#include <sstream> +#include <string.h> + #include "cmAlgorithms.h" #include "cmComputeLinkInformation.h" #include "cmCustomCommandGenerator.h" #include "cmGeneratedFileStream.h" +#include "cmGeneratorExpression.h" #include "cmGeneratorTarget.h" #include "cmGlobalNinjaGenerator.h" #include "cmLocalGenerator.h" @@ -14,31 +24,26 @@ #include "cmNinjaNormalTargetGenerator.h" #include "cmNinjaUtilityTargetGenerator.h" #include "cmOutputConverter.h" +#include "cmRulePlaceholderExpander.h" #include "cmSourceFile.h" #include "cmState.h" +#include "cmStateTypes.h" #include "cmSystemTools.h" +#include "cm_auto_ptr.hxx" #include "cmake.h" -#include "cm_jsoncpp_writer.h" - -#include <algorithm> -#include <iterator> -#include <map> -#include <sstream> -#include <string.h> - cmNinjaTargetGenerator* cmNinjaTargetGenerator::New(cmGeneratorTarget* target) { switch (target->GetType()) { - case cmState::EXECUTABLE: - case cmState::SHARED_LIBRARY: - case cmState::STATIC_LIBRARY: - case cmState::MODULE_LIBRARY: - case cmState::OBJECT_LIBRARY: + case cmStateEnums::EXECUTABLE: + case cmStateEnums::SHARED_LIBRARY: + case cmStateEnums::STATIC_LIBRARY: + case cmStateEnums::MODULE_LIBRARY: + case cmStateEnums::OBJECT_LIBRARY: return new cmNinjaNormalTargetGenerator(target); - case cmState::UTILITY: - case cmState::GLOBAL_TARGET: + case cmStateEnums::UTILITY: + case cmStateEnums::GLOBAL_TARGET: return new cmNinjaUtilityTargetGenerator(target); default: @@ -130,8 +135,14 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject( } // Add source file specific flags. - this->LocalGenerator->AppendFlags(flags, - source->GetProperty("COMPILE_FLAGS")); + if (const char* cflags = source->GetProperty("COMPILE_FLAGS")) { + std::string config = this->LocalGenerator->GetConfigName(); + cmGeneratorExpression ge; + CM_AUTO_PTR<cmCompiledGeneratorExpression> cge = ge.Parse(cflags); + const char* evaluatedFlags = cge->Evaluate(this->LocalGenerator, config, + false, this->GeneratorTarget); + this->LocalGenerator->AppendFlags(flags, evaluatedFlags); + } return flags; } @@ -185,8 +196,8 @@ std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source, cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const { // Static libraries never depend on other targets for linking. - if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY || - this->GeneratorTarget->GetType() == cmState::OBJECT_LIBRARY) { + if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY || + this->GeneratorTarget->GetType() == cmStateEnums::OBJECT_LIBRARY) { return cmNinjaDeps(); } @@ -273,8 +284,9 @@ std::string cmNinjaTargetGenerator::GetPreprocessedFilePath( objName.substr(0, objName.size() - objExt.size()) + "-pp." + ppExt; std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); - if (!path.empty()) + if (!path.empty()) { path += "/"; + } path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); path += "/"; path += ppName; @@ -285,8 +297,9 @@ std::string cmNinjaTargetGenerator::GetDyndepFilePath( std::string const& lang) const { std::string path = this->LocalGenerator->GetHomeRelativeOutputPath(); - if (!path.empty()) + if (!path.empty()) { path += "/"; + } path += this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); path += "/"; path += lang; @@ -334,15 +347,15 @@ bool cmNinjaTargetGenerator::SetMsvcTargetPdbVariable(cmNinjaVars& vars) const mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID")) { std::string pdbPath; std::string compilePdbPath; - if (this->GeneratorTarget->GetType() == cmState::EXECUTABLE || - this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY || - this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY || - this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) { + if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE || + this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY || + this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY || + this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) { pdbPath = this->GeneratorTarget->GetPDBDirectory(this->GetConfigName()); pdbPath += "/"; pdbPath += this->GeneratorTarget->GetPDBName(this->GetConfigName()); } - if (this->GeneratorTarget->GetType() <= cmState::OBJECT_LIBRARY) { + if (this->GeneratorTarget->GetType() <= cmStateEnums::OBJECT_LIBRARY) { compilePdbPath = this->GeneratorTarget->GetCompilePDBPath(this->GetConfigName()); if (compilePdbPath.empty()) { @@ -373,9 +386,10 @@ void cmNinjaTargetGenerator::WriteLanguageRules(const std::string& language) void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) { - cmLocalGenerator::RuleVariables vars; - vars.RuleLauncher = "RULE_LAUNCH_COMPILE"; - vars.CMTarget = this->GetGeneratorTarget(); + cmRulePlaceholderExpander::RuleVariables vars; + vars.CMTargetName = this->GetGeneratorTarget()->GetName().c_str(); + vars.CMTargetType = + cmState::GetTargetTypeName(this->GetGeneratorTarget()->GetType()); vars.Language = lang.c_str(); vars.Source = "$IN_ABS"; vars.Object = "$out"; @@ -452,10 +466,21 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) vars.Flags = flags.c_str(); vars.DependencyFile = depfile.c_str(); + CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + this->GetLocalGenerator()->CreateRulePlaceholderExpander()); + std::string const tdi = this->GetLocalGenerator()->ConvertToOutputFormat( ConvertToNinjaPath(this->GetTargetDependInfoPath(lang)), cmLocalGenerator::SHELL); + std::string launcher; + const char* val = this->GetLocalGenerator()->GetRuleLauncher( + this->GetGeneratorTarget(), "RULE_LAUNCH_COMPILE"); + if (val && *val) { + launcher = val; + launcher += " "; + } + if (explicitPP) { // Lookup the explicit preprocessing rule. std::string const ppVar = "CMAKE_" + lang + "_PREPROCESS_SOURCE"; @@ -466,9 +491,9 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) std::string const ppDeptype = ""; // no deps= for multiple outputs std::string const ppDepfile = "$DEP_FILE"; - cmLocalGenerator::RuleVariables ppVars; - ppVars.RuleLauncher = vars.RuleLauncher; - ppVars.CMTarget = vars.CMTarget; + cmRulePlaceholderExpander::RuleVariables ppVars; + ppVars.CMTargetName = vars.CMTargetName; + ppVars.CMTargetType = vars.CMTargetType; ppVars.Language = vars.Language; ppVars.Object = "$out"; // for RULE_LAUNCH_COMPILE ppVars.PreprocessedSource = "$out"; @@ -496,7 +521,9 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) for (std::vector<std::string>::iterator i = ppCmds.begin(); i != ppCmds.end(); ++i) { - this->GetLocalGenerator()->ExpandRuleVariables(*i, ppVars); + *i = launcher + *i; + rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), + *i, ppVars); } // Run CMake dependency scanner on preprocessed output. @@ -608,7 +635,9 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) for (std::vector<std::string>::iterator i = compileCmds.begin(); i != compileCmds.end(); ++i) { - this->GetLocalGenerator()->ExpandRuleVariables(*i, vars); + *i = launcher + *i; + rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), *i, + vars); } std::string cmdLine = @@ -961,7 +990,7 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand( return; } - cmLocalGenerator::RuleVariables compileObjectVars; + cmRulePlaceholderExpander::RuleVariables compileObjectVars; compileObjectVars.Language = language.c_str(); std::string escapedSourceFileName = sourceFileName; @@ -993,9 +1022,13 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand( std::vector<std::string> compileCmds; cmSystemTools::ExpandListArgument(compileCmd, compileCmds); + CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander( + this->GetLocalGenerator()->CreateRulePlaceholderExpander()); + for (std::vector<std::string>::iterator i = compileCmds.begin(); i != compileCmds.end(); ++i) { - this->GetLocalGenerator()->ExpandRuleVariables(*i, compileObjectVars); + rulePlaceholderExpander->ExpandRuleVariables(this->GetLocalGenerator(), *i, + compileObjectVars); } std::string cmdLine = |