cmTargetLinkLibrariesCommand.cxx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 == "debug")
  34. {
  35. ++i;
  36. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  37. cmTarget::DEBUG);
  38. }
  39. else if (*i == "optimized")
  40. {
  41. ++i;
  42. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  43. cmTarget::OPTIMIZED);
  44. }
  45. else
  46. {
  47. m_Makefile->AddLinkLibraryForTarget(args[0].c_str(),i->c_str(),
  48. cmTarget::GENERAL);
  49. }
  50. // if this is a library that cmake knows about, and LIBRARY_OUTPUT_PATH
  51. // is not set, then add the link directory
  52. const char* ldir = m_Makefile->GetDefinition("LIBRARY_OUTPUT_PATH");
  53. if (cmSystemTools::IsOff(ldir))
  54. {
  55. std::string libPath = *i + "_CMAKE_PATH";
  56. const char* dir = m_Makefile->GetDefinition(libPath.c_str());
  57. if( dir )
  58. {
  59. m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), dir );
  60. }
  61. }
  62. else
  63. {
  64. m_Makefile->AddLinkDirectoryForTarget(args[0].c_str(), ldir );
  65. }
  66. }
  67. return true;
  68. }