cmTargetLinkLibrariesCommand.cxx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // cmTargetLinkLibrariesCommand
  15. bool cmTargetLinkLibrariesCommand::InitialPass(std::vector<std::string> const& args)
  16. {
  17. // must have one argument
  18. if(args.size() < 1)
  19. {
  20. this->SetError("called with incorrect number of arguments");
  21. return false;
  22. }
  23. m_TargetName = args[0];
  24. // but we might not have any libs after variable expansion
  25. if(args.size() < 2)
  26. {
  27. return true;
  28. }
  29. // add libraries, nothe that there is an optional prefix
  30. // of debug and optimized than can be used
  31. std::vector<std::string>::const_iterator i = args.begin();
  32. for(++i; i != args.end(); ++i)
  33. {
  34. if (*i == "debug")
  35. {
  36. ++i;
  37. if(i == args.end())
  38. {
  39. this->SetError("The \"debug\" argument must be followed by a library");
  40. return false;
  41. }
  42. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  43. cmTarget::DEBUG);
  44. }
  45. else if (*i == "optimized")
  46. {
  47. ++i;
  48. if(i == args.end())
  49. {
  50. this->SetError("The \"optimized\" argument must be followed by a library");
  51. return false;
  52. }
  53. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  54. cmTarget::OPTIMIZED);
  55. }
  56. else
  57. {
  58. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  59. cmTarget::GENERAL);
  60. }
  61. // if this is a library that cmake knows about, and LIBRARY_OUTPUT_PATH
  62. // is not set, then add the link directory
  63. const char* ldir = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  64. if (cmSystemTools::IsOff(ldir))
  65. {
  66. std::string libPath = *i + "_CMAKE_PATH";
  67. const char* dir = m_Makefile->GetDefinition(libPath.c_str());
  68. if( dir && *dir )
  69. {
  70. m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), dir );
  71. }
  72. else
  73. {
  74. m_HasLocation.push_back(*i);
  75. }
  76. }
  77. else
  78. {
  79. m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), ldir );
  80. }
  81. }
  82. return true;
  83. }
  84. void cmTargetLinkLibrariesCommand::FinalPass()
  85. {
  86. std::vector<std::string>::size_type cc;
  87. std::string libPath;
  88. if ( !m_Makefile->GetDefinition("CMAKE_IGNORE_DEPENDENCIES_ORDERING") )
  89. {
  90. for ( cc = 0; cc < m_HasLocation.size(); cc ++ )
  91. {
  92. libPath = m_HasLocation[cc] + "_CMAKE_PATH";
  93. const char* dir = m_Makefile->GetDefinition(libPath.c_str());
  94. if ( dir && *dir )
  95. {
  96. std::string str = "Library " + m_HasLocation[cc] +
  97. " is defined using ADD_LIBRARY after the library is used "
  98. "using TARGET_LINK_LIBRARIES for the target " + m_TargetName +
  99. ". This breaks CMake's dependency "
  100. "handling. Please fix the CMakeLists.txt file.";
  101. this->SetError(str.c_str());
  102. cmSystemTools::Message(str.c_str(), "CMake Error");
  103. }
  104. }
  105. }
  106. }