[Cmake-commits] [cmake-commits] king committed cmTargetLinkLibrariesCommand.cxx 1.25 1.26 cmTargetLinkLibrariesCommand.h 1.15 1.16

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Aug 7 17:51:31 EDT 2008


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv12085/Source

Modified Files:
	cmTargetLinkLibrariesCommand.cxx 
	cmTargetLinkLibrariesCommand.h 
Log Message:
ENH: Tolerate repeated link library types

The "debug", "optimized", and "general" link library type specifier
arguments to the target_link_library commands are sometimes repeated in
user code due to variable expansion and other complications.  Instead of
silently accepting the duplicates and trying to link to a bogus library
like "optimized.lib", warn and ignore the earlier specifiers.


Index: cmTargetLinkLibrariesCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTargetLinkLibrariesCommand.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -C 2 -d -r1.15 -r1.16
*** cmTargetLinkLibrariesCommand.h	6 Feb 2008 20:23:36 -0000	1.15
--- cmTargetLinkLibrariesCommand.h	7 Aug 2008 21:51:29 -0000	1.16
***************
*** 80,83 ****
--- 80,85 ----
    cmTypeMacro(cmTargetLinkLibrariesCommand, cmCommand);
  private:
+   void LinkLibraryTypeSpecifierWarning(int left, int right);
+   static const char* LinkLibraryTypeNames[3];
  };
  

Index: cmTargetLinkLibrariesCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmTargetLinkLibrariesCommand.cxx,v
retrieving revision 1.25
retrieving revision 1.26
diff -C 2 -d -r1.25 -r1.26
*** cmTargetLinkLibrariesCommand.cxx	23 Jan 2008 15:27:59 -0000	1.25
--- cmTargetLinkLibrariesCommand.cxx	7 Aug 2008 21:51:29 -0000	1.26
***************
*** 17,20 ****
--- 17,27 ----
  #include "cmTargetLinkLibrariesCommand.h"
  
+ const char* cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[3] =
+ {
+   "general",
+   "debug",
+   "optimized"
+ };
+ 
  // cmTargetLinkLibrariesCommand
  bool cmTargetLinkLibrariesCommand
***************
*** 33,36 ****
--- 40,48 ----
      return true;
      }
+ 
+   // Keep track of link configuration specifiers.
+   cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
+   bool haveLLT = false;
+ 
    // add libraries, nothe that there is an optional prefix 
    // of debug and optimized than can be used
***************
*** 39,81 ****
    for(++i; i != args.end(); ++i)
      {
!     if (*i == "debug")
        {
!       ++i;
!       if(i == args.end())
          {
!         this->SetError
!           ("The \"debug\" argument must be followed by a library");
!         return false;
          }
!       this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
!                                           cmTarget::DEBUG);
        }
!     else if (*i == "optimized")
        {
!       ++i;
!       if(i == args.end())
          {
!         this->SetError(
!           "The \"optimized\" argument must be followed by a library");
!         return false;
          }
!       this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
!                                  cmTarget::OPTIMIZED);
        }
!     else if (*i == "general")
        {
!       ++i;
!       if(i == args.end())
          {
!         this->SetError(
!           "The \"general\" argument must be followed by a library");
!         return false;
          }
!       this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
!                                  cmTarget::GENERAL);
        }
      else
        {
!       // make sure the type is correct if it is currently general.  So if you
        // do a target_link_libraries(foo optimized bar) it will stay optimized
        // and not use the lookup.  As there maybe the case where someone has
--- 51,91 ----
    for(++i; i != args.end(); ++i)
      {
!     if(*i == "debug")
        {
!       if(haveLLT)
          {
!         this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::DEBUG);
          }
!       llt = cmTarget::DEBUG;
!       haveLLT = true;
        }
!     else if(*i == "optimized")
        {
!       if(haveLLT)
          {
!         this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::OPTIMIZED);
          }
!       llt = cmTarget::OPTIMIZED;
!       haveLLT = true;
        }
!     else if(*i == "general")
        {
!       if(haveLLT)
          {
!         this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::GENERAL);
          }
!       llt = cmTarget::GENERAL;
!       haveLLT = true;
!       }
!     else if(haveLLT)
!       {
!       // The link type was specified by the previous argument.
!       haveLLT = false;
!       this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),
!                                               i->c_str(), llt);
        }
      else
        {
!       // Lookup old-style cache entry if type is unspecified.  So if you
        // do a target_link_libraries(foo optimized bar) it will stay optimized
        // and not use the lookup.  As there maybe the case where someone has
***************
*** 83,87 ****
        // only there for backwards compatibility when mixing projects built
        // with old versions of CMake and new)
!       cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
        std::string linkType = args[0];
        linkType += "_LINK_TYPE";
--- 93,97 ----
        // only there for backwards compatibility when mixing projects built
        // with old versions of CMake and new)
!       llt = cmTarget::GENERAL;
        std::string linkType = args[0];
        linkType += "_LINK_TYPE";
***************
*** 102,105 ****
--- 112,139 ----
        }
      } 
+ 
+   // Make sure the last argument was not a library type specifier.
+   if(haveLLT)
+     {
+     cmOStringStream e;
+     e << "The \"" << this->LinkLibraryTypeNames[llt]
+       << "\" argument must be followed by a library.";
+     this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
+     cmSystemTools::SetFatalErrorOccured();
+     }
+ 
    return true;
  }
+ 
+ //----------------------------------------------------------------------------
+ void
+ cmTargetLinkLibrariesCommand
+ ::LinkLibraryTypeSpecifierWarning(int left, int right)
+ {
+   cmOStringStream w;
+   w << "Link library type specifier \""
+     << this->LinkLibraryTypeNames[left] << "\" is followed by specifier \""
+     << this->LinkLibraryTypeNames[right] << "\" instead of a library name.  "
+     << "The first specifier will be ignored.";
+   this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
+ }



More information about the Cmake-commits mailing list