summaryrefslogtreecommitdiffstats
path: root/Source/cmGlobalNinjaGenerator.cxx
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2012-05-09 21:47:37 (GMT)
committerStephen Kelly <steveire@gmail.com>2012-06-04 21:42:37 (GMT)
commitdb839bec7d076b54c5e9ad0d19386a26557a509e (patch)
treea9ad4797209348cc105d19e01eacf5c25ddff8bf /Source/cmGlobalNinjaGenerator.cxx
parent8778357898327c1e4893d8dc140fc0e63331e36b (diff)
downloadCMake-db839bec7d076b54c5e9ad0d19386a26557a509e.zip
CMake-db839bec7d076b54c5e9ad0d19386a26557a509e.tar.gz
CMake-db839bec7d076b54c5e9ad0d19386a26557a509e.tar.bz2
Make the CMAKE_EXPORT_COMPILE_COMMANDS option work with Ninja.
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 328706c..0e89fab 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -341,6 +341,7 @@ cmGlobalNinjaGenerator::cmGlobalNinjaGenerator()
: cmGlobalGenerator()
, BuildFileStream(0)
, RulesFileStream(0)
+ , CompileCommandsStream(0)
, Rules()
, AllDependencies()
{
@@ -390,6 +391,7 @@ void cmGlobalNinjaGenerator::Generate()
this->BuildFileStream->setstate(std::ios_base::failbit);
}
+ this->CloseCompileCommandsStream();
this->CloseRulesFileStream();
this->CloseBuildFileStream();
}
@@ -623,6 +625,46 @@ void cmGlobalNinjaGenerator::CloseRulesFileStream()
}
}
+void cmGlobalNinjaGenerator::AddCXXCompileCommand(
+ const std::string &commandLine,
+ const std::string &sourceFile)
+{
+ // Compute Ninja's build file path.
+ std::string buildFileDir =
+ this->GetCMakeInstance()->GetHomeOutputDirectory();
+ if (!this->CompileCommandsStream)
+ {
+ std::string buildFilePath = buildFileDir + "/compile_commands.json";
+
+ // Get a stream where to generate things.
+ this->CompileCommandsStream =
+ new cmGeneratedFileStream(buildFilePath.c_str());
+ *this->CompileCommandsStream << "[";
+ } else {
+ *this->CompileCommandsStream << "," << std::endl;
+ }
+
+ *this->CompileCommandsStream << "\n{\n"
+ << " \"directory\": \""
+ << cmGlobalGenerator::EscapeJSON(buildFileDir) << "\",\n"
+ << " \"command\": \""
+ << cmGlobalGenerator::EscapeJSON(commandLine) << "\",\n"
+ << " \"file\": \""
+ << cmGlobalGenerator::EscapeJSON(sourceFile) << "\"\n"
+ << "}";
+}
+
+void cmGlobalNinjaGenerator::CloseCompileCommandsStream()
+{
+ if (this->CompileCommandsStream)
+ {
+ *this->CompileCommandsStream << "\n]";
+ delete this->CompileCommandsStream;
+ this->CompileCommandsStream = 0;
+ }
+
+}
+
void cmGlobalNinjaGenerator::WriteDisclaimer(std::ostream& os)
{
os