Преглед на файлове

Merge topic 'tll-IMPORTED-targets'

9cfe4f1 Allow target_link_libraries with IMPORTED targets.
Brad King преди 13 години
родител
ревизия
2341470673
променени са 2 файла, в които са добавени 17 реда и са изтрити 0 реда
  1. 14 0
      Source/cmTargetLinkLibrariesCommand.cxx
  2. 3 0
      Tests/CMakeCommands/target_link_libraries/CMakeLists.txt

+ 14 - 0
Source/cmTargetLinkLibrariesCommand.cxx

@@ -33,6 +33,10 @@ bool cmTargetLinkLibrariesCommand
   this->Target =
     this->Makefile->GetCMakeInstance()
     ->GetGlobalGenerator()->FindTarget(0, args[0].c_str());
+  if(!this->Target)
+    {
+    this->Target = this->Makefile->FindTargetToUse(args[0].c_str());
+    }
   if(!this->Target)
     {
     cmake::MessageType t = cmake::FATAL_ERROR;  // fail by default
@@ -257,6 +261,16 @@ cmTargetLinkLibrariesCommand::HandleLibrary(const char* lib,
   // Handle normal case first.
   if(this->CurrentProcessingState != ProcessingLinkInterface)
     {
+    if (this->Target->IsImported())
+      {
+      cmOStringStream e;
+      e << "Imported targets may only be used with the "
+          "LINK_INTERFACE_LIBRARIES specifier to target_link_libraries.";
+      this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+      return;
+      }
+
+
     this->Makefile
       ->AddLinkLibraryForTarget(this->Target->GetName(), lib, llt);
     if (this->CurrentProcessingState != ProcessingPublicInterface)

+ 3 - 0
Tests/CMakeCommands/target_link_libraries/CMakeLists.txt

@@ -29,6 +29,9 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
 add_library(depA SHARED depA.cpp)
 generate_export_header(depA)
 
+add_library(importedlib UNKNOWN IMPORTED)
+target_link_libraries(importedlib LINK_INTERFACE_LIBRARIES depA)
+
 add_library(depB SHARED depB.cpp)
 generate_export_header(depB)