summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefileLibraryTargetGenerator.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmMakefileLibraryTargetGenerator.cxx')
-rw-r--r--Source/cmMakefileLibraryTargetGenerator.cxx148
1 files changed, 85 insertions, 63 deletions
diff --git a/Source/cmMakefileLibraryTargetGenerator.cxx b/Source/cmMakefileLibraryTargetGenerator.cxx
index 2b1d7cc..a249efd 100644
--- a/Source/cmMakefileLibraryTargetGenerator.cxx
+++ b/Source/cmMakefileLibraryTargetGenerator.cxx
@@ -5,12 +5,15 @@
#include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h"
#include "cmGlobalUnixMakefileGenerator3.h"
+#include "cmLinkLineComputer.h"
#include "cmLocalGenerator.h"
#include "cmLocalUnixMakefileGenerator3.h"
#include "cmMakefile.h"
#include "cmOSXBundleGenerator.h"
#include "cmOutputConverter.h"
+#include "cmRulePlaceholderExpander.h"
#include "cmState.h"
+#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmake.h"
@@ -22,7 +25,7 @@ cmMakefileLibraryTargetGenerator::cmMakefileLibraryTargetGenerator(
: cmMakefileTargetGenerator(target)
{
this->CustomCommandDriver = OnDepends;
- if (this->GeneratorTarget->GetType() != cmState::INTERFACE_LIBRARY) {
+ if (this->GeneratorTarget->GetType() != cmStateEnums::INTERFACE_LIBRARY) {
this->GeneratorTarget->GetLibraryNames(
this->TargetNameOut, this->TargetNameSO, this->TargetNameReal,
this->TargetNameImport, this->TargetNamePDB, this->ConfigName);
@@ -55,24 +58,24 @@ void cmMakefileLibraryTargetGenerator::WriteRuleFiles()
// write the link rules
// Write the rule for this target type.
switch (this->GeneratorTarget->GetType()) {
- case cmState::STATIC_LIBRARY:
+ case cmStateEnums::STATIC_LIBRARY:
this->WriteStaticLibraryRules();
break;
- case cmState::SHARED_LIBRARY:
+ case cmStateEnums::SHARED_LIBRARY:
this->WriteSharedLibraryRules(false);
if (this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName)) {
// Write rules to link an installable version of the target.
this->WriteSharedLibraryRules(true);
}
break;
- case cmState::MODULE_LIBRARY:
+ case cmStateEnums::MODULE_LIBRARY:
this->WriteModuleLibraryRules(false);
if (this->GeneratorTarget->NeedRelinkBeforeInstall(this->ConfigName)) {
// Write rules to link an installable version of the target.
this->WriteModuleLibraryRules(true);
}
break;
- case cmState::OBJECT_LIBRARY:
+ case cmStateEnums::OBJECT_LIBRARY:
this->WriteObjectLibraryRules();
break;
default:
@@ -159,7 +162,13 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
this->LocalGenerator->AddConfigVariableFlags(
extraFlags, "CMAKE_SHARED_LINKER_FLAGS", this->ConfigName);
- this->AddModuleDefinitionFlag(extraFlags);
+
+ CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ this->CreateLinkLineComputer(
+ this->LocalGenerator,
+ this->LocalGenerator->GetStateSnapshot().GetDirectory()));
+
+ this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
if (this->GeneratorTarget->GetPropertyAsBool("LINK_WHAT_YOU_USE")) {
this->LocalGenerator->AppendFlags(extraFlags, " -Wl,--no-as-needed");
@@ -184,7 +193,13 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
extraFlags, this->GeneratorTarget->GetProperty(linkFlagsConfig));
this->LocalGenerator->AddConfigVariableFlags(
extraFlags, "CMAKE_MODULE_LINKER_FLAGS", this->ConfigName);
- this->AddModuleDefinitionFlag(extraFlags);
+
+ CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ this->CreateLinkLineComputer(
+ this->LocalGenerator,
+ this->LocalGenerator->GetStateSnapshot().GetDirectory()));
+
+ this->AddModuleDefinitionFlag(linkLineComputer.get(), extraFlags);
this->WriteLibraryRules(linkRuleVar, extraFlags, relink);
}
@@ -237,8 +252,8 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
this->LocalGenerator->AppendFlags(linkFlags, extraFlags);
// Add OSX version flags, if any.
- if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY ||
- this->GeneratorTarget->GetType() == cmState::MODULE_LIBRARY) {
+ if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY ||
+ this->GeneratorTarget->GetType() == cmStateEnums::MODULE_LIBRARY) {
this->AppendOSXVerFlag(linkFlags, linkLanguage, "COMPATIBILITY", true);
this->AppendOSXVerFlag(linkFlags, linkLanguage, "CURRENT", false);
}
@@ -305,20 +320,20 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
targetFullPathPDB, cmOutputConverter::SHELL);
std::string targetOutPath = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->ConvertToRelativePath(
+ this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPath),
cmOutputConverter::SHELL);
std::string targetOutPathSO = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->ConvertToRelativePath(
+ this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathSO),
cmOutputConverter::SHELL);
std::string targetOutPathReal = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->ConvertToRelativePath(
+ this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathReal),
cmOutputConverter::SHELL);
std::string targetOutPathImport =
this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->ConvertToRelativePath(
+ this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(),
targetFullPathImport),
cmOutputConverter::SHELL);
@@ -331,13 +346,13 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
std::string buildEcho = "Linking ";
buildEcho += linkLanguage;
switch (this->GeneratorTarget->GetType()) {
- case cmState::STATIC_LIBRARY:
+ case cmStateEnums::STATIC_LIBRARY:
buildEcho += " static library ";
break;
- case cmState::SHARED_LIBRARY:
+ case cmStateEnums::SHARED_LIBRARY:
buildEcho += " shared library ";
break;
- case cmState::MODULE_LIBRARY:
+ case cmStateEnums::MODULE_LIBRARY:
if (this->GeneratorTarget->IsCFBundleOnApple()) {
buildEcho += " CFBundle";
}
@@ -352,38 +367,26 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
commands, buildEcho, cmLocalUnixMakefileGenerator3::EchoLink, &progress);
}
- const char* forbiddenFlagVar = CM_NULLPTR;
- switch (this->GeneratorTarget->GetType()) {
- case cmState::SHARED_LIBRARY:
- forbiddenFlagVar = "_CREATE_SHARED_LIBRARY_FORBIDDEN_FLAGS";
- break;
- case cmState::MODULE_LIBRARY:
- forbiddenFlagVar = "_CREATE_SHARED_MODULE_FORBIDDEN_FLAGS";
- break;
- default:
- break;
- }
-
// Clean files associated with this library.
std::vector<std::string> libCleanFiles;
- libCleanFiles.push_back(this->LocalGenerator->ConvertToRelativePath(
+ libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPath));
if (targetNameReal != targetName) {
- libCleanFiles.push_back(this->LocalGenerator->ConvertToRelativePath(
+ libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathReal));
}
if (targetNameSO != targetName && targetNameSO != targetNameReal) {
- libCleanFiles.push_back(this->LocalGenerator->ConvertToRelativePath(
+ libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathSO));
}
if (!targetNameImport.empty()) {
- libCleanFiles.push_back(this->LocalGenerator->ConvertToRelativePath(
+ libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(),
targetFullPathImport));
std::string implib;
if (this->GeneratorTarget->GetImplibGNUtoMS(targetFullPathImport,
implib)) {
- libCleanFiles.push_back(this->LocalGenerator->ConvertToRelativePath(
+ libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), implib));
}
}
@@ -391,14 +394,14 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// List the PDB for cleaning only when the whole target is
// cleaned. We do not want to delete the .pdb file just before
// linking the target.
- this->CleanFiles.push_back(this->LocalGenerator->ConvertToRelativePath(
+ this->CleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathPDB));
#ifdef _WIN32
// There may be a manifest file for this target. Add it to the
// clean set just in case.
- if (this->GeneratorTarget->GetType() != cmState::STATIC_LIBRARY) {
- libCleanFiles.push_back(this->LocalGenerator->ConvertToRelativePath(
+ if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) {
+ libCleanFiles.push_back(this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(),
(targetFullPath + ".manifest").c_str()));
}
@@ -407,7 +410,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
std::vector<std::string> commands1;
// Add a command to remove any existing files for this library.
// for static libs only
- if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY) {
+ if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
this->LocalGenerator->AppendCleanCommand(commands1, libCleanFiles,
this->GeneratorTarget, "target");
this->LocalGenerator->CreateCDCommand(
@@ -441,7 +444,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
std::vector<std::string> archiveAppendCommands;
std::vector<std::string> archiveFinishCommands;
std::string::size_type archiveCommandLimit = std::string::npos;
- if (this->GeneratorTarget->GetType() == cmState::STATIC_LIBRARY) {
+ if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) {
haveStaticLibraryRule = this->Makefile->IsDefinitionSet(linkRuleVar);
std::string arCreateVar = "CMAKE_";
arCreateVar += linkLanguage;
@@ -490,9 +493,18 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// Collect up flags to link in needed libraries.
std::string linkLibs;
- if (this->GeneratorTarget->GetType() != cmState::STATIC_LIBRARY) {
- this->CreateLinkLibs(linkLibs, relink, useResponseFileForLibs, depends,
- useWatcomQuote);
+ if (this->GeneratorTarget->GetType() != cmStateEnums::STATIC_LIBRARY) {
+
+ CM_AUTO_PTR<cmLinkLineComputer> linkLineComputer(
+ this->CreateLinkLineComputer(
+ this->LocalGenerator,
+ this->LocalGenerator->GetStateSnapshot().GetDirectory()));
+ linkLineComputer->SetForResponse(useResponseFileForLibs);
+ linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
+ linkLineComputer->SetRelink(relink);
+
+ this->CreateLinkLibs(linkLineComputer.get(), linkLibs,
+ useResponseFileForLibs, depends);
}
// Construct object file lists that may be needed to expand the
@@ -503,14 +515,14 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
useWatcomQuote);
// maybe create .def file from list of objects
- if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY &&
+ if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY &&
this->Makefile->IsOn("CMAKE_SUPPORT_WINDOWS_EXPORT_ALL_SYMBOLS")) {
this->GenDefFile(real_link_commands, linkFlags);
}
std::string manifests = this->GetManifests();
- cmLocalGenerator::RuleVariables vars;
+ cmRulePlaceholderExpander::RuleVariables vars;
vars.TargetPDB = targetOutPathPDB.c_str();
// Setup the target version.
@@ -530,14 +542,15 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
vars.TargetVersionMajor = targetVersionMajor.c_str();
vars.TargetVersionMinor = targetVersionMinor.c_str();
- vars.RuleLauncher = "RULE_LAUNCH_LINK";
- vars.CMTarget = this->GeneratorTarget;
+ vars.CMTargetName = this->GeneratorTarget->GetName().c_str();
+ vars.CMTargetType =
+ cmState::GetTargetTypeName(this->GeneratorTarget->GetType());
vars.Language = linkLanguage.c_str();
vars.Objects = buildObjs.c_str();
std::string objectDir = this->GeneratorTarget->GetSupportDirectory();
objectDir = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->ConvertToRelativePath(
+ this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), objectDir),
cmOutputConverter::SHELL);
@@ -546,7 +559,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
? cmOutputConverter::WATCOMQUOTE
: cmOutputConverter::SHELL;
std::string target = this->LocalGenerator->ConvertToOutputFormat(
- this->LocalGenerator->ConvertToRelativePath(
+ this->LocalGenerator->MaybeConvertToRelativePath(
this->LocalGenerator->GetCurrentBinaryDirectory(), targetFullPathReal),
output);
vars.Target = target.c_str();
@@ -562,7 +575,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// Compute the directory portion of the install_name setting.
std::string install_name_dir;
- if (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY) {
+ if (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY) {
// Get the install_name directory for the build tree.
install_name_dir =
this->GeneratorTarget->GetInstallNameDirForBuildTree(this->ConfigName);
@@ -585,15 +598,20 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
this->LocalGenerator->AddArchitectureFlags(
langFlags, this->GeneratorTarget, linkLanguage, this->ConfigName);
- // remove any language flags that might not work with the
- // particular os
- if (forbiddenFlagVar) {
- this->RemoveForbiddenFlags(forbiddenFlagVar, linkLanguage, langFlags);
- }
vars.LanguageCompileFlags = langFlags.c_str();
+ std::string launcher;
+ const char* val = this->LocalGenerator->GetRuleLauncher(
+ this->GeneratorTarget, "RULE_LAUNCH_LINK");
+ if (val && *val) {
+ launcher = val;
+ launcher += " ";
+ }
+
+ CM_AUTO_PTR<cmRulePlaceholderExpander> rulePlaceholderExpander(
+ this->LocalGenerator->CreateRulePlaceholderExpander());
// Construct the main link rule and expand placeholders.
- this->LocalGenerator->TargetImplib = targetOutPathImport;
+ rulePlaceholderExpander->SetTargetImpLib(targetOutPathImport);
if (useArchiveRules) {
// Construct the individual object list strings.
std::vector<std::string> object_strings;
@@ -606,8 +624,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
for (std::vector<std::string>::const_iterator i =
archiveCreateCommands.begin();
i != archiveCreateCommands.end(); ++i) {
- std::string cmd = *i;
- this->LocalGenerator->ExpandRuleVariables(cmd, vars);
+ std::string cmd = launcher + *i;
+ rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
+ cmd, vars);
real_link_commands.push_back(cmd);
}
}
@@ -617,8 +636,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
for (std::vector<std::string>::const_iterator i =
archiveAppendCommands.begin();
i != archiveAppendCommands.end(); ++i) {
- std::string cmd = *i;
- this->LocalGenerator->ExpandRuleVariables(cmd, vars);
+ std::string cmd = launcher + *i;
+ rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator,
+ cmd, vars);
real_link_commands.push_back(cmd);
}
}
@@ -627,8 +647,9 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
for (std::vector<std::string>::const_iterator i =
archiveFinishCommands.begin();
i != archiveFinishCommands.end(); ++i) {
- std::string cmd = *i;
- this->LocalGenerator->ExpandRuleVariables(cmd, vars);
+ std::string cmd = launcher + *i;
+ rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, cmd,
+ vars);
// If there is no ranlib the command will be ":". Skip it.
if (!cmd.empty() && cmd[0] != ':') {
real_link_commands.push_back(cmd);
@@ -639,7 +660,7 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
std::string linkRule = this->GetLinkRule(linkRuleVar);
cmSystemTools::ExpandListArgument(linkRule, real_link_commands);
if (this->GeneratorTarget->GetPropertyAsBool("LINK_WHAT_YOU_USE") &&
- (this->GeneratorTarget->GetType() == cmState::SHARED_LIBRARY)) {
+ (this->GeneratorTarget->GetType() == cmStateEnums::SHARED_LIBRARY)) {
std::string cmakeCommand = this->LocalGenerator->ConvertToOutputFormat(
cmSystemTools::GetCMakeCommand(), cmLocalGenerator::SHELL);
cmakeCommand += " -E __run_iwyu --lwyu=";
@@ -650,10 +671,11 @@ void cmMakefileLibraryTargetGenerator::WriteLibraryRules(
// Expand placeholders.
for (std::vector<std::string>::iterator i = real_link_commands.begin();
i != real_link_commands.end(); ++i) {
- this->LocalGenerator->ExpandRuleVariables(*i, vars);
+ *i = launcher + *i;
+ rulePlaceholderExpander->ExpandRuleVariables(this->LocalGenerator, *i,
+ vars);
}
}
- this->LocalGenerator->TargetImplib = "";
// Restore path conversion to normal shells.
this->LocalGenerator->SetLinkScriptShell(false);