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:
parent
341853c887
commit
af95f61d76
|
@ -1067,21 +1067,11 @@ void cmGlobalXCodeGenerator::CreateBuildSettings(cmTarget& target,
|
||||||
{
|
{
|
||||||
std::string flags;
|
std::string flags;
|
||||||
std::string defFlags;
|
std::string defFlags;
|
||||||
bool shared = ((target.GetType() == cmTarget::SHARED_LIBRARY) ||
|
// Add the export symbol definition for shared library objects.
|
||||||
(target.GetType() == cmTarget::MODULE_LIBRARY));
|
if(const char* exportMacro = target.GetExportMacro())
|
||||||
if(shared)
|
|
||||||
{
|
{
|
||||||
defFlags += "-D";
|
defFlags += "-D";
|
||||||
if(const char* custom_export_name = target.GetProperty("DEFINE_SYMBOL"))
|
defFlags += exportMacro;
|
||||||
{
|
|
||||||
defFlags += custom_export_name;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::string in = target.GetName();
|
|
||||||
in += "_EXPORTS";
|
|
||||||
defFlags += cmSystemTools::MakeCindentifier(in.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const char* lang = target.GetLinkerLanguage(this);
|
const char* lang = target.GetLinkerLanguage(this);
|
||||||
std::string cflags;
|
std::string cflags;
|
||||||
|
|
|
@ -1289,18 +1289,13 @@ void cmLocalVisualStudio6Generator
|
||||||
staticLibOptions = libflags;
|
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;
|
std::string line;
|
||||||
while(cmSystemTools::GetLineFromStream(fin, line))
|
while(cmSystemTools::GetLineFromStream(fin, line))
|
||||||
|
|
|
@ -520,22 +520,10 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout,
|
||||||
configDefine += "\\\"";
|
configDefine += "\\\"";
|
||||||
targetOptions.AddDefine(configDefine);
|
targetOptions.AddDefine(configDefine);
|
||||||
|
|
||||||
// Add a definition for the export macro.
|
// Add the export symbol definition for shared library objects.
|
||||||
if(target.GetType() == cmTarget::SHARED_LIBRARY ||
|
if(const char* exportMacro = target.GetExportMacro())
|
||||||
target.GetType() == cmTarget::MODULE_LIBRARY)
|
|
||||||
{
|
{
|
||||||
std::string exportSymbol;
|
targetOptions.AddDefine(exportMacro);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The intermediate directory name consists of a directory for the
|
// The intermediate directory name consists of a directory for the
|
||||||
|
|
|
@ -243,23 +243,14 @@ void cmMakefileTargetGenerator::WriteTargetLanguageFlags()
|
||||||
{
|
{
|
||||||
const char *lang = l->first.c_str();
|
const char *lang = l->first.c_str();
|
||||||
std::string flags;
|
std::string flags;
|
||||||
// Add the export symbol definition for shared library objects.
|
|
||||||
bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) ||
|
bool shared = ((this->Target->GetType() == cmTarget::SHARED_LIBRARY) ||
|
||||||
(this->Target->GetType() == cmTarget::MODULE_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";
|
flags += "-D";
|
||||||
if(const char* custom_export_name =
|
flags += exportMacro;
|
||||||
this->Target->GetProperty("DEFINE_SYMBOL"))
|
|
||||||
{
|
|
||||||
flags += custom_export_name;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::string in = this->Target->GetName();
|
|
||||||
in += "_EXPORTS";
|
|
||||||
flags += cmSystemTools::MakeCindentifier(in.c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add language-specific flags.
|
// Add language-specific flags.
|
||||||
|
|
|
@ -2157,3 +2157,30 @@ const char* cmTarget::GetOutputDir(bool implib)
|
||||||
|
|
||||||
return out.c_str();
|
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
|
// Compute the OBJECT_FILES property only when requested
|
||||||
void ComputeObjectFiles();
|
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:
|
private:
|
||||||
/**
|
/**
|
||||||
* A list of direct dependencies. Use in conjunction with DependencyMap.
|
* A list of direct dependencies. Use in conjunction with DependencyMap.
|
||||||
|
@ -359,6 +363,7 @@ private:
|
||||||
std::string OutputDirImplib;
|
std::string OutputDirImplib;
|
||||||
std::string Directory;
|
std::string Directory;
|
||||||
std::string Location;
|
std::string Location;
|
||||||
|
std::string ExportMacro;
|
||||||
std::set<cmStdString> Utilities;
|
std::set<cmStdString> Utilities;
|
||||||
bool RecordDependencies;
|
bool RecordDependencies;
|
||||||
cmPropertyMap Properties;
|
cmPropertyMap Properties;
|
||||||
|
|
Loading…
Reference in New Issue