cmTargetLinkLibrariesCommand.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  38. cmTarget::DEBUG);
  39. }
  40. else if (*i == "optimized")
  41. {
  42. ++i;
  43. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  44. cmTarget::OPTIMIZED);
  45. }
  46. else
  47. {
  48. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  49. cmTarget::GENERAL);
  50. }
  51. // if this is a library that cmake knows about, and LIBRARY_OUTPUT_PATH
  52. // is not set, then add the link directory
  53. const char* ldir = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  54. if (cmSystemTools::IsOff(ldir))
  55. {
  56. std::string libPath = *i + "_CMAKE_PATH";
  57. const char* dir = m_Makefile->GetDefinition(libPath.c_str());
  58. if( dir && *dir )
  59. {
  60. m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), dir );
  61. }
  62. else
  63. {
  64. m_HasLocation.push_back(*i);
  65. }
  66. }
  67. else
  68. {
  69. m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), ldir );
  70. }
  71. }
  72. return true;
  73. }
  74. void cmTargetLinkLibrariesCommand::FinalPass()
  75. {
  76. std::vector<std::string>::size_type cc;
  77. std::string libPath;
  78. if ( !m_Makefile->GetDefinition("CMAKE_IGNORE_DEPENDENCIES_ORDERING") )
  79. {
  80. for ( cc = 0; cc < m_HasLocation.size(); cc ++ )
  81. {
  82. libPath = m_HasLocation[cc] + "_CMAKE_PATH";
  83. const char* dir = m_Makefile->GetDefinition(libPath.c_str());
  84. if ( dir && *dir )
  85. {
  86. std::string str = "Library " + m_HasLocation[cc] +
  87. " is defined using ADD_LIBRARY after the library is used "
  88. "using TARGET_LINK_LIBRARIES for the target " + m_TargetName +
  89. ". This breaks CMake's dependency "
  90. "handling. Please fix the CMakeLists.txt file.";
  91. this->SetError(str.c_str());
  92. cmSystemTools::Message(str.c_str(), "CMake Error");
  93. }
  94. }
  95. }
  96. }