From e0aa060352f0ea663500e87086192f52440952b9 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 5 Apr 2018 11:04:23 -0400 Subject: cmNinjaTargetGenerator: Move depfile logic to later in its function Clarify that other compile rule generation logic does not depend on it. --- Source/cmNinjaTargetGenerator.cxx | 96 ++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index fa7d95a..d982020 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -465,52 +465,6 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) vars.Includes = ""; } - // Tell ninja dependency format so all deps can be loaded into a database - std::string deptype; - std::string depfile; - std::string cldeps; - if (explicitPP) { - // The explicit preprocessing step will handle dependency scanning. - } else if (this->NeedDepTypeMSVC(lang)) { - deptype = "msvc"; - depfile.clear(); - flags += " /showIncludes"; - } else if (mf->IsOn("CMAKE_NINJA_CMCLDEPS_" + lang)) { - // For the MS resource compiler we need cmcldeps, but skip dependencies - // for source-file try_compile cases because they are always fresh. - if (!mf->GetIsSourceFileTryCompile()) { - deptype = "gcc"; - depfile = "$DEP_FILE"; - const std::string cl = mf->GetDefinition("CMAKE_C_COMPILER") - ? mf->GetSafeDefinition("CMAKE_C_COMPILER") - : mf->GetSafeDefinition("CMAKE_CXX_COMPILER"); - cldeps = "\""; - cldeps += cmSystemTools::GetCMClDepsCommand(); - cldeps += "\" " + lang + " " + vars.Source + " $DEP_FILE $out \""; - cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"); - cldeps += "\" \"" + cl + "\" "; - } - } else { - deptype = "gcc"; - const char* langdeptype = mf->GetDefinition("CMAKE_NINJA_DEPTYPE_" + lang); - if (langdeptype) { - deptype = langdeptype; - } - depfile = "$DEP_FILE"; - const std::string flagsName = "CMAKE_DEPFILE_FLAGS_" + lang; - std::string depfileFlags = mf->GetSafeDefinition(flagsName); - if (!depfileFlags.empty()) { - cmSystemTools::ReplaceString(depfileFlags, "", "$DEP_FILE"); - cmSystemTools::ReplaceString(depfileFlags, "", "$out"); - cmSystemTools::ReplaceString(depfileFlags, "", - mf->GetDefinition("CMAKE_C_COMPILER")); - flags += " " + depfileFlags; - } - } - - vars.Flags = flags.c_str(); - vars.DependencyFile = depfile.c_str(); - std::unique_ptr rulePlaceholderExpander( this->GetLocalGenerator()->CreateRulePlaceholderExpander()); @@ -550,7 +504,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) vars.Source = "$in"; // Preprocessing and compilation use the same flags. - ppVars.Flags = vars.Flags; + std::string ppFlags = flags; // Move preprocessor definitions to the preprocessor rule. ppVars.Defines = vars.Defines; @@ -560,6 +514,8 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) // compilation rule still needs them for the INCLUDE directive. ppVars.Includes = vars.Includes; + ppVars.Flags = ppFlags.c_str(); + // Rule for preprocessing source file. std::vector ppCmds; cmSystemTools::ExpandListArgument(ppCmd, ppCmds); @@ -631,6 +587,52 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang) /*generator*/ false); } + // Tell ninja dependency format so all deps can be loaded into a database + std::string deptype; + std::string depfile; + std::string cldeps; + if (explicitPP) { + // The explicit preprocessing step will handle dependency scanning. + } else if (this->NeedDepTypeMSVC(lang)) { + deptype = "msvc"; + depfile.clear(); + flags += " /showIncludes"; + } else if (mf->IsOn("CMAKE_NINJA_CMCLDEPS_" + lang)) { + // For the MS resource compiler we need cmcldeps, but skip dependencies + // for source-file try_compile cases because they are always fresh. + if (!mf->GetIsSourceFileTryCompile()) { + deptype = "gcc"; + depfile = "$DEP_FILE"; + const std::string cl = mf->GetDefinition("CMAKE_C_COMPILER") + ? mf->GetSafeDefinition("CMAKE_C_COMPILER") + : mf->GetSafeDefinition("CMAKE_CXX_COMPILER"); + cldeps = "\""; + cldeps += cmSystemTools::GetCMClDepsCommand(); + cldeps += "\" " + lang + " " + vars.Source + " $DEP_FILE $out \""; + cldeps += mf->GetSafeDefinition("CMAKE_CL_SHOWINCLUDES_PREFIX"); + cldeps += "\" \"" + cl + "\" "; + } + } else { + deptype = "gcc"; + const char* langdeptype = mf->GetDefinition("CMAKE_NINJA_DEPTYPE_" + lang); + if (langdeptype) { + deptype = langdeptype; + } + depfile = "$DEP_FILE"; + const std::string flagsName = "CMAKE_DEPFILE_FLAGS_" + lang; + std::string depfileFlags = mf->GetSafeDefinition(flagsName); + if (!depfileFlags.empty()) { + cmSystemTools::ReplaceString(depfileFlags, "", "$DEP_FILE"); + cmSystemTools::ReplaceString(depfileFlags, "", "$out"); + cmSystemTools::ReplaceString(depfileFlags, "", + mf->GetDefinition("CMAKE_C_COMPILER")); + flags += " " + depfileFlags; + } + } + + vars.Flags = flags.c_str(); + vars.DependencyFile = depfile.c_str(); + // Rule for compiling object file. std::vector compileCmds; if (lang == "CUDA") { -- cgit v0.12