summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2007-03-22 13:45:25 (GMT)
committerBrad King <brad.king@kitware.com>2007-03-22 13:45:25 (GMT)
commit5a32aa5919bd9dab272748c0e0ea12fbcd36436b (patch)
treeb4b0d2c70b896a8c95c91c88112ec2b3bb9d987d /Source
parent187816c9371e49769c02481ea46491b2d7e22d66 (diff)
downloadCMake-5a32aa5919bd9dab272748c0e0ea12fbcd36436b.zip
CMake-5a32aa5919bd9dab272748c0e0ea12fbcd36436b.tar.gz
CMake-5a32aa5919bd9dab272748c0e0ea12fbcd36436b.tar.bz2
ENH: Added target property ENABLE_EXPORTS for executable targets. It enables the executables for linking by loadable modules that import symbols from the executable. This finishes the executable import library support mentioned in bug #4210.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmLocalGenerator.cxx16
-rw-r--r--Source/cmMakefile.cxx7
-rw-r--r--Source/cmMakefileExecutableTargetGenerator.cxx13
-rw-r--r--Source/cmTarget.cxx17
4 files changed, 48 insertions, 5 deletions
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 71d3c51..c7f50f6 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1659,9 +1659,19 @@ void cmLocalGenerator
{
// Compute the proper name to use to link this library.
cmTarget* tgt = this->GlobalGenerator->FindTarget(0, lib.c_str());
- if(tgt && (tgt->GetType() == cmTarget::STATIC_LIBRARY ||
- tgt->GetType() == cmTarget::SHARED_LIBRARY ||
- tgt->GetType() == cmTarget::MODULE_LIBRARY))
+ bool impexe = (tgt &&
+ tgt->GetType() == cmTarget::EXECUTABLE &&
+ tgt->GetPropertyAsBool("ENABLE_EXPORTS"));
+ if(impexe && !implib)
+ {
+ // Skip linking to executables on platforms with no import
+ // libraries.
+ continue;
+ }
+ else if(tgt && (tgt->GetType() == cmTarget::STATIC_LIBRARY ||
+ tgt->GetType() == cmTarget::SHARED_LIBRARY ||
+ tgt->GetType() == cmTarget::MODULE_LIBRARY ||
+ impexe))
{
// This is a CMake target. Ask the target for its real name.
// Pass the full path to the target file but purposely leave
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 78b44a4..e5dc29b 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -944,13 +944,16 @@ void cmMakefile::AddLinkLibraryForTarget(const char *target,
}
// if it is not a static or shared library then you can not link to it
if(!((tgt->GetType() == cmTarget::STATIC_LIBRARY) ||
- (tgt->GetType() == cmTarget::SHARED_LIBRARY)))
+ (tgt->GetType() == cmTarget::SHARED_LIBRARY) ||
+ (tgt->GetType() == cmTarget::EXECUTABLE &&
+ tgt->GetPropertyAsBool("ENABLE_EXPORTS"))))
{
cmOStringStream e;
e << "Attempt to add link target " << lib << " of type: "
<< cmTarget::TargetTypeNames[static_cast<int>(tgt->GetType())]
<< "\nto target " << target
- << ". You can only link to STATIC or SHARED libraries.";
+ << ". One can only link to STATIC or SHARED libraries, or "
+ << "to executables with the ENABLE_EXPORTS property set.";
// in older versions of cmake linking to modules was allowed
if( tgt->GetType() == cmTarget::MODULE_LIBRARY )
{
diff --git a/Source/cmMakefileExecutableTargetGenerator.cxx b/Source/cmMakefileExecutableTargetGenerator.cxx
index 2414458..48aa284 100644
--- a/Source/cmMakefileExecutableTargetGenerator.cxx
+++ b/Source/cmMakefileExecutableTargetGenerator.cxx
@@ -347,6 +347,19 @@ void cmMakefileExecutableTargetGenerator::WriteExecutableRule(bool relink)
std::string linkRule =
this->Makefile->GetRequiredDefinition(linkRuleVar.c_str());
cmSystemTools::ExpandListArgument(linkRule, commands1);
+ if(this->Target->GetPropertyAsBool("ENABLE_EXPORTS"))
+ {
+ // If a separate rule for creating an import library is specified
+ // add it now.
+ std::string implibRuleVar = "CMAKE_";
+ implibRuleVar += linkLanguage;
+ implibRuleVar += "_CREATE_IMPORT_LIBRARY";
+ if(const char* rule =
+ this->Makefile->GetDefinition(implibRuleVar.c_str()))
+ {
+ cmSystemTools::ExpandListArgument(rule, commands1);
+ }
+ }
this->LocalGenerator->CreateCDCommand
(commands1,
this->Makefile->GetStartOutputDirectory(),
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index ef4a07e..441269c 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -259,6 +259,23 @@ void cmTarget::DefineProperties(cmake *cm)
"how the executable will be linked.");
cm->DefineProperty
+ ("ENABLE_EXPORTS", cmProperty::TARGET,
+ "Specify whether an executable exports symbols for loadable modules.",
+ "Normally an executable does not export any symbols because it is "
+ "the final program. It is possible for an executable to export "
+ "symbols to be used by loadable modules. When this property is "
+ "set to true CMake will allow other targets to \"link\" to the "
+ "executable with the TARGET_LINK_LIBRARIES command. "
+ "On all platforms a target-level dependency on the executable is "
+ "created for targets that link to it. "
+ "For non-DLL platforms the link rule is simply ignored since "
+ "the dynamic loader will automatically bind symbols when the "
+ "module is loaded. "
+ "For DLL platforms an import library will be created for the "
+ "exported symbols and then used for linking. "
+ "All Windows-based systems including Cygwin are DLL platforms.");
+
+ cm->DefineProperty
("OBJECT_FILES", cmProperty::TARGET,
"Used to get the resulting list of object files that make up a "
"target.",