cmExportLibraryDependencies.cxx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "cmExportLibraryDependencies.h"
  14. #include "cmGlobalGenerator.h"
  15. #include "cmLocalGenerator.h"
  16. #include "cmake.h"
  17. // cmExecutableCommand
  18. bool cmExportLibraryDependenciesCommand::InitialPass(std::vector<std::string> const& args)
  19. {
  20. // First argument is the name of the test
  21. // Second argument is the name of the executable to run (a target or external
  22. // program)
  23. // Remaining arguments are the arguments to pass to the executable
  24. if(args.size() < 1 )
  25. {
  26. this->SetError("called with incorrect number of arguments");
  27. return false;
  28. }
  29. // store the arguments for the final pass
  30. // also expand any CMake variables
  31. m_Args = args;
  32. return true;
  33. }
  34. void cmExportLibraryDependenciesCommand::FinalPass()
  35. {
  36. // don't do anything if local mode
  37. if(m_Makefile->GetLocal())
  38. {
  39. return;
  40. }
  41. // Create a full path filename for output Testfile
  42. std::string fname = m_Args[0];
  43. bool append = false;
  44. if(m_Args.size() > 1)
  45. {
  46. if(m_Args[1] == "APPEND")
  47. {
  48. append = true;
  49. }
  50. }
  51. // Open the output Testfile
  52. std::ofstream fout;
  53. if(append)
  54. {
  55. fout.open(fname.c_str(), std::ios::app);
  56. }
  57. else
  58. {
  59. fout.open(fname.c_str());
  60. }
  61. if (!fout)
  62. {
  63. cmSystemTools::Error("Error Writing ", fname.c_str());
  64. return;
  65. }
  66. cmake* cm = m_Makefile->GetCMakeInstance();
  67. cmGlobalGenerator* global = cm->GetGlobalGenerator();
  68. std::vector<cmLocalGenerator *> locals;
  69. global->GetLocalGenerators(locals);
  70. std::string libDepName;
  71. for(std::vector<cmLocalGenerator *>::iterator i = locals.begin();
  72. i != locals.end(); ++i)
  73. {
  74. cmLocalGenerator* gen = *i;
  75. cmTargets &tgts = gen->GetMakefile()->GetTargets();
  76. for(cmTargets::const_iterator l = tgts.begin();
  77. l != tgts.end(); ++l)
  78. {
  79. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  80. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  81. {
  82. libDepName = l->first;
  83. libDepName += "_LIB_DEPENDS";
  84. const char* def = m_Makefile->GetDefinition(libDepName.c_str());
  85. if(def)
  86. {
  87. fout << "SET(" << libDepName << " \"" << def << "\")\n";
  88. }
  89. }
  90. }
  91. }
  92. fout << ")" << std::endl;
  93. fout.close();
  94. return;
  95. }