diff options
author | David Cole <david.cole@kitware.com> | 2012-06-05 18:21:36 (GMT) |
---|---|---|
committer | CMake Topic Stage <kwrobot@kitware.com> | 2012-06-05 18:21:36 (GMT) |
commit | 7687d557dc9a04c56ca9d9e943ff8e21ac8eb028 (patch) | |
tree | a9e51af78cba10b79fa1a04cdc92f82e0dfad47d /Source/cmGlobalNinjaGenerator.cxx | |
parent | 80abbeb3f2fe1cd245633e6ac52caa329f37ae52 (diff) | |
parent | 3545645c1b01f609496a4fc41e20419dedbbd98d (diff) | |
download | CMake-7687d557dc9a04c56ca9d9e943ff8e21ac8eb028.zip CMake-7687d557dc9a04c56ca9d9e943ff8e21ac8eb028.tar.gz CMake-7687d557dc9a04c56ca9d9e943ff8e21ac8eb028.tar.bz2 |
Merge topic 'Ninja-EXPORT_COMPILE_COMMANDS'
3545645 Exclude the CompileCommandOutput test on WIN32.
fbaddf4 Escape the source file to be compiled if required.
db839be Make the CMAKE_EXPORT_COMPILE_COMMANDS option work with Ninja.
8778357 Add newline to the output.
2c04bc0 Move the EscapeJSON method to a sharable location.
Diffstat (limited to 'Source/cmGlobalNinjaGenerator.cxx')
-rw-r--r-- | Source/cmGlobalNinjaGenerator.cxx | 42 |
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 |