summaryrefslogtreecommitdiffstats
path: root/Source/cmNinjaNormalTargetGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmNinjaNormalTargetGenerator.cxx')
-rw-r--r--Source/cmNinjaNormalTargetGenerator.cxx62
1 files changed, 35 insertions, 27 deletions
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index e344df4..25931f3 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -194,12 +194,7 @@ cmNinjaNormalTargetGenerator
vars.ObjectDir = "$OBJECT_DIR";
- // TODO:
- // Makefile generator expands <TARGET> to the plain target name
- // with suffix. $out expands to a relative path. This difference
- // could make trouble when switching to Ninja generator. Maybe
- // using TARGET_NAME and RuleVariables::TargetName is a fix.
- vars.Target = "$out";
+ vars.Target = "$TARGET_FILE";
vars.SONameFlag = "$SONAME_FLAG";
vars.TargetSOName = "$SONAME";
@@ -252,7 +247,7 @@ cmNinjaNormalTargetGenerator
<< this->GetVisibleTypeName() << ".";
cmOStringStream description;
description << "Linking " << this->TargetLinkLanguage << " "
- << this->GetVisibleTypeName() << " $out";
+ << this->GetVisibleTypeName() << " $TARGET_FILE";
this->GetGlobalGenerator()->AddRule(ruleName,
linkCmd,
description.str(),
@@ -261,7 +256,7 @@ cmNinjaNormalTargetGenerator
/*deptype*/ "",
rspfile,
rspcontent,
- /*restat*/ false,
+ /*restat*/ "$RESTAT",
/*generator*/ false);
}
@@ -283,7 +278,7 @@ cmNinjaNormalTargetGenerator
/*deptype*/ "",
/*rspfile*/ "",
/*rspcontent*/ "",
- /*restat*/ false,
+ /*restat*/ "",
/*generator*/ false);
else
this->GetGlobalGenerator()->AddRule("CMAKE_SYMLINK_LIBRARY",
@@ -297,7 +292,7 @@ cmNinjaNormalTargetGenerator
/*deptype*/ "",
/*rspfile*/ "",
/*rspcontent*/ "",
- /*restat*/ false,
+ /*restat*/ "",
/*generator*/ false);
}
}
@@ -326,7 +321,7 @@ cmNinjaNormalTargetGenerator
this->GetLocalGenerator()->ConvertToOutputFormat(
mf->GetRequiredDefinition("CMAKE_COMMAND"),
cmLocalGenerator::SHELL);
- linkCmds.push_back(cmakeCommand + " -E remove $out");
+ linkCmds.push_back(cmakeCommand + " -E remove $TARGET_FILE");
}
// TODO: Use ARCHIVE_APPEND for archives over a certain size.
{
@@ -375,14 +370,14 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
cmTarget& target = *this->GetTarget();
const std::string cfgName = this->GetConfigName();
std::string targetOutput = ConvertToNinjaPath(
- target.GetFullPath(cfgName).c_str());
+ target.GetFullPath(cfgName));
std::string targetOutputReal = ConvertToNinjaPath(
target.GetFullPath(cfgName,
/*implib=*/false,
- /*realpath=*/true).c_str());
+ /*realpath=*/true));
std::string targetOutputImplib = ConvertToNinjaPath(
target.GetFullPath(cfgName,
- /*implib=*/true).c_str());
+ /*implib=*/true));
if (target.IsAppBundleOnApple())
{
@@ -394,11 +389,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
targetOutput = outpath;
targetOutput += "/";
targetOutput += this->TargetNameOut;
- targetOutput = this->ConvertToNinjaPath(targetOutput.c_str());
+ targetOutput = this->ConvertToNinjaPath(targetOutput);
targetOutputReal = outpath;
targetOutputReal += "/";
targetOutputReal += this->TargetNameReal;
- targetOutputReal = this->ConvertToNinjaPath(targetOutputReal.c_str());
+ targetOutputReal = this->ConvertToNinjaPath(targetOutputReal);
}
else if (target.IsFrameworkOnApple())
{
@@ -450,6 +445,10 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
this->GetConfigName());
bool useWatcomQuote = mf->IsOn(createRule+"_USE_WATCOM_QUOTE");
cmLocalNinjaGenerator& localGen = *this->GetLocalGenerator();
+
+ vars["TARGET_FILE"] =
+ localGen.ConvertToOutputFormat(targetOutputReal, cmLocalGenerator::SHELL);
+
localGen.GetTargetFlags(vars["LINK_LIBRARIES"],
vars["FLAGS"],
vars["LINK_FLAGS"],
@@ -509,6 +508,10 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
cmLocalGenerator::SHELL);
vars["TARGET_IMPLIB"] = impLibPath;
EnsureParentDirectoryExists(impLibPath);
+ if(target.HasImportLibrary())
+ {
+ outputs.push_back(targetOutputImplib);
+ }
}
if (!this->SetMsvcTargetPdbVariable(vars))
@@ -531,7 +534,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
if (mf->IsOn("CMAKE_COMPILER_IS_MINGW"))
{
const std::string objPath = GetTarget()->GetSupportDirectory();
- vars["OBJECT_DIR"] = ConvertToNinjaPath(objPath.c_str());
+ vars["OBJECT_DIR"] = ConvertToNinjaPath(objPath);
EnsureDirectoryExists(objPath);
// ar.exe can't handle backslashes in rsp files (implicitly used by gcc)
std::string& linkLibraries = vars["LINK_LIBRARIES"];
@@ -553,6 +556,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
&postBuildCmdLines
};
+ cmNinjaDeps byproducts;
for (unsigned i = 0; i != 3; ++i)
{
for (std::vector<cmCustomCommand>::const_iterator
@@ -561,6 +565,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
{
cmCustomCommandGenerator ccg(*ci, cfgName, mf);
localGen.AppendCustomCommandLines(ccg, *cmdLineLists[i]);
+ std::vector<std::string> const& ccByproducts = ccg.GetByproducts();
+ std::transform(ccByproducts.begin(), ccByproducts.end(),
+ std::back_inserter(byproducts), MapToNinjaPath());
}
}
@@ -608,6 +615,17 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
this->GetLocalGenerator()->AppendTargetDepends(this->GetTarget(),
orderOnlyDeps);
+ // Ninja should restat after linking if and only if there are byproducts.
+ vars["RESTAT"] = byproducts.empty()? "" : "1";
+
+ for (cmNinjaDeps::const_iterator oi = byproducts.begin(),
+ oe = byproducts.end();
+ oi != oe; ++oi)
+ {
+ this->GetGlobalGenerator()->SeenCustomCommandOutput(*oi);
+ outputs.push_back(*oi);
+ }
+
// Write the build statement for this target.
globalGen.WriteBuild(this->GetBuildFileStream(),
comment.str(),
@@ -659,16 +677,6 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
}
}
- if (!this->TargetNameImport.empty())
- {
- // Since using multiple outputs would mess up the $out variable, use an
- // alias for the import library.
- globalGen.WritePhonyBuild(this->GetBuildFileStream(),
- "Alias for import library.",
- cmNinjaDeps(1, targetOutputImplib),
- cmNinjaDeps(1, targetOutputReal));
- }
-
// Add aliases for the file name and the target name.
globalGen.AddTargetAlias(this->TargetNameOut, &target);
globalGen.AddTargetAlias(this->GetTargetName(), &target);