summaryrefslogtreecommitdiffstats
path: root/Source/cmNinjaTargetGenerator.cxx
diff options
context:
space:
mode:
authorDavid Cole <david.cole@kitware.com>2012-06-19 18:42:41 (GMT)
committerCMake Topic Stage <kwrobot@kitware.com>2012-06-19 18:42:41 (GMT)
commit565744bd3db6f730a31e0325a1c7336224237d12 (patch)
treebf231f1aafe422fa60fd4fcba4a9e180a718d221 /Source/cmNinjaTargetGenerator.cxx
parent8d198a71fc157343de56b0addcd987681639c127 (diff)
parenteb410e8dd8f4d1401d11713f398d38e0f250b136 (diff)
downloadCMake-565744bd3db6f730a31e0325a1c7336224237d12.zip
CMake-565744bd3db6f730a31e0325a1c7336224237d12.tar.gz
CMake-565744bd3db6f730a31e0325a1c7336224237d12.tar.bz2
Merge topic 'ninja-cldeps'
eb410e8 Ninja: disable cldeps for bcc32, it's too old, and ninja would also not build 5ead31d Ninja: try work around for bcc32 bug 1333b57 Ninja: build server fixes 9081e3a remove warning about unused parameter f430bea Ninja: maybe this fixes the bcc32 build f2c1288 Ninja: msvc6 for-scoping 44b9bbc Ninja: build with old msvc versions 57156a5 Ninja: build server fixes f1abdce Ninja: some bytes of the rc files couldn't be piped correctly 2de963d Ninja: don't remove space between command and parameters 50b6f33 Ninja: build cmcldeps with mingw c05653e Ninja: try to make GetProcessId visible ab245ff Ninja: but cl supports /nologo ... bf58e9a Ninja: no /nologo option in old rc.exe 2fb07fc Ninja: Eclipse and KDevelop fixes for ninja 518c065 Ninja: don't pollute build dir with preprocessed rc files ...
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaTargetGenerator.cxx95
1 files changed, 77 insertions, 18 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index a362d13..6157931 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -151,6 +151,8 @@ cmNinjaTargetGenerator::ComputeFlagsForObject(cmSourceFile *source,
language.c_str());
std::string includeFlags =
this->LocalGenerator->GetIncludeFlags(includes, language.c_str(), false);
+ if(cmGlobalNinjaGenerator::IsMinGW())
+ cmSystemTools::ReplaceString(includeFlags, "\\", "/");
this->LocalGenerator->AppendFlags(flags, includeFlags.c_str());
}
@@ -298,7 +300,7 @@ std::string cmNinjaTargetGenerator::GetTargetPDB() const
targetFullPathPDB += this->Target->GetPDBName(this->GetConfigName());
}
- return ConvertToNinjaPath(targetFullPathPDB.c_str());
+ return targetFullPathPDB.c_str();
}
@@ -306,10 +308,11 @@ void
cmNinjaTargetGenerator
::WriteLanguageRules(const std::string& language)
{
+#ifdef NINJA_GEN_VERBOSE_FILES
this->GetRulesFileStream()
<< "# Rules for language " << language << "\n\n";
+#endif
this->WriteCompileRule(language);
- this->GetRulesFileStream() << "\n";
}
void
@@ -327,20 +330,45 @@ cmNinjaTargetGenerator
vars.Defines = "$DEFINES";
vars.TargetPDB = "$TARGET_PDB";
+
+ cmMakefile* mf = this->GetMakefile();
+
+ bool useClDeps = false;
+ std::string clDepsBinary;
+ std::string clShowPrefix;
+ if (lang == "C" || lang == "CXX" || lang == "RC")
+ {
+ 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?
+ const std::string projectName = mf->GetProjectName() ?
+ mf->GetProjectName() : "";
+ if (projectName != "CMAKE_TRY_COMPILE")
+ {
+ useClDeps = true;
+ std::string qu = "\"";
+ clDepsBinary = qu + depsPtr + qu;
+ clShowPrefix = qu + showPtr + qu;
+ vars.DependencyFile = "$DEP_FILE";
+ }
+ }
+ }
+
+
std::string depfile;
std::string depfileFlagsName = "CMAKE_DEPFILE_FLAGS_" + language;
- const char *depfileFlags =
- this->GetMakefile()->GetDefinition(depfileFlagsName.c_str());
- if (depfileFlags) {
- std::string depfileFlagsStr = depfileFlags;
- depfile = "$out.d";
- cmSystemTools::ReplaceString(depfileFlagsStr, "<DEPFILE>",
- depfile.c_str());
- cmSystemTools::ReplaceString(depfileFlagsStr, "<OBJECT>",
- "$out");
- cmSystemTools::ReplaceString(depfileFlagsStr, "<CMAKE_C_COMPILER>",
- this->GetMakefile()->GetDefinition("CMAKE_C_COMPILER"));
- flags += " " + depfileFlagsStr;
+ const char *depfileFlags = mf->GetDefinition(depfileFlagsName.c_str());
+ if (depfileFlags || useClDeps) {
+ 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 += " " + depFlagsStr;
}
vars.Flags = flags.c_str();
@@ -349,8 +377,7 @@ cmNinjaTargetGenerator
std::string compileCmdVar = "CMAKE_";
compileCmdVar += language;
compileCmdVar += "_COMPILE_OBJECT";
- std::string compileCmd =
- this->GetMakefile()->GetRequiredDefinition(compileCmdVar.c_str());
+ std::string compileCmd = mf->GetRequiredDefinition(compileCmdVar.c_str());
std::vector<std::string> compileCmds;
cmSystemTools::ExpandListArgument(compileCmd, compileCmds);
@@ -361,6 +388,14 @@ cmNinjaTargetGenerator
std::string cmdLine =
this->GetLocalGenerator()->BuildCommandLine(compileCmds);
+ if(useClDeps)
+ {
+ std::string cl = mf->GetDefinition("CMAKE_C_COMPILER");
+ cl = "\"" + cl + "\" ";
+ cmdLine = clDepsBinary + " " + lang + " $in \"$DEP_FILE\" $out "
+ + clShowPrefix + " " + cl + cmdLine;
+ }
+
// Write the rule for compiling file of the given language.
cmOStringStream comment;
comment << "Rule for compiling " << language << " files.";
@@ -481,8 +516,18 @@ cmNinjaTargetGenerator
cmNinjaVars vars;
vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
vars["DEFINES"] = this->ComputeDefines(source, language);
- vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
- this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL);
+ vars["DEP_FILE"] = objectFileName + ".d";;
+ EnsureParentDirectoryExists(objectFileName);
+
+ // TODO move to GetTargetPDB
+ cmMakefile* mf = this->GetMakefile();
+ if (mf->GetDefinition("MSVC_C_ARCHITECTURE_ID") ||
+ mf->GetDefinition("MSVC_CXX_ARCHITECTURE_ID"))
+ {
+ vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
+ ConvertToNinjaPath(GetTargetPDB().c_str()).c_str(),
+ cmLocalGenerator::SHELL);
+ }
if(this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS"))
{
@@ -563,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()));
+}