From 43200c145d9690701f0cc6dbd5c60ee3ece5edf8 Mon Sep 17 00:00:00 2001 From: Peter Kuemmel Date: Wed, 13 Jun 2012 00:52:46 +0200 Subject: Ninja: work with ninja/master, don't compile rc files with cl Ninja generates for paths with spaces wrong results for $out.d, using the new DEP_FILE variable instead. --- Source/cmLocalGenerator.cxx | 7 ++++ Source/cmLocalGenerator.h | 1 + Source/cmNinjaNormalTargetGenerator.cxx | 15 --------- Source/cmNinjaNormalTargetGenerator.h | 3 -- Source/cmNinjaTargetGenerator.cxx | 59 +++++++++++++++++++++++---------- Source/cmNinjaTargetGenerator.h | 3 ++ 6 files changed, 52 insertions(+), 36 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 8265d72..90ed270 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -872,6 +872,13 @@ cmLocalGenerator::ExpandRuleVariable(std::string const& variable, return replaceValues.TargetPDB; } } + if(replaceValues.DependencyFile ) + { + if(variable == "DEP_FILE") + { + return replaceValues.DependencyFile; + } + } if(replaceValues.Target) { diff --git a/Source/cmLocalGenerator.h b/Source/cmLocalGenerator.h index cb84a30..f53700a 100644 --- a/Source/cmLocalGenerator.h +++ b/Source/cmLocalGenerator.h @@ -235,6 +235,7 @@ public: const char* LanguageCompileFlags; const char* Defines; const char* RuleLauncher; + const char* DependencyFile; }; /** Set whether to treat conversions to SHELL as a link script shell. */ diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index df1418f..81715dc 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -55,21 +55,6 @@ cmNinjaNormalTargetGenerator::~cmNinjaNormalTargetGenerator() { } -void -cmNinjaNormalTargetGenerator -::EnsureDirectoryExists(const std::string& dir) -{ - cmSystemTools::MakeDirectory(dir.c_str()); -} - -void -cmNinjaNormalTargetGenerator -::EnsureParentDirectoryExists(const std::string& path) -{ - EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path.c_str())); -} - - void cmNinjaNormalTargetGenerator::Generate() { if (!this->TargetLinkLanguage) { diff --git a/Source/cmNinjaNormalTargetGenerator.h b/Source/cmNinjaNormalTargetGenerator.h index 3be1c94..1ef9567 100644 --- a/Source/cmNinjaNormalTargetGenerator.h +++ b/Source/cmNinjaNormalTargetGenerator.h @@ -35,9 +35,6 @@ private: void WriteObjectLibStatement(); std::vector ComputeLinkCmd(); - void EnsureDirectoryExists(const std::string& dir); - void EnsureParentDirectoryExists(const std::string& path); - private: // Target name info. std::string TargetNameOut; diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 5c6a45d..ce1aac2 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -333,19 +333,29 @@ cmNinjaTargetGenerator vars.Defines = "$DEFINES"; vars.TargetPDB = "$TARGET_PDB"; + cmMakefile* mf = this->GetMakefile(); + bool useClDeps = false; - const char* clDepsBinary = mf->GetDefinition("CMAKE_CMCLDEPS_EXECUTABLE"); - const char* clShowPrefix = mf->GetDefinition("CMAKE_CL_SHOWINCLUDE_PREFIX"); - const char* projectName = mf->GetProjectName(); - if (clDepsBinary && clShowPrefix) + std::string clDepsBinary; + std::string clShowPrefix; + if (lang == "C" || lang == "CXX") { - useClDeps = true; - if (projectName && std::string(projectName) == "CMAKE_TRY_COMPILE") + const char* depsPtr = mf->GetDefinition("CMAKE_CMCLDEPS_EXECUTABLE"); + const char* showPtr = mf->GetDefinition("CMAKE_CL_SHOWINCLUDE_PREFIX"); + if (depsPtr && showPtr) { // don't wrap for try_compile, // TODO but why doesn't it work with cmcldeps? - useClDeps = false; + const std::string projectName = mf->GetProjectName() ? + mf->GetProjectName() : ""; + if (projectName != "CMAKE_TRY_COMPILE") + { + useClDeps = true; + clDepsBinary = depsPtr; + clShowPrefix = showPtr; + vars.DependencyFile = "$DEP_FILE"; + } } } @@ -354,15 +364,13 @@ cmNinjaTargetGenerator std::string depfileFlagsName = "CMAKE_DEPFILE_FLAGS_" + language; const char *depfileFlags = mf->GetDefinition(depfileFlagsName.c_str()); if (depfileFlags || useClDeps) { - std::string depfileFlagsStr = depfileFlags ? depfileFlags : ""; - depfile = "$out.d"; - cmSystemTools::ReplaceString(depfileFlagsStr, "", - depfile.c_str()); - cmSystemTools::ReplaceString(depfileFlagsStr, "", - "$out"); - cmSystemTools::ReplaceString(depfileFlagsStr, "", + std::string depFlagsStr = depfileFlags ? depfileFlags : ""; + depfile = "$DEP_FILE"; + cmSystemTools::ReplaceString(depFlagsStr, "", "\"$DEP_FILE\""); + cmSystemTools::ReplaceString(depFlagsStr, "", "$out"); + cmSystemTools::ReplaceString(depFlagsStr, "", mf->GetDefinition("CMAKE_C_COMPILER")); - flags += " " + depfileFlagsStr; + flags += " " + depFlagsStr; } vars.Flags = flags.c_str(); @@ -384,9 +392,8 @@ cmNinjaTargetGenerator if(useClDeps) { - std::string prefix = clShowPrefix; - cmdLine = "\"" + std::string(clDepsBinary) + "\" $in $out.d $out \"" - + prefix + "\" " + cmdLine; + cmdLine = "\"" + clDepsBinary + "\" $in \"$DEP_FILE\" $out \"" + + clShowPrefix + "\" " + cmdLine; } // Write the rule for compiling file of the given language. @@ -509,6 +516,8 @@ cmNinjaTargetGenerator cmNinjaVars vars; vars["FLAGS"] = this->ComputeFlagsForObject(source, language); vars["DEFINES"] = this->ComputeDefines(source, language); + vars["DEP_FILE"] = objectFileName + ".d";; + EnsureParentDirectoryExists(objectFileName); // TODO move to GetTargetPDB cmMakefile* mf = this->GetMakefile(); @@ -599,3 +608,17 @@ cmNinjaTargetGenerator this->ModuleDefinitionFile.c_str())); this->LocalGenerator->AppendFlags(flags, flag.c_str()); } + +void +cmNinjaTargetGenerator +::EnsureDirectoryExists(const std::string& dir) +{ + cmSystemTools::MakeDirectory(dir.c_str()); +} + +void +cmNinjaTargetGenerator +::EnsureParentDirectoryExists(const std::string& path) +{ + EnsureDirectoryExists(cmSystemTools::GetParentDirectory(path.c_str())); +} diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index b64ce1e..af43a8b 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -111,6 +111,9 @@ protected: // Helper to add flag for windows .def file. void AddModuleDefinitionFlag(std::string& flags); + void EnsureDirectoryExists(const std::string& dir); + void EnsureParentDirectoryExists(const std::string& path); + private: cmTarget* Target; cmGeneratorTarget* GeneratorTarget; -- cgit v0.12