summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-08-18 15:39:22 (GMT)
committerBrad King <brad.king@kitware.com>2008-08-18 15:39:22 (GMT)
commit061d20be3869d53e0dee4c72b4f9e0202fe6b197 (patch)
treee3b1e82517d89a5795e6d1927e49de21d0294983
parent0bf093fd172951a8da7fc892da95c5c37a3354e2 (diff)
downloadCMake-061d20be3869d53e0dee4c72b4f9e0202fe6b197.zip
CMake-061d20be3869d53e0dee4c72b4f9e0202fe6b197.tar.gz
CMake-061d20be3869d53e0dee4c72b4f9e0202fe6b197.tar.bz2
ENH: Add UNKNOWN type for IMPORTED libraries
When creating an IMPORTED target for a library that has been found on disk, it may not be known whether the library is STATIC or SHARED. However, the library may still be linked using the file found from disk. Use of an IMPORTED target is still important to allow per-configuration files to be specified for the library. This change creates an UNKNOWN type for IMPORTED library targets. The IMPORTED_LOCATION property (and its per-config equivalents) specifies the location of the library. CMake makes no assumptions about the library that cannot be inferred from the file on disk. This will help projects and find-modules import targets found on disk or specified by the user.
-rw-r--r--Source/cmAddLibraryCommand.cxx16
-rw-r--r--Source/cmAddLibraryCommand.h2
-rw-r--r--Source/cmComputeLinkDepends.cxx12
-rw-r--r--Source/cmComputeLinkInformation.cxx13
-rw-r--r--Source/cmLocalGenerator.cxx1
-rw-r--r--Source/cmTarget.cxx20
-rw-r--r--Source/cmTarget.h6
-rw-r--r--Tests/SimpleInstall/CMakeLists.txt6
-rw-r--r--Tests/SimpleInstallS2/CMakeLists.txt6
9 files changed, 70 insertions, 12 deletions
diff --git a/Source/cmAddLibraryCommand.cxx b/Source/cmAddLibraryCommand.cxx
index 575dd04..2bc65ce 100644
--- a/Source/cmAddLibraryCommand.cxx
+++ b/Source/cmAddLibraryCommand.cxx
@@ -68,6 +68,12 @@ bool cmAddLibraryCommand
type = cmTarget::MODULE_LIBRARY;
haveSpecifiedType = true;
}
+ else if(libType == "UNKNOWN")
+ {
+ ++s;
+ type = cmTarget::UNKNOWN_LIBRARY;
+ haveSpecifiedType = true;
+ }
else if(*s == "EXCLUDE_FROM_ALL")
{
++s;
@@ -127,6 +133,16 @@ bool cmAddLibraryCommand
return true;
}
+ // A non-imported target may not have UNKNOWN type.
+ if(type == cmTarget::UNKNOWN_LIBRARY)
+ {
+ this->Makefile->IssueMessage(
+ cmake::FATAL_ERROR,
+ "The UNKNOWN library type may be used only for IMPORTED libraries."
+ );
+ return true;
+ }
+
// Enforce name uniqueness.
{
std::string msg;
diff --git a/Source/cmAddLibraryCommand.h b/Source/cmAddLibraryCommand.h
index ad23ffc..6cad681 100644
--- a/Source/cmAddLibraryCommand.h
+++ b/Source/cmAddLibraryCommand.h
@@ -100,7 +100,7 @@ public:
"\n"
"The add_library command can also create IMPORTED library "
"targets using this signature:\n"
- " add_library(<name> <SHARED|STATIC|MODULE> IMPORTED)\n"
+ " add_library(<name> <SHARED|STATIC|MODULE|UNKNOWN> IMPORTED)\n"
"An IMPORTED library target references a library file located "
"outside the project. "
"No rules are generated to build it. "
diff --git a/Source/cmComputeLinkDepends.cxx b/Source/cmComputeLinkDepends.cxx
index 177ec58..df329a6 100644
--- a/Source/cmComputeLinkDepends.cxx
+++ b/Source/cmComputeLinkDepends.cxx
@@ -891,6 +891,14 @@ void cmComputeLinkDepends::CheckWrongConfigItem(std::string const& item)
}
//----------------------------------------------------------------------------
+static bool cmComputeLinkDependsNotStatic(cmTarget* tgt)
+{
+ return (tgt &&
+ tgt->GetType() != cmTarget::STATIC_LIBRARY &&
+ tgt->GetType() != cmTarget::UNKNOWN_LIBRARY);
+}
+
+//----------------------------------------------------------------------------
void cmComputeLinkDepends::PreserveOriginalEntries()
{
// Skip the part of the input sequence that already appears in the
@@ -901,7 +909,7 @@ void cmComputeLinkDepends::PreserveOriginalEntries()
out != this->FinalLinkOrder.end())
{
cmTarget* tgt = this->EntryList[*in].Target;
- if(tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY)
+ if(cmComputeLinkDependsNotStatic(tgt))
{
// Skip input items known to not be static libraries.
++in;
@@ -924,7 +932,7 @@ void cmComputeLinkDepends::PreserveOriginalEntries()
while(in != this->OriginalEntries.end())
{
cmTarget* tgt = this->EntryList[*in].Target;
- if(tgt && tgt->GetType() != cmTarget::STATIC_LIBRARY)
+ if(cmComputeLinkDependsNotStatic(tgt))
{
// Skip input items known to not be static libraries.
++in;
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx
index 6e0f10b..0b02ae1 100644
--- a/Source/cmComputeLinkInformation.cxx
+++ b/Source/cmComputeLinkInformation.cxx
@@ -581,10 +581,7 @@ void cmComputeLinkInformation::AddItem(std::string const& item, cmTarget* tgt)
return;
}
- if(tgt && (tgt->GetType() == cmTarget::STATIC_LIBRARY ||
- tgt->GetType() == cmTarget::SHARED_LIBRARY ||
- tgt->GetType() == cmTarget::MODULE_LIBRARY ||
- impexe))
+ if(tgt && tgt->IsLinkable())
{
// This is a CMake target. Ask the target for its real name.
if(impexe && this->LoaderFlag)
@@ -1555,6 +1552,14 @@ void
cmComputeLinkInformation::AddLibraryRuntimeInfo(std::string const& fullPath,
cmTarget* target)
{
+ // Libraries with unknown type must be handled using just the file
+ // on disk.
+ if(target->GetType() == cmTarget::UNKNOWN_LIBRARY)
+ {
+ this->AddLibraryRuntimeInfo(fullPath);
+ return;
+ }
+
// Skip targets that are not shared libraries (modules cannot be linked).
if(target->GetType() != cmTarget::SHARED_LIBRARY)
{
diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx
index 064cfb5..4bf1839 100644
--- a/Source/cmLocalGenerator.cxx
+++ b/Source/cmLocalGenerator.cxx
@@ -1706,6 +1706,7 @@ std::string cmLocalGenerator::GetRealDependency(const char* inName,
case cmTarget::STATIC_LIBRARY:
case cmTarget::SHARED_LIBRARY:
case cmTarget::MODULE_LIBRARY:
+ case cmTarget::UNKNOWN_LIBRARY:
{
// Get the location of the target's output file and depend on it.
if(const char* location = target->GetLocation(config))
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index caa534f..296e93d 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -30,7 +30,8 @@
const char* cmTarget::TargetTypeNames[] = {
"EXECUTABLE", "STATIC_LIBRARY",
"SHARED_LIBRARY", "MODULE_LIBRARY", "UTILITY", "GLOBAL_TARGET",
- "INSTALL_FILES", "INSTALL_PROGRAMS", "INSTALL_DIRECTORY"
+ "INSTALL_FILES", "INSTALL_PROGRAMS", "INSTALL_DIRECTORY",
+ "UNKNOWN_LIBRARY"
};
//----------------------------------------------------------------------------
@@ -277,6 +278,7 @@ void cmTarget::DefineProperties(cmake *cm)
"For frameworks on OS X this is the location of the library file "
"symlink just inside the framework folder. "
"For DLLs this is the location of the \".dll\" part of the library. "
+ "For UNKNOWN libraries this is the location of the file to be linked. "
"Ignored for non-imported targets.");
cm->DefineProperty
@@ -787,6 +789,16 @@ bool cmTarget::IsExecutableWithExports()
}
//----------------------------------------------------------------------------
+bool cmTarget::IsLinkable()
+{
+ return (this->GetType() == cmTarget::STATIC_LIBRARY ||
+ this->GetType() == cmTarget::SHARED_LIBRARY ||
+ this->GetType() == cmTarget::MODULE_LIBRARY ||
+ this->GetType() == cmTarget::UNKNOWN_LIBRARY ||
+ this->IsExecutableWithExports());
+}
+
+//----------------------------------------------------------------------------
bool cmTarget::IsFrameworkOnApple()
{
return (this->GetType() == cmTarget::SHARED_LIBRARY &&
@@ -1860,7 +1872,8 @@ const char *cmTarget::GetProperty(const char* prop,
if(this->GetType() == cmTarget::EXECUTABLE ||
this->GetType() == cmTarget::STATIC_LIBRARY ||
this->GetType() == cmTarget::SHARED_LIBRARY ||
- this->GetType() == cmTarget::MODULE_LIBRARY)
+ this->GetType() == cmTarget::MODULE_LIBRARY ||
+ this->GetType() == cmTarget::UNKNOWN_LIBRARY)
{
if(!this->IsImported() && strcmp(prop,"LOCATION") == 0)
{
@@ -1957,6 +1970,9 @@ const char *cmTarget::GetProperty(const char* prop,
case cmTarget::INSTALL_DIRECTORY:
return "INSTALL_DIRECTORY";
// break; /* unreachable */
+ case cmTarget::UNKNOWN_LIBRARY:
+ return "UNKNOWN_LIBRARY";
+ // break; /* unreachable */
}
return 0;
}
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index 7141e41..07004be 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -80,7 +80,8 @@ public:
cmTarget();
enum TargetType { EXECUTABLE, STATIC_LIBRARY,
SHARED_LIBRARY, MODULE_LIBRARY, UTILITY, GLOBAL_TARGET,
- INSTALL_FILES, INSTALL_PROGRAMS, INSTALL_DIRECTORY};
+ INSTALL_FILES, INSTALL_PROGRAMS, INSTALL_DIRECTORY,
+ UNKNOWN_LIBRARY};
static const char* TargetTypeNames[];
enum CustomCommandType { PRE_BUILD, PRE_LINK, POST_BUILD };
@@ -393,6 +394,9 @@ public:
enabled. */
bool IsExecutableWithExports();
+ /** Return whether this target may be used to link another target. */
+ bool IsLinkable();
+
/** Return whether this target is a shared library Framework on
Apple. */
bool IsFrameworkOnApple();
diff --git a/Tests/SimpleInstall/CMakeLists.txt b/Tests/SimpleInstall/CMakeLists.txt
index 34914b6..c204e64 100644
--- a/Tests/SimpleInstall/CMakeLists.txt
+++ b/Tests/SimpleInstall/CMakeLists.txt
@@ -66,9 +66,13 @@ IF(STAGE2)
PATHS ${LIBPATHS}
DOC "Fourth library")
+ # Test importing a library found on disk.
+ ADD_LIBRARY(lib_test4 UNKNOWN IMPORTED)
+ SET_PROPERTY(TARGET lib_test4 PROPERTY IMPORTED_LOCATION ${TEST4_LIBRARY})
+
INCLUDE_DIRECTORIES(${CMAKE_INSTALL_PREFIX}/MyTest/include)
ADD_EXECUTABLE (SimpleInstExeS2 inst2.cxx foo.c foo.h)
- TARGET_LINK_LIBRARIES(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} ${TEST4_LIBRARY})
+ TARGET_LINK_LIBRARIES(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} lib_test4)
SET(install_target SimpleInstExeS2)
IF("${TEST1_LIBRARY}" MATCHES "static")
diff --git a/Tests/SimpleInstallS2/CMakeLists.txt b/Tests/SimpleInstallS2/CMakeLists.txt
index 34914b6..c204e64 100644
--- a/Tests/SimpleInstallS2/CMakeLists.txt
+++ b/Tests/SimpleInstallS2/CMakeLists.txt
@@ -66,9 +66,13 @@ IF(STAGE2)
PATHS ${LIBPATHS}
DOC "Fourth library")
+ # Test importing a library found on disk.
+ ADD_LIBRARY(lib_test4 UNKNOWN IMPORTED)
+ SET_PROPERTY(TARGET lib_test4 PROPERTY IMPORTED_LOCATION ${TEST4_LIBRARY})
+
INCLUDE_DIRECTORIES(${CMAKE_INSTALL_PREFIX}/MyTest/include)
ADD_EXECUTABLE (SimpleInstExeS2 inst2.cxx foo.c foo.h)
- TARGET_LINK_LIBRARIES(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} ${TEST4_LIBRARY})
+ TARGET_LINK_LIBRARIES(SimpleInstExeS2 ${TEST1_LIBRARY} ${TEST2_LIBRARY} lib_test4)
SET(install_target SimpleInstExeS2)
IF("${TEST1_LIBRARY}" MATCHES "static")