cmFindLibraryCommand.cxx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2000 National Library of Medicine
  8. All rights reserved.
  9. See COPYRIGHT.txt for copyright details.
  10. =========================================================================*/
  11. #include "cmFindLibraryCommand.h"
  12. #include "cmCacheManager.h"
  13. // cmFindLibraryCommand
  14. bool cmFindLibraryCommand::Invoke(std::vector<std::string>& args)
  15. {
  16. if(args.size() < 2 )
  17. {
  18. this->SetError("called with incorrect number of arguments");
  19. return false;
  20. }
  21. // Now check and see if the value has been stored in the cache
  22. // already, if so use that value and don't look for the program
  23. const char* cacheValue
  24. = cmCacheManager::GetInstance()->GetCacheValue(args[0].c_str());
  25. if(cacheValue)
  26. {
  27. m_Makefile->AddDefinition(args[0].c_str(), cacheValue);
  28. return true;
  29. }
  30. std::vector<std::string> path;
  31. // add any user specified paths
  32. for (unsigned int j = 2; j < args.size(); j++)
  33. {
  34. // expand variables
  35. std::string exp = args[j];
  36. m_Makefile->ExpandVariablesInString(exp);
  37. path.push_back(exp);
  38. }
  39. // add the standard path
  40. cmSystemTools::GetPath(path);
  41. for(unsigned int k=0; k < path.size(); k++)
  42. {
  43. std::string tryPath = path[k];
  44. tryPath += "/";
  45. tryPath += args[1];
  46. if(cmSystemTools::FileExists(tryPath.c_str()))
  47. {
  48. m_Makefile->AddDefinition(args[0].c_str(), path[k].c_str());
  49. cmCacheManager::GetInstance()->AddCacheEntry(args[0].c_str(),
  50. path[k].c_str(),
  51. cmCacheManager::PATH);
  52. return true;
  53. }
  54. }
  55. return false;
  56. }