Add STATIC_LIBRARY_FLAGS_<CONFIG> property (#10768)

This is a per-configuration version of STATIC_LIBRARY_FLAGS.
This commit is contained in:
Brad King 2010-05-28 10:45:54 -04:00
parent d3303dbc81
commit fe971d97ca
7 changed files with 77 additions and 13 deletions

View File

@ -1381,11 +1381,43 @@ void cmLocalVisualStudio6Generator
cmSystemTools::Error("Error Reading ", this->DSPHeaderTemplate.c_str());
}
std::string staticLibOptions;
std::string staticLibOptionsDebug;
std::string staticLibOptionsRelease;
std::string staticLibOptionsMinSizeRel;
std::string staticLibOptionsRelWithDebInfo;
if(target.GetType() == cmTarget::STATIC_LIBRARY )
{
if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
{
staticLibOptions = libflags;
staticLibOptionsDebug = libflags;
staticLibOptionsRelease = libflags;
staticLibOptionsMinSizeRel = libflags;
staticLibOptionsRelWithDebInfo = libflags;
}
if(const char* libflagsDebug =
target.GetProperty("STATIC_LIBRARY_FLAGS_DEBUG"))
{
staticLibOptionsDebug += " ";
staticLibOptionsDebug = libflagsDebug;
}
if(const char* libflagsRelease =
target.GetProperty("STATIC_LIBRARY_FLAGS_RELEASE"))
{
staticLibOptionsRelease += " ";
staticLibOptionsRelease = libflagsRelease;
}
if(const char* libflagsMinSizeRel =
target.GetProperty("STATIC_LIBRARY_FLAGS_MINSIZEREL"))
{
staticLibOptionsMinSizeRel += " ";
staticLibOptionsMinSizeRel = libflagsMinSizeRel;
}
if(const char* libflagsRelWithDebInfo =
target.GetProperty("STATIC_LIBRARY_FLAGS_RELWITHDEBINFO"))
{
staticLibOptionsRelWithDebInfo += " ";
staticLibOptionsRelWithDebInfo = libflagsRelWithDebInfo;
}
}
@ -1417,6 +1449,14 @@ void cmLocalVisualStudio6Generator
mfcFlag);
if(target.GetType() == cmTarget::STATIC_LIBRARY )
{
cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_DEBUG",
staticLibOptionsDebug.c_str());
cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_RELEASE",
staticLibOptionsRelease.c_str());
cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_MINSIZEREL",
staticLibOptionsMinSizeRel.c_str());
cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS_RELWITHDEBINFO",
staticLibOptionsRelWithDebInfo.c_str());
cmSystemTools::ReplaceString(line, "CM_STATIC_LIB_ARGS",
staticLibOptions.c_str());
}

View File

@ -915,7 +915,20 @@ void cmLocalVisualStudio7Generator::OutputBuildTool(std::ostream& fout,
}
fout << "\t\t\t<Tool\n"
<< "\t\t\t\tName=\"" << tool << "\"\n";
if(const char* libflags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
std::string libflags;
if(const char* flags = target.GetProperty("STATIC_LIBRARY_FLAGS"))
{
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())
{
fout << "\t\t\t\tAdditionalOptions=\"" << libflags << "\"\n";
}

View File

@ -122,6 +122,10 @@ void cmMakefileLibraryTargetGenerator::WriteStaticLibraryRules()
std::string extraFlags;
this->LocalGenerator->AppendFlags
(extraFlags,this->Target->GetProperty("STATIC_LIBRARY_FLAGS"));
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);
}

View File

@ -707,6 +707,11 @@ void cmTarget::DefineProperties(cmake *cm)
"Extra flags to use when linking static libraries.",
"Extra flags to use when linking a static library.");
cm->DefineProperty
("STATIC_LIBRARY_FLAGS_<CONFIG>", cmProperty::TARGET,
"Per-configuration flags for creating a static library.",
"This is the configuration-specific version of STATIC_LIBRARY_FLAGS.");
cm->DefineProperty
("SUFFIX", cmProperty::TARGET,
"What comes after the library name.",

View File

@ -1023,22 +1023,27 @@ WriteRCOptions(std::string const& ,
}
void cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const&
)
void
cmVisualStudio10TargetGenerator::WriteLibOptions(std::string const& config)
{
if(this->Target->GetType() != cmTarget::STATIC_LIBRARY)
{
return;
}
if(const char* libflags = this->Target
->GetProperty("STATIC_LIBRARY_FLAGS"))
const char* libflags = this->Target->GetProperty("STATIC_LIBRARY_FLAGS");
std::string flagsConfigVar = "STATIC_LIBRARY_FLAGS_";
flagsConfigVar += cmSystemTools::UpperCase(config);
const char* libflagsConfig =
this->Target->GetProperty(flagsConfigVar.c_str());
if(libflags || libflagsConfig)
{
this->WriteString("<Lib>\n", 2);
cmVisualStudioGeneratorOptions
libOptions(this->LocalGenerator, 10,
cmVisualStudioGeneratorOptions::Linker,
cmVS10LibFlagTable, 0, this);
libOptions.Parse(libflags);
libOptions.Parse(libflags?libflags:"");
libOptions.Parse(libflagsConfig?libflagsConfig:"");
libOptions.OutputAdditionalOptions(*this->BuildFileStream, " ", "");
libOptions.OutputFlagMap(*this->BuildFileStream, " ");
this->WriteString("</Lib>\n", 2);

View File

@ -67,7 +67,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_RELEASE/OUTPUT_NAME_RELEASE" CM_STATIC_LIB_ARGS
# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_RELEASE/OUTPUT_NAME_RELEASE" CM_STATIC_LIB_ARGS_RELEASE
CMAKE_CUSTOM_RULE_CODE_RELEASE
@ -97,7 +97,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_DEBUG/OUTPUT_NAME_DEBUG" CM_STATIC_LIB_ARGS
# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_DEBUG/OUTPUT_NAME_DEBUG" CM_STATIC_LIB_ARGS_DEBUG
CMAKE_CUSTOM_RULE_CODE_DEBUG
@ -128,7 +128,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_MINSIZEREL/OUTPUT_NAME_MINSIZEREL" CM_STATIC_LIB_ARGS
# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_MINSIZEREL/OUTPUT_NAME_MINSIZEREL" CM_STATIC_LIB_ARGS_MINSIZEREL
CMAKE_CUSTOM_RULE_CODE_MINSIZEREL
@ -158,7 +158,7 @@ BSC32=bscmake.exe
# ADD BSC32 /nologo
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_RELWITHDEBINFO/OUTPUT_NAME_RELWITHDEBINFO" CM_STATIC_LIB_ARGS
# ADD LIB32 /nologo /out:"OUTPUT_DIRECTORY_RELWITHDEBINFO/OUTPUT_NAME_RELWITHDEBINFO" CM_STATIC_LIB_ARGS_RELWITHDEBINFO
CMAKE_CUSTOM_RULE_CODE_RELWITHDEBINFO

View File

@ -202,9 +202,6 @@ IF(BUILD_TESTING)
ADD_LINK_FLAGS_TEST(dll_config lib_config)
ADD_LINK_FLAGS_TEST(exe_config dll_config)
# STATIC_LIBRARY_FLAGS_<CONFIG> not yet implemented
SET_TESTS_PROPERTIES(LinkFlags-lib_config PROPERTIES WILL_FAIL 1)
# If we are running right now with a UnixMakefiles based generator,
# build the "Simple" test with the ExtraGenerators, if available
# This doesn't test whether the generated project files work (unfortunately),