Ninja: Import library support for Windows

This commit is contained in:
Peter Collingbourne 2012-02-19 21:38:10 +00:00
parent 21997cea4d
commit a1a30340a2
3 changed files with 18 additions and 17 deletions

View File

@ -31,6 +31,7 @@ cmLocalNinjaGenerator::cmLocalNinjaGenerator()
#ifdef _WIN32 #ifdef _WIN32
this->WindowsShell = true; this->WindowsShell = true;
#endif #endif
this->TargetImplib = "$TARGET_IMPLIB";
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -172,10 +172,6 @@ cmNinjaNormalTargetGenerator
i != linkCmds.end(); i != linkCmds.end();
++i) ++i)
{ {
#ifdef _WIN32
// TODO TARGET_IMPLIB is empty
cmSystemTools::ReplaceString(*i, "/implib:", "");
#endif
this->GetLocalGenerator()->ExpandRuleVariables(*i, vars); this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
} }
linkCmds.insert(linkCmds.begin(), "$PRE_LINK"); linkCmds.insert(linkCmds.begin(), "$PRE_LINK");
@ -314,6 +310,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
this->GetTarget()->GetFullPath(this->GetConfigName(), this->GetTarget()->GetFullPath(this->GetConfigName(),
/*implib=*/false, /*implib=*/false,
/*realpath=*/true).c_str()); /*realpath=*/true).c_str());
std::string targetOutputImplib = ConvertToNinjaPath(
this->GetTarget()->GetFullPath(this->GetConfigName(),
/*implib=*/true).c_str());
// Compute the comment. // Compute the comment.
std::ostringstream comment; std::ostringstream comment;
@ -357,6 +356,11 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
} }
} }
if (!this->TargetNameImport.empty()) {
vars["TARGET_IMPLIB"] = this->GetLocalGenerator()->ConvertToOutputFormat(
targetOutputImplib.c_str(), cmLocalGenerator::SHELL);
}
std::vector<cmCustomCommand> *cmdLists[3] = { std::vector<cmCustomCommand> *cmdLists[3] = {
&this->GetTarget()->GetPreBuildCommands(), &this->GetTarget()->GetPreBuildCommands(),
&this->GetTarget()->GetPreLinkCommands(), &this->GetTarget()->GetPreLinkCommands(),
@ -434,6 +438,15 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement()
} }
} }
if (!this->TargetNameImport.empty()) {
// Since using multiple outputs would mess up the $out variable, use an
// alias for the import library.
cmGlobalNinjaGenerator::WritePhonyBuild(this->GetBuildFileStream(),
"Alias for import library.",
cmNinjaDeps(1, targetOutputImplib),
cmNinjaDeps(1, targetOutputReal));
}
// Add aliases for the file name and the target name. // Add aliases for the file name and the target name.
this->GetGlobalGenerator()->AddTargetAlias(this->TargetNameOut, this->GetGlobalGenerator()->AddTargetAlias(this->TargetNameOut,
this->GetTarget()); this->GetTarget());

View File

@ -223,22 +223,9 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const
if(!cli) if(!cli)
return cmNinjaDeps(); return cmNinjaDeps();
#ifndef _WIN32
const std::vector<std::string> &deps = cli->GetDepends(); const std::vector<std::string> &deps = cli->GetDepends();
cmNinjaDeps result(deps.size()); cmNinjaDeps result(deps.size());
std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath()); std::transform(deps.begin(), deps.end(), result.begin(), MapToNinjaPath());
#else
// TODO The ninja generator misses a lot on Windows.
// This hack avoids a problem when a Dll is build:
// It builds the .dll but uses the .lib which is then unknown to ninja.
cmNinjaDeps result;
for(unsigned i = 0; i < cli->GetItems().size(); ++i) {
if( cli->GetItems()[i].Target ) {
result.push_back( cli->GetItems()[i].Target->GetName() );
}
}
#endif
return result; return result;
} }