ENH: Created method cmTarget::GetExportMacro to centralize computation of the export symbol name. This removes duplicate code from all the generators. Also enabled the export definition for executable targets with the ENABLE_EXPORTS property set.

This commit is contained in:
Brad King 2007-03-27 23:13:25 -04:00
parent 341853c887
commit af95f61d76
6 changed files with 48 additions and 52 deletions

View File

@ -1067,21 +1067,11 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
{
std::string flags;
std::string defFlags;
bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
(target.GetType() == cmTarget::MODULE_LIBRARY));
if(shared)
// Add the export symbol definition for shared library objects.
if(const char* exportMacro = target.GetExportMacro())
{
defFlags += "-D";
if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
{
defFlags += custom_export_name;
}
else
{
std::string in = target.GetName();
in += "_EXPORTS";
defFlags += cmSystemTools::MakeCindentifier(in.c_str());
}
defFlags += exportMacro;
}
const char* lang = target.GetLinkerLanguage(this);
std::string cflags;

View File

@ -1289,18 +1289,13 @@ void cmLocalVisualStudio6Generator
staticLibOptions = libflags;
}
}
std::string exportSymbol;
if (const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
{
exportSymbol = custom_export_name;
}
else
{
std::string in = libName;
in += "_EXPORTS";
exportSymbol = cmSystemTools::MakeCindentifier(in.c_str());
}
// Add the export symbol definition for shared library objects.
std::string exportSymbol;
if(const char* exportMacro = target.GetExportMacro())
{
exportSymbol = exportMacro;
}
std::string line;
while(cmSystemTools::GetLineFromStream(fin, line))

View File

@ -520,22 +520,10 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
configDefine += "\\\"";
targetOptions.AddDefine(configDefine);
// Add a definition for the export macro.
if(target.GetType() == cmTarget::SHARED_LIBRARY ||
target.GetType() == cmTarget::MODULE_LIBRARY)
// Add the export symbol definition for shared library objects.
if(const char* exportMacro = target.GetExportMacro())
{
std::string exportSymbol;
if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
{
exportSymbol = custom_export_name;
}
else
{
std::string id = libName;
id += "_EXPORTS";
exportSymbol = cmSystemTools::MakeCindentifier(id.c_str());
}
targetOptions.AddDefine(exportSymbol);
targetOptions.AddDefine(exportMacro);
}
// The intermediate directory name consists of a directory for the

View File

@ -243,23 +243,14 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
{
const char *lang = l->first.c_str();
std::string flags;
// Add the export symbol definition for shared library objects.
bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) ||
(this->Target->GetType() == cmTarget::MODULE_LIBRARY));
if(shared)
// Add the export symbol definition for shared library objects.
if(const char* exportMacro = this->Target->GetExportMacro())
{
flags += "-D";
if(const char* custom_export_name =
this->Target->GetProperty("DEFINE_SYMBOL"))
{
flags += custom_export_name;
}
else
{
std::string in = this->Target->GetName();
in += "_EXPORTS";
flags += cmSystemTools::MakeCindentifier(in.c_str());
}
flags += exportMacro;
}
// Add language-specific flags.

View File

@ -2157,3 +2157,30 @@ const char* cmTarget::GetOutputDir(bool implib)
return out.c_str();
}
//----------------------------------------------------------------------------
const char* cmTarget::GetExportMacro()
{
// Define the symbol for targets that export symbols.
if(this->GetType() == cmTarget::SHARED_LIBRARY ||
this->GetType() == cmTarget::MODULE_LIBRARY ||
this->GetType() == cmTarget::EXECUTABLE &&
this->GetPropertyAsBool("ENABLE_EXPORTS"))
{
if(const char* custom_export_name = this->GetProperty("DEFINE_SYMBOL"))
{
this->ExportMacro = custom_export_name;
}
else
{
std::string in = this->GetName();
in += "_EXPORTS";
this->ExportMacro = cmSystemTools::MakeCindentifier(in.c_str());
}
return this->ExportMacro.c_str();
}
else
{
return 0;
}
}

View File

@ -259,6 +259,10 @@ public:
// Compute the OBJECT_FILES property only when requested
void ComputeObjectFiles();
/** Get the macro to define when building sources in this target.
If no macro should be defined null is returned. */
const char* GetExportMacro();
private:
/**
* A list of direct dependencies. Use in conjunction with DependencyMap.
@ -359,6 +363,7 @@ private:
std::string OutputDirImplib;
std::string Directory;
std::string Location;
std::string ExportMacro;
std::set<cmStdString> Utilities;
bool RecordDependencies;
cmPropertyMap Properties;