summaryrefslogtreecommitdiff
path: root/Source/cmNinjaTargetGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmNinjaTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaTargetGenerator.cxx96
1 files changed, 72 insertions, 24 deletions
diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx
index 5805259a5..f4faf47a2 100644
--- a/Source/cmNinjaTargetGenerator.cxx
+++ b/Source/cmNinjaTargetGenerator.cxx
@@ -135,13 +135,21 @@ std::string cmNinjaTargetGenerator::ComputeFlagsForObject(
}
// Add source file specific flags.
- if (const char* cflags = source->GetProperty("COMPILE_FLAGS")) {
- std::string config = this->LocalGenerator->GetConfigName();
- cmGeneratorExpression ge;
- std::unique_ptr<cmCompiledGeneratorExpression> cge = ge.Parse(cflags);
- const char* evaluatedFlags = cge->Evaluate(this->LocalGenerator, config,
- false, this->GeneratorTarget);
- this->LocalGenerator->AppendFlags(flags, evaluatedFlags);
+ cmGeneratorExpressionInterpreter genexInterpreter(
+ this->LocalGenerator, this->GeneratorTarget,
+ this->LocalGenerator->GetConfigName(), this->GeneratorTarget->GetName(),
+ language);
+
+ const std::string COMPILE_FLAGS("COMPILE_FLAGS");
+ if (const char* cflags = source->GetProperty(COMPILE_FLAGS)) {
+ this->LocalGenerator->AppendFlags(
+ flags, genexInterpreter.Evaluate(cflags, COMPILE_FLAGS));
+ }
+
+ const std::string COMPILE_OPTIONS("COMPILE_OPTIONS");
+ if (const char* coptions = source->GetProperty(COMPILE_OPTIONS)) {
+ this->LocalGenerator->AppendCompileOptions(
+ flags, genexInterpreter.Evaluate(coptions, COMPILE_OPTIONS));
}
return flags;
@@ -178,13 +186,23 @@ std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
const std::string& language)
{
std::set<std::string> defines;
- this->LocalGenerator->AppendDefines(
- defines, source->GetProperty("COMPILE_DEFINITIONS"));
- {
- std::string defPropName = "COMPILE_DEFINITIONS_";
- defPropName += cmSystemTools::UpperCase(this->GetConfigName());
- this->LocalGenerator->AppendDefines(defines,
- source->GetProperty(defPropName));
+ const std::string config = this->LocalGenerator->GetConfigName();
+ cmGeneratorExpressionInterpreter genexInterpreter(
+ this->LocalGenerator, this->GeneratorTarget, config,
+ this->GeneratorTarget->GetName(), language);
+
+ const std::string COMPILE_DEFINITIONS("COMPILE_DEFINITIONS");
+ if (const char* compile_defs = source->GetProperty(COMPILE_DEFINITIONS)) {
+ this->LocalGenerator->AppendDefines(
+ defines, genexInterpreter.Evaluate(compile_defs, COMPILE_DEFINITIONS));
+ }
+
+ std::string defPropName = "COMPILE_DEFINITIONS_";
+ defPropName += cmSystemTools::UpperCase(config);
+ if (const char* config_compile_defs = source->GetProperty(defPropName)) {
+ this->LocalGenerator->AppendDefines(
+ defines,
+ genexInterpreter.Evaluate(config_compile_defs, COMPILE_DEFINITIONS));
}
std::string definesString = this->GetDefines(language);
@@ -193,6 +211,30 @@ std::string cmNinjaTargetGenerator::ComputeDefines(cmSourceFile const* source,
return definesString;
}
+std::string cmNinjaTargetGenerator::ComputeIncludes(
+ cmSourceFile const* source, const std::string& language)
+{
+ std::vector<std::string> includes;
+ const std::string config = this->LocalGenerator->GetConfigName();
+ cmGeneratorExpressionInterpreter genexInterpreter(
+ this->LocalGenerator, this->GeneratorTarget, config,
+ this->GeneratorTarget->GetName(), language);
+
+ const std::string INCLUDE_DIRECTORIES("INCLUDE_DIRECTORIES");
+ if (const char* cincludes = source->GetProperty(INCLUDE_DIRECTORIES)) {
+ this->LocalGenerator->AppendIncludeDirectories(
+ includes, genexInterpreter.Evaluate(cincludes, INCLUDE_DIRECTORIES),
+ *source);
+ }
+
+ std::string includesString = this->LocalGenerator->GetIncludeFlags(
+ includes, this->GeneratorTarget, language, true, false, config);
+ this->LocalGenerator->AppendFlags(includesString,
+ this->GetIncludes(language));
+
+ return includesString;
+}
+
cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
{
// Static libraries never depend on other targets for linking.
@@ -405,14 +447,20 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
std::string flags = "$FLAGS";
std::string rspfile;
std::string rspcontent;
- std::string responseFlag;
bool const lang_supports_response = !(lang == "RC" || lang == "CUDA");
if (lang_supports_response && this->ForceResponseFile()) {
+ std::string const responseFlagVar =
+ "CMAKE_" + lang + "_RESPONSE_FILE_FLAG";
+ std::string responseFlag =
+ this->Makefile->GetSafeDefinition(responseFlagVar);
+ if (responseFlag.empty()) {
+ responseFlag = "@";
+ }
rspfile = "$RSP_FILE";
- responseFlag = "@" + rspfile;
+ responseFlag += rspfile;
rspcontent = " $DEFINES $INCLUDES $FLAGS";
- flags = responseFlag;
+ flags = std::move(responseFlag);
vars.Defines = "";
vars.Includes = "";
}
@@ -647,7 +695,7 @@ void cmNinjaTargetGenerator::WriteCompileRule(const std::string& lang)
// Maybe insert a compiler launcher like ccache or distcc
if (!compileCmds.empty() &&
- (lang == "C" || lang == "CXX" || lang == "CUDA")) {
+ (lang == "C" || lang == "CXX" || lang == "Fortran" || lang == "CUDA")) {
std::string const clauncher_prop = lang + "_COMPILER_LAUNCHER";
const char* clauncher = this->GeneratorTarget->GetProperty(clauncher_prop);
if (clauncher && *clauncher) {
@@ -807,7 +855,7 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatement(
cmNinjaVars vars;
vars["FLAGS"] = this->ComputeFlagsForObject(source, language);
vars["DEFINES"] = this->ComputeDefines(source, language);
- vars["INCLUDES"] = this->GetIncludes(language);
+ vars["INCLUDES"] = this->ComputeIncludes(source, language);
if (!this->NeedDepTypeMSVC(language)) {
vars["DEP_FILE"] = this->GetLocalGenerator()->ConvertToOutputFormat(
objectFileName + ".d", cmOutputConverter::SHELL);
@@ -1035,7 +1083,7 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
std::string escapedSourceFileName = sourceFileName;
- if (!cmSystemTools::FileIsFullPath(sourceFileName.c_str())) {
+ if (!cmSystemTools::FileIsFullPath(sourceFileName)) {
escapedSourceFileName = cmSystemTools::CollapseFullPath(
escapedSourceFileName, this->GetGlobalGenerator()
->GetCMakeInstance()
@@ -1095,8 +1143,8 @@ void cmNinjaTargetGenerator::ExportObjectCompileCommand(
void cmNinjaTargetGenerator::EnsureDirectoryExists(
const std::string& path) const
{
- if (cmSystemTools::FileIsFullPath(path.c_str())) {
- cmSystemTools::MakeDirectory(path.c_str());
+ if (cmSystemTools::FileIsFullPath(path)) {
+ cmSystemTools::MakeDirectory(path);
} else {
cmGlobalNinjaGenerator* gg = this->GetGlobalGenerator();
std::string fullPath =
@@ -1104,7 +1152,7 @@ void cmNinjaTargetGenerator::EnsureDirectoryExists(
// Also ensures their is a trailing slash.
gg->StripNinjaOutputPathPrefixAsSuffix(fullPath);
fullPath += path;
- cmSystemTools::MakeDirectory(fullPath.c_str());
+ cmSystemTools::MakeDirectory(fullPath);
}
}
@@ -1140,7 +1188,7 @@ void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
output);
// Add as a dependency to the target so that it gets called.
- this->Generator->ExtraFiles.push_back(output);
+ this->Generator->ExtraFiles.push_back(std::move(output));
}
void cmNinjaTargetGenerator::addPoolNinjaVariable(