cmTargetLinkLibrariesCommand.cxx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // but we might not have any libs after variable expansion
  24. if(args.size() < 2)
  25. {
  26. return true;
  27. }
  28. // add libraries, nothe that there is an optional prefix
  29. // of debug and optimized than can be used
  30. std::vector<std::string>::const_iterator i = args.begin();
  31. for(++i; i != args.end(); ++i)
  32. {
  33. if ( *i == "NOTFOUND" )
  34. {
  35. this->SetError("CMake attempted to put library that was not found to the list of libraries.");
  36. return false;
  37. }
  38. if (*i == "debug")
  39. {
  40. ++i;
  41. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  42. cmTarget::DEBUG);
  43. }
  44. else if (*i == "optimized")
  45. {
  46. ++i;
  47. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  48. cmTarget::OPTIMIZED);
  49. }
  50. else
  51. {
  52. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  53. cmTarget::GENERAL);
  54. }
  55. // if this is a library that cmake knows about, and LIBRARY_OUTPUT_PATH
  56. // is not set, then add the link directory
  57. const char* ldir = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  58. if (cmSystemTools::IsOff(ldir))
  59. {
  60. std::string libPath = *i + "_CMAKE_PATH";
  61. const char* dir = m_Makefile->GetDefinition(libPath.c_str());
  62. if( dir )
  63. {
  64. m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), dir );
  65. }
  66. }
  67. else
  68. {
  69. m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), ldir );
  70. }
  71. }
  72. return true;
  73. }