Merge topic 'refactor-ninja-command-exporter'
cd530df8
cmNinjaTargetGenerator: Factor out compile command exporter
This commit is contained in:
commit
2a2a560125
|
@ -546,22 +546,39 @@ cmNinjaTargetGenerator
|
||||||
::WriteObjectBuildStatement(
|
::WriteObjectBuildStatement(
|
||||||
cmSourceFile const* source, bool writeOrderDependsTargetForTarget)
|
cmSourceFile const* source, bool writeOrderDependsTargetForTarget)
|
||||||
{
|
{
|
||||||
|
std::string const language = source->GetLanguage();
|
||||||
|
std::string const sourceFileName =
|
||||||
|
language=="RC" ? source->GetFullPath() : this->GetSourceFilePath(source);
|
||||||
|
std::string const objectDir = this->Target->GetSupportDirectory();
|
||||||
|
std::string const objectFileName = this->GetObjectFilePath(source);
|
||||||
|
std::string const objectFileDir =
|
||||||
|
cmSystemTools::GetFilenamePath(objectFileName);
|
||||||
|
|
||||||
|
cmNinjaVars vars;
|
||||||
|
vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
|
||||||
|
vars["DEFINES"] = this->ComputeDefines(source, language);
|
||||||
|
vars["INCLUDES"] = this->GetIncludes(language);
|
||||||
|
if (!this->NeedDepTypeMSVC(language))
|
||||||
|
{
|
||||||
|
vars["DEP_FILE"] =
|
||||||
|
cmGlobalNinjaGenerator::EncodeDepfileSpace(objectFileName + ".d");
|
||||||
|
}
|
||||||
|
|
||||||
|
this->ExportObjectCompileCommand(
|
||||||
|
language, sourceFileName,
|
||||||
|
objectDir, objectFileName, objectFileDir,
|
||||||
|
vars["FLAGS"], vars["DEFINES"], vars["INCLUDES"]
|
||||||
|
);
|
||||||
|
|
||||||
std::string comment;
|
std::string comment;
|
||||||
const std::string language = source->GetLanguage();
|
|
||||||
std::string rule = this->LanguageCompilerRule(language);
|
std::string rule = this->LanguageCompilerRule(language);
|
||||||
|
|
||||||
cmNinjaDeps outputs;
|
cmNinjaDeps outputs;
|
||||||
std::string objectFileName = this->GetObjectFilePath(source);
|
|
||||||
outputs.push_back(objectFileName);
|
outputs.push_back(objectFileName);
|
||||||
// Add this object to the list of object files.
|
// Add this object to the list of object files.
|
||||||
this->Objects.push_back(objectFileName);
|
this->Objects.push_back(objectFileName);
|
||||||
|
|
||||||
cmNinjaDeps explicitDeps;
|
cmNinjaDeps explicitDeps;
|
||||||
std::string sourceFileName;
|
|
||||||
if (language == "RC")
|
|
||||||
sourceFileName = source->GetFullPath();
|
|
||||||
else
|
|
||||||
sourceFileName = this->GetSourceFilePath(source);
|
|
||||||
explicitDeps.push_back(sourceFileName);
|
explicitDeps.push_back(sourceFileName);
|
||||||
|
|
||||||
cmNinjaDeps implicitDeps;
|
cmNinjaDeps implicitDeps;
|
||||||
|
@ -596,21 +613,11 @@ cmNinjaTargetGenerator
|
||||||
orderOnlyDeps);
|
orderOnlyDeps);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmNinjaVars vars;
|
|
||||||
vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
|
|
||||||
vars["DEFINES"] = this->ComputeDefines(source, language);
|
|
||||||
vars["INCLUDES"] = this->GetIncludes(language);
|
|
||||||
if (!this->NeedDepTypeMSVC(language)) {
|
|
||||||
vars["DEP_FILE"] =
|
|
||||||
cmGlobalNinjaGenerator::EncodeDepfileSpace(objectFileName + ".d");
|
|
||||||
}
|
|
||||||
EnsureParentDirectoryExists(objectFileName);
|
EnsureParentDirectoryExists(objectFileName);
|
||||||
|
|
||||||
std::string objectDir = this->Target->GetSupportDirectory();
|
|
||||||
vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
|
vars["OBJECT_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
|
||||||
ConvertToNinjaPath(objectDir),
|
ConvertToNinjaPath(objectDir),
|
||||||
cmLocalGenerator::SHELL);
|
cmLocalGenerator::SHELL);
|
||||||
std::string objectFileDir = cmSystemTools::GetFilenamePath(objectFileName);
|
|
||||||
vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
|
vars["OBJECT_FILE_DIR"] = this->GetLocalGenerator()->ConvertToOutputFormat(
|
||||||
ConvertToNinjaPath(objectFileDir),
|
ConvertToNinjaPath(objectFileDir),
|
||||||
cmLocalGenerator::SHELL);
|
cmLocalGenerator::SHELL);
|
||||||
|
@ -619,54 +626,6 @@ cmNinjaTargetGenerator
|
||||||
|
|
||||||
this->SetMsvcTargetPdbVariable(vars);
|
this->SetMsvcTargetPdbVariable(vars);
|
||||||
|
|
||||||
if(this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS"))
|
|
||||||
{
|
|
||||||
cmLocalGenerator::RuleVariables compileObjectVars;
|
|
||||||
std::string lang = language;
|
|
||||||
compileObjectVars.Language = lang.c_str();
|
|
||||||
|
|
||||||
std::string escapedSourceFileName = sourceFileName;
|
|
||||||
|
|
||||||
if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
|
|
||||||
{
|
|
||||||
escapedSourceFileName = cmSystemTools::CollapseFullPath(
|
|
||||||
escapedSourceFileName,
|
|
||||||
this->GetGlobalGenerator()->GetCMakeInstance()->
|
|
||||||
GetHomeOutputDirectory());
|
|
||||||
}
|
|
||||||
|
|
||||||
escapedSourceFileName =
|
|
||||||
this->LocalGenerator->ConvertToOutputFormat(
|
|
||||||
escapedSourceFileName, cmLocalGenerator::SHELL);
|
|
||||||
|
|
||||||
compileObjectVars.Source = escapedSourceFileName.c_str();
|
|
||||||
compileObjectVars.Object = objectFileName.c_str();
|
|
||||||
compileObjectVars.ObjectDir = objectDir.c_str();
|
|
||||||
compileObjectVars.ObjectFileDir = objectFileDir.c_str();
|
|
||||||
compileObjectVars.Flags = vars["FLAGS"].c_str();
|
|
||||||
compileObjectVars.Defines = vars["DEFINES"].c_str();
|
|
||||||
compileObjectVars.Includes = vars["INCLUDES"].c_str();
|
|
||||||
|
|
||||||
// Rule for compiling object file.
|
|
||||||
std::string compileCmdVar = "CMAKE_";
|
|
||||||
compileCmdVar += language;
|
|
||||||
compileCmdVar += "_COMPILE_OBJECT";
|
|
||||||
std::string compileCmd =
|
|
||||||
this->GetMakefile()->GetRequiredDefinition(compileCmdVar);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(),
|
this->GetGlobalGenerator()->WriteBuild(this->GetBuildFileStream(),
|
||||||
comment,
|
comment,
|
||||||
rule,
|
rule,
|
||||||
|
@ -688,6 +647,69 @@ cmNinjaTargetGenerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cmNinjaTargetGenerator
|
||||||
|
::ExportObjectCompileCommand(
|
||||||
|
std::string const& language,
|
||||||
|
std::string const& sourceFileName,
|
||||||
|
std::string const& objectDir,
|
||||||
|
std::string const& objectFileName,
|
||||||
|
std::string const& objectFileDir,
|
||||||
|
std::string const& flags,
|
||||||
|
std::string const& defines,
|
||||||
|
std::string const& includes
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if(!this->Makefile->IsOn("CMAKE_EXPORT_COMPILE_COMMANDS"))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cmLocalGenerator::RuleVariables compileObjectVars;
|
||||||
|
compileObjectVars.Language = language.c_str();
|
||||||
|
|
||||||
|
std::string escapedSourceFileName = sourceFileName;
|
||||||
|
|
||||||
|
if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str()))
|
||||||
|
{
|
||||||
|
escapedSourceFileName = cmSystemTools::CollapseFullPath(
|
||||||
|
escapedSourceFileName,
|
||||||
|
this->GetGlobalGenerator()->GetCMakeInstance()->
|
||||||
|
GetHomeOutputDirectory());
|
||||||
|
}
|
||||||
|
|
||||||
|
escapedSourceFileName =
|
||||||
|
this->LocalGenerator->ConvertToOutputFormat(
|
||||||
|
escapedSourceFileName, cmLocalGenerator::SHELL);
|
||||||
|
|
||||||
|
compileObjectVars.Source = escapedSourceFileName.c_str();
|
||||||
|
compileObjectVars.Object = objectFileName.c_str();
|
||||||
|
compileObjectVars.ObjectDir = objectDir.c_str();
|
||||||
|
compileObjectVars.ObjectFileDir = objectFileDir.c_str();
|
||||||
|
compileObjectVars.Flags = flags.c_str();
|
||||||
|
compileObjectVars.Defines = defines.c_str();
|
||||||
|
compileObjectVars.Includes = includes.c_str();
|
||||||
|
|
||||||
|
// Rule for compiling object file.
|
||||||
|
std::string compileCmdVar = "CMAKE_";
|
||||||
|
compileCmdVar += language;
|
||||||
|
compileCmdVar += "_COMPILE_OBJECT";
|
||||||
|
std::string compileCmd =
|
||||||
|
this->GetMakefile()->GetRequiredDefinition(compileCmdVar);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cmNinjaTargetGenerator
|
cmNinjaTargetGenerator
|
||||||
::EnsureDirectoryExists(const std::string& path) const
|
::EnsureDirectoryExists(const std::string& path) const
|
||||||
|
|
|
@ -114,6 +114,17 @@ protected:
|
||||||
void WriteObjectBuildStatement(cmSourceFile const* source,
|
void WriteObjectBuildStatement(cmSourceFile const* source,
|
||||||
bool writeOrderDependsTargetForTarget);
|
bool writeOrderDependsTargetForTarget);
|
||||||
|
|
||||||
|
void ExportObjectCompileCommand(
|
||||||
|
std::string const& language,
|
||||||
|
std::string const& sourceFileName,
|
||||||
|
std::string const& objectDir,
|
||||||
|
std::string const& objectFileName,
|
||||||
|
std::string const& objectFileDir,
|
||||||
|
std::string const& flags,
|
||||||
|
std::string const& defines,
|
||||||
|
std::string const& includes
|
||||||
|
);
|
||||||
|
|
||||||
cmNinjaDeps GetObjects() const
|
cmNinjaDeps GetObjects() const
|
||||||
{ return this->Objects; }
|
{ return this->Objects; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue