From a1a30340a2eb0174f9f6911ee1e2cf4a36eaac96 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Sun, 19 Feb 2012 21:38:10 +0000 Subject: [PATCH] Ninja: Import library support for Windows --- Source/cmLocalNinjaGenerator.cxx | 1 + Source/cmNinjaNormalTargetGenerator.cxx | 21 +++++++++++++++++---- Source/cmNinjaTargetGenerator.cxx | 13 ------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/Source/cmLocalNinjaGenerator.cxx b/Source/cmLocalNinjaGenerator.cxx index 687dbb87d..ea03cbb2e 100644 --- a/Source/cmLocalNinjaGenerator.cxx +++ b/Source/cmLocalNinjaGenerator.cxx @@ -31,6 +31,7 @@ cmLocalNinjaGenerator::cmLocalNinjaGenerator() #ifdef _WIN32 this->WindowsShell = true; #endif + this->TargetImplib = "$TARGET_IMPLIB"; } //---------------------------------------------------------------------------- diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index 66714e953..9294a013f 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -172,10 +172,6 @@ cmNinjaNormalTargetGenerator i != linkCmds.end(); ++i) { -#ifdef _WIN32 - // TODO TARGET_IMPLIB is empty - cmSystemTools::ReplaceString(*i, "/implib:", ""); -#endif this->GetLocalGenerator()->ExpandRuleVariables(*i, vars); } linkCmds.insert(linkCmds.begin(), "$PRE_LINK"); @@ -314,6 +310,9 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement() this->GetTarget()->GetFullPath(this->GetConfigName(), /*implib=*/false, /*realpath=*/true).c_str()); + std::string targetOutputImplib = ConvertToNinjaPath( + this->GetTarget()->GetFullPath(this->GetConfigName(), + /*implib=*/true).c_str()); // Compute the 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 *cmdLists[3] = { &this->GetTarget()->GetPreBuildCommands(), &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. this->GetGlobalGenerator()->AddTargetAlias(this->TargetNameOut, this->GetTarget()); diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index 1a8d13d41..8a563b640 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -223,22 +223,9 @@ cmNinjaDeps cmNinjaTargetGenerator::ComputeLinkDeps() const if(!cli) return cmNinjaDeps(); - -#ifndef _WIN32 const std::vector &deps = cli->GetDepends(); cmNinjaDeps result(deps.size()); 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; }