cmTargetLinkLibrariesCommand.cxx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmTargetLinkLibrariesCommand.h"
  14. const char* cmTargetLinkLibrariesCommand::LinkLibraryTypeNames[3] =
  15. {
  16. "general",
  17. "debug",
  18. "optimized"
  19. };
  20. // cmTargetLinkLibrariesCommand
  21. bool cmTargetLinkLibrariesCommand
  22. ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &)
  23. {
  24. // must have one argument
  25. if(args.size() < 1)
  26. {
  27. this->SetError("called with incorrect number of arguments");
  28. return false;
  29. }
  30. // but we might not have any libs after variable expansion
  31. if(args.size() < 2)
  32. {
  33. return true;
  34. }
  35. // Keep track of link configuration specifiers.
  36. cmTarget::LinkLibraryType llt = cmTarget::GENERAL;
  37. bool haveLLT = false;
  38. // add libraries, nothe that there is an optional prefix
  39. // of debug and optimized than can be used
  40. std::vector<std::string>::const_iterator i = args.begin();
  41. for(++i; i != args.end(); ++i)
  42. {
  43. if(*i == "debug")
  44. {
  45. if(haveLLT)
  46. {
  47. this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::DEBUG);
  48. }
  49. llt = cmTarget::DEBUG;
  50. haveLLT = true;
  51. }
  52. else if(*i == "optimized")
  53. {
  54. if(haveLLT)
  55. {
  56. this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::OPTIMIZED);
  57. }
  58. llt = cmTarget::OPTIMIZED;
  59. haveLLT = true;
  60. }
  61. else if(*i == "general")
  62. {
  63. if(haveLLT)
  64. {
  65. this->LinkLibraryTypeSpecifierWarning(llt, cmTarget::GENERAL);
  66. }
  67. llt = cmTarget::GENERAL;
  68. haveLLT = true;
  69. }
  70. else if(haveLLT)
  71. {
  72. // The link type was specified by the previous argument.
  73. haveLLT = false;
  74. this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),
  75. i->c_str(), llt);
  76. }
  77. else
  78. {
  79. // Lookup old-style cache entry if type is unspecified. So if you
  80. // do a target_link_libraries(foo optimized bar) it will stay optimized
  81. // and not use the lookup. As there maybe the case where someone has
  82. // specifed that a library is both debug and optimized. (this check is
  83. // only there for backwards compatibility when mixing projects built
  84. // with old versions of CMake and new)
  85. llt = cmTarget::GENERAL;
  86. std::string linkType = args[0];
  87. linkType += "_LINK_TYPE";
  88. const char* linkTypeString =
  89. this->Makefile->GetDefinition( linkType.c_str() );
  90. if(linkTypeString)
  91. {
  92. if(strcmp(linkTypeString, "debug") == 0)
  93. {
  94. llt = cmTarget::DEBUG;
  95. }
  96. if(strcmp(linkTypeString, "optimized") == 0)
  97. {
  98. llt = cmTarget::OPTIMIZED;
  99. }
  100. }
  101. this->Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),llt);
  102. }
  103. }
  104. // Make sure the last argument was not a library type specifier.
  105. if(haveLLT)
  106. {
  107. cmOStringStream e;
  108. e << "The \"" << this->LinkLibraryTypeNames[llt]
  109. << "\" argument must be followed by a library.";
  110. this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
  111. cmSystemTools::SetFatalErrorOccured();
  112. }
  113. return true;
  114. }
  115. //----------------------------------------------------------------------------
  116. void
  117. cmTargetLinkLibrariesCommand
  118. ::LinkLibraryTypeSpecifierWarning(int left, int right)
  119. {
  120. cmOStringStream w;
  121. w << "Link library type specifier \""
  122. << this->LinkLibraryTypeNames[left] << "\" is followed by specifier \""
  123. << this->LinkLibraryTypeNames[right] << "\" instead of a library name. "
  124. << "The first specifier will be ignored.";
  125. this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str());
  126. }