Commit af95f61d authored by Brad King's avatar Brad King
Browse files

ENH: Created method cmTarget::GetExportMacro to centralize computation of the...

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.
parent 341853c8
......@@ -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;
......
......@@ -1289,18 +1289,13 @@ void cmLocalVisualStudio6Generator
staticLibOptions = libflags;
}
}
// Add the export symbol definition for shared library objects.
std::string exportSymbol;
if (const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
if(const char* exportMacro = target.GetExportMacro())
{
exportSymbol = custom_export_name;
exportSymbol = exportMacro;
}
else
{
std::string in = libName;
in += "_EXPORTS";
exportSymbol = cmSystemTools::MakeCindentifier(in.c_str());
}
std::string line;
while(cmSystemTools::GetLineFromStream(fin, line))
......
......@@ -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
......
......@@ -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.
......
......@@ -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;
}
}
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment