ENH: add support for per config target LINK_FLAGS

This commit is contained in:
Bill Hoffman 2006-04-03 12:57:51 -04:00
parent 32b63ef915
commit 3c8e899102
6 changed files with 63 additions and 7 deletions

View File

@ -1045,6 +1045,14 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
{
linkFlags += targetLinkFlags;
linkFlags += " ";
std::string configLinkFlags = targetLinkFlags;
configLinkFlags += buildType;
targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
if(targetLinkFlags)
{
linkFlags += targetLinkFlags;
linkFlags += " ";
}
}
cmOStringStream linklibsStr;
this->OutputLinkLibraries(linklibsStr, target, false);
@ -1103,7 +1111,15 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
if(targetLinkFlags)
{
linkFlags += targetLinkFlags;
linkFlags += " ";
linkFlags += " ";
std::string configLinkFlags = targetLinkFlags;
configLinkFlags += buildType;
targetLinkFlags = target.GetProperty(configLinkFlags.c_str());
if(targetLinkFlags)
{
linkFlags += targetLinkFlags;
linkFlags += " ";
}
}
}
break;

View File

@ -1062,7 +1062,6 @@ void cmLocalVisualStudio6Generator
libMultiLineOptionsForDebug += targetLinkFlags;
libMultiLineOptionsForDebug += " \n";
}
// are there any custom rules on the target itself
// only if the target is a lib or exe
@ -1185,18 +1184,38 @@ void cmLocalVisualStudio6Generator
std::string flagVar = baseFlagVar + "_RELEASE";
flagsRelease = this->Makefile->GetRequiredDefinition(flagVar.c_str());
flagsRelease += " -DCMAKE_INTDIR=\\\"Release\\\" ";
if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_RELEASE"))
{
flagsRelease += targetLinkFlags;
flagsRelease += " ";
}
flagVar = baseFlagVar + "_MINSIZEREL";
flagsMinSize = this->Makefile->GetRequiredDefinition(flagVar.c_str());
flagsMinSize += " -DCMAKE_INTDIR=\\\"MinSizeRel\\\" ";
if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_MINSIZEREL"))
{
flagsMinSize += targetLinkFlags;
flagsMinSize += " ";
}
flagVar = baseFlagVar + "_DEBUG";
flagsDebug = this->Makefile->GetRequiredDefinition(flagVar.c_str());
flagsDebug += " -DCMAKE_INTDIR=\\\"Debug\\\" ";
if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_DEBUG"))
{
flagsDebug += targetLinkFlags;
flagsDebug += " ";
}
flagVar = baseFlagVar + "_RELWITHDEBINFO";
flagsDebugRel = this->Makefile->GetRequiredDefinition(flagVar.c_str());
flagsDebugRel += " -DCMAKE_INTDIR=\\\"RelWithDebInfo\\\" ";
if(const char* targetLinkFlags = target.GetProperty("LINK_FLAGS_RELWITHDEBINFO"))
{
flagsDebugRel += targetLinkFlags;
flagsDebugRel += " ";
}
}
// if unicode is not found, then add -D_MBCS

View File

@ -626,7 +626,15 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
extraLinkOptions += " ";
extraLinkOptions += targetLinkFlags;
}
std::string configTypeUpper = cmSystemTools::UpperCase(configName);
std::string linkFlagsConfig = "LINK_FLAGS_";
linkFlagsConfig += configTypeUpper;
targetLinkFlags = target.GetProperty(linkFlagsConfig.c_str());
if(targetLinkFlags)
{
extraLinkOptions += " ";
extraLinkOptions += targetLinkFlags;
}
std::map<cmStdString, cmStdString> flagMap;
this->
FillFlagMapFromCommandFlags(flagMap,

View File

@ -232,7 +232,10 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
// Add target-specific linker flags.
this->LocalGenerator->AppendFlags(linkFlags, this->Target->GetProperty("LINK_FLAGS"));
std::string linkFlagsConfig = "LINK_FLAGS_";
linkFlagsConfig += cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str());
this->LocalGenerator->AppendFlags(linkFlags,
this->Target->GetProperty(linkFlagsConfig.c_str()));
// Construct a list of files associated with this executable that
// may need to be cleaned.
std::vector<std::string> exeCleanFiles;

View File

@ -109,6 +109,11 @@ void cmMakefileLibraryTargetGenerator::WriteSharedLibraryRules(bool relink)
std::string extraFlags;
this->LocalGenerator->AppendFlags(extraFlags, this->Target->GetProperty("LINK_FLAGS"));
std::string linkFlagsConfig = "LINK_FLAGS_";
linkFlagsConfig += cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str());
this->LocalGenerator->AppendFlags(extraFlags,
this->Target->GetProperty(linkFlagsConfig.c_str()));
this->LocalGenerator->AddConfigVariableFlags(extraFlags, "CMAKE_SHARED_LINKER_FLAGS",
this->LocalGenerator->ConfigurationName.c_str());
if(this->Makefile->IsOn("WIN32") && !(this->Makefile->IsOn("CYGWIN") || this->Makefile->IsOn("MINGW")))
@ -143,6 +148,10 @@ void cmMakefileLibraryTargetGenerator::WriteModuleLibraryRules(bool relink)
std::string extraFlags;
this->LocalGenerator->AppendFlags(extraFlags, this->Target->GetProperty("LINK_FLAGS"));
std::string linkFlagsConfig = "LINK_FLAGS_";
linkFlagsConfig += cmSystemTools::UpperCase(this->LocalGenerator->ConfigurationName.c_str());
this->LocalGenerator->AppendFlags(extraFlags,
this->Target->GetProperty(linkFlagsConfig.c_str()));
this->LocalGenerator->AddConfigVariableFlags(extraFlags, "CMAKE_MODULE_LINKER_FLAGS",
this->LocalGenerator->ConfigurationName.c_str());
// TODO: .def files should be supported here also.

View File

@ -79,7 +79,8 @@ public:
"variable for executables)."
"\n"
"The LINK_FLAGS property can be used to add extra flags to the "
"link step of a target. "
"link step of a target. LINK_FLAGS_<CONFIG> will add to the configuration "
"<CONFIG>, for example, DEBUG, RELEASE, MINSIZEREL, RELWITHDEBINFO. "
"DEFINE_SYMBOL sets the name of the preprocessor symbol defined when "
"compiling sources in a shared library. "
"If not set here then it is set to target_EXPORTS by default "