Unify the way the flags of a static library are read
Introduce cmLocalGenerator::GetStaticLibraryFlags() to have a central function for getting the linker flags for a given target.
This commit is contained in:
parent
8d3b65346f
commit
14bbf8340a
@ -1769,27 +1769,31 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
|||||||
configName);
|
configName);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* linkFlagsProp = "LINK_FLAGS";
|
|
||||||
if(target.GetType() == cmTarget::OBJECT_LIBRARY ||
|
if(target.GetType() == cmTarget::OBJECT_LIBRARY ||
|
||||||
target.GetType() == cmTarget::STATIC_LIBRARY)
|
target.GetType() == cmTarget::STATIC_LIBRARY)
|
||||||
{
|
{
|
||||||
linkFlagsProp = "STATIC_LIBRARY_FLAGS";
|
this->CurrentLocalGenerator
|
||||||
|
->GetStaticLibraryFlags(extraLinkOptions,
|
||||||
|
cmSystemTools::UpperCase(configName),
|
||||||
|
&target);
|
||||||
}
|
}
|
||||||
const char* targetLinkFlags = target.GetProperty(linkFlagsProp);
|
else
|
||||||
|
{
|
||||||
|
const char* targetLinkFlags = target.GetProperty("LINK_FLAGS");
|
||||||
if(targetLinkFlags)
|
if(targetLinkFlags)
|
||||||
{
|
{
|
||||||
extraLinkOptions += " ";
|
this->CurrentLocalGenerator->
|
||||||
extraLinkOptions += targetLinkFlags;
|
AppendFlags(extraLinkOptions, targetLinkFlags);
|
||||||
}
|
}
|
||||||
if(configName && *configName)
|
if(configName && *configName)
|
||||||
{
|
{
|
||||||
std::string linkFlagsVar = linkFlagsProp;
|
std::string linkFlagsVar = "LINK_FLAGS_";
|
||||||
linkFlagsVar += "_";
|
|
||||||
linkFlagsVar += cmSystemTools::UpperCase(configName);
|
linkFlagsVar += cmSystemTools::UpperCase(configName);
|
||||||
if(const char* linkFlags = target.GetProperty(linkFlagsVar.c_str()))
|
if(const char* linkFlags = target.GetProperty(linkFlagsVar.c_str()))
|
||||||
{
|
{
|
||||||
extraLinkOptions += " ";
|
this->CurrentLocalGenerator->
|
||||||
extraLinkOptions += linkFlags;
|
AppendFlags(extraLinkOptions, linkFlags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1541,6 +1541,18 @@ void cmLocalGenerator::GetIncludeDirectories(std::vector<std::string>& dirs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cmLocalGenerator::GetStaticLibraryFlags(std::string& flags,
|
||||||
|
std::string const& config,
|
||||||
|
cmTarget* target)
|
||||||
|
{
|
||||||
|
this->AppendFlags(flags, target->GetProperty("STATIC_LIBRARY_FLAGS"));
|
||||||
|
if(!config.empty())
|
||||||
|
{
|
||||||
|
std::string name = "STATIC_LIBRARY_FLAGS_" + config;
|
||||||
|
this->AppendFlags(flags, target->GetProperty(name.c_str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
|
void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
|
||||||
std::string& flags,
|
std::string& flags,
|
||||||
std::string& linkFlags,
|
std::string& linkFlags,
|
||||||
@ -1557,26 +1569,7 @@ void cmLocalGenerator::GetTargetFlags(std::string& linkLibs,
|
|||||||
switch(target->GetType())
|
switch(target->GetType())
|
||||||
{
|
{
|
||||||
case cmTarget::STATIC_LIBRARY:
|
case cmTarget::STATIC_LIBRARY:
|
||||||
{
|
this->GetStaticLibraryFlags(linkFlags, buildType, target->Target);
|
||||||
const char* targetLinkFlags =
|
|
||||||
target->GetProperty("STATIC_LIBRARY_FLAGS");
|
|
||||||
if(targetLinkFlags)
|
|
||||||
{
|
|
||||||
linkFlags += targetLinkFlags;
|
|
||||||
linkFlags += " ";
|
|
||||||
}
|
|
||||||
if(!buildType.empty())
|
|
||||||
{
|
|
||||||
std::string build = "STATIC_LIBRARY_FLAGS_";
|
|
||||||
build += buildType;
|
|
||||||
targetLinkFlags = target->GetProperty(build.c_str());
|
|
||||||
if(targetLinkFlags)
|
|
||||||
{
|
|
||||||
linkFlags += targetLinkFlags;
|
|
||||||
linkFlags += " ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case cmTarget::MODULE_LIBRARY:
|
case cmTarget::MODULE_LIBRARY:
|
||||||
libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
|
libraryLinkVariable = "CMAKE_MODULE_LINKER_FLAGS";
|
||||||
|
@ -348,6 +348,11 @@ public:
|
|||||||
std::string const& dir_max,
|
std::string const& dir_max,
|
||||||
bool* hasSourceExtension = 0);
|
bool* hasSourceExtension = 0);
|
||||||
|
|
||||||
|
/** Fill out the static linker flags for the given target. */
|
||||||
|
void GetStaticLibraryFlags(std::string& flags,
|
||||||
|
std::string const& config,
|
||||||
|
cmTarget* target);
|
||||||
|
|
||||||
/** Fill out these strings for the given target. Libraries to link,
|
/** Fill out these strings for the given target. Libraries to link,
|
||||||
* flags, and linkflags. */
|
* flags, and linkflags. */
|
||||||
void GetTargetFlags(std::string& linkLibs,
|
void GetTargetFlags(std::string& linkLibs,
|
||||||
|
@ -1039,17 +1039,7 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::string libflags;
|
std::string libflags;
|
||||||
if(const char* flags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
|
this->GetStaticLibraryFlags(libflags, configTypeUpper, &target);
|
||||||
{
|
|
||||||
libflags += flags;
|
|
||||||
}
|
|
||||||
std::string libFlagsConfig = "STATIC_LIBRARY_FLAGS_";
|
|
||||||
libFlagsConfig += configTypeUpper;
|
|
||||||
if(const char* flagsConfig = target.GetProperty(libFlagsConfig.c_str()))
|
|
||||||
{
|
|
||||||
libflags += " ";
|
|
||||||
libflags += flagsConfig;
|
|
||||||
}
|
|
||||||
if(!libflags.empty())
|
if(!libflags.empty())
|
||||||
{
|
{
|
||||||
fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
|
fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
|
||||||
|
@ -144,12 +144,8 @@ void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string extraFlags;
|
std::string extraFlags;
|
||||||
this->LocalGenerator->AppendFlags
|
this->LocalGenerator->GetStaticLibraryFlags(extraFlags,
|
||||||
(extraFlags,this->Target->GetProperty("STATIC_LIBRARY_FLAGS"));
|
cmSystemTools::UpperCase(this->ConfigName), this->Target);
|
||||||
std::string staticLibraryFlagsConfig = "STATIC_LIBRARY_FLAGS_";
|
|
||||||
staticLibraryFlagsConfig += cmSystemTools::UpperCase(this->ConfigName);
|
|
||||||
this->LocalGenerator->AppendFlags
|
|
||||||
(extraFlags, this->Target->GetProperty(staticLibraryFlagsConfig.c_str()));
|
|
||||||
this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), false);
|
this->WriteLibraryRules(linkRuleVar.c_str(), extraFlags.c_str(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1417,20 +1417,17 @@ cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const char* libflags = this->Target->GetProperty("STATIC_LIBRARY_FLAGS");
|
std::string libflags;
|
||||||
std::string flagsConfigVar = "STATIC_LIBRARY_FLAGS_";
|
this->LocalGenerator->GetStaticLibraryFlags(libflags,
|
||||||
flagsConfigVar += cmSystemTools::UpperCase(config);
|
cmSystemTools::UpperCase(config), this->Target);
|
||||||
const char* libflagsConfig =
|
if(!libflags.empty())
|
||||||
this->Target->GetProperty(flagsConfigVar.c_str());
|
|
||||||
if(libflags || libflagsConfig)
|
|
||||||
{
|
{
|
||||||
this->WriteString("<Lib>\n", 2);
|
this->WriteString("<Lib>\n", 2);
|
||||||
cmVisualStudioGeneratorOptions
|
cmVisualStudioGeneratorOptions
|
||||||
libOptions(this->LocalGenerator,
|
libOptions(this->LocalGenerator,
|
||||||
cmVisualStudioGeneratorOptions::Linker,
|
cmVisualStudioGeneratorOptions::Linker,
|
||||||
cmVSGetLibFlagTable(this->LocalGenerator), 0, this);
|
cmVSGetLibFlagTable(this->LocalGenerator), 0, this);
|
||||||
libOptions.Parse(libflags?libflags:"");
|
libOptions.Parse(libflags.c_str());
|
||||||
libOptions.Parse(libflagsConfig?libflagsConfig:"");
|
|
||||||
libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
|
libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
|
||||||
libOptions.OutputFlagMap(*this->BuildFileStream, " ");
|
libOptions.OutputFlagMap(*this->BuildFileStream, " ");
|
||||||
this->WriteString("</Lib>\n", 2);
|
this->WriteString("</Lib>\n", 2);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user