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.
This commit is contained in:
Peter Kuemmel 2012-06-13 00:52:46 +02:00
parent 12cc6434bf
commit 43200c145d
6 changed files with 52 additions and 36 deletions

View File

@ -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)
{

View File

@ -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. */

View File

@ -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) {

View File

@ -35,9 +35,6 @@ private:
void WriteObjectLibStatement();
std::vector<std::string> ComputeLinkCmd();
void EnsureDirectoryExists(const std::string& dir);
void EnsureParentDirectoryExists(const std::string& path);
private:
// Target name info.
std::string TargetNameOut;

View File

@ -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>",
depfile.c_str());
cmSystemTools::ReplaceString(depfileFlagsStr, "<OBJECT>",
"$out");
cmSystemTools::ReplaceString(depfileFlagsStr, "<CMAKE_C_COMPILER>",
std::string depFlagsStr = depfileFlags ? depfileFlags : "";
depfile = "$DEP_FILE";
cmSystemTools::ReplaceString(depFlagsStr, "<DEPFILE>", "\"$DEP_FILE\"");
cmSystemTools::ReplaceString(depFlagsStr, "<OBJECT>", "$out");
cmSystemTools::ReplaceString(depFlagsStr, "<CMAKE_C_COMPILER>",
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()));
}

View File

@ -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;