diff options
author | Stephen Kelly <steveire@gmail.com> | 2012-05-09 21:47:37 (GMT) |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2012-06-04 21:42:37 (GMT) |
commit | db839bec7d076b54c5e9ad0d19386a26557a509e (patch) | |
tree | a9ad4797209348cc105d19e01eacf5c25ddff8bf /Source/cmNinjaTargetGenerator.cxx | |
parent | 8778357898327c1e4893d8dc140fc0e63331e36b (diff) | |
download | CMake-db839bec7d076b54c5e9ad0d19386a26557a509e.zip CMake-db839bec7d076b54c5e9ad0d19386a26557a509e.tar.gz CMake-db839bec7d076b54c5e9ad0d19386a26557a509e.tar.bz2 |
Make the CMAKE_EXPORT_COMPILE_COMMANDS option work with Ninja.
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 80007f1..7c58154 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -487,6 +487,36 @@ cmNinjaTargetGenerator vars["TARGET_PDB"] = this->GetLocalGenerator()->ConvertToOutputFormat( this->GetTargetPDB().c_str(), cmLocalGenerator::SHELL); + if(this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS")) + { + cmLocalGenerator::RuleVariables compileObjectVars; + std::string lang = language; + compileObjectVars.Language = lang.c_str(); + compileObjectVars.Source = sourceFileName.c_str(); + compileObjectVars.Object = objectFileName.c_str(); + compileObjectVars.Flags = vars["FLAGS"].c_str(); + compileObjectVars.Defines = vars["DEFINES"].c_str(); + + // Rule for compiling object file. + std::string compileCmdVar = "CMAKE_"; + compileCmdVar += language; + compileCmdVar += "_COMPILE_OBJECT"; + std::string compileCmd = + this->GetMakefile()->GetRequiredDefinition(compileCmdVar.c_str()); + std::vector<std::string> compileCmds; + cmSystemTools::ExpandListArgument(compileCmd, compileCmds); + + for (std::vector<std::string>::iterator i = compileCmds.begin(); + i != compileCmds.end(); ++i) + this->GetLocalGenerator()->ExpandRuleVariables(*i, compileObjectVars); + + std::string cmdLine = + this->GetLocalGenerator()->BuildCommandLine(compileCmds); + + this->GetGlobalGenerator()->AddCXXCompileCommand(cmdLine, + sourceFileName); + } + cmGlobalNinjaGenerator::WriteBuild(this->GetBuildFileStream(), comment, rule, |