cmExportLibraryDependencies.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. std::vector<std::string> depends;
  77. const char *defType;
  78. for(cmTargets::const_iterator l = tgts.begin();
  79. l != tgts.end(); ++l)
  80. {
  81. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  82. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  83. {
  84. libDepName = l->first;
  85. libDepName += "_LIB_DEPENDS";
  86. const char* def = m_Makefile->GetDefinition(libDepName.c_str());
  87. if(def)
  88. {
  89. fout << "SET(" << libDepName << " \"" << def << "\")\n";
  90. // now for each dependency, check for link type
  91. cmSystemTools::ExpandListArgument(def, depends);
  92. for(std::vector<std::string>::const_iterator d = depends.begin();
  93. d != depends.end(); ++d)
  94. {
  95. libDepName = *d;
  96. libDepName += "_LINK_TYPE";
  97. defType = m_Makefile->GetDefinition(libDepName.c_str());
  98. libDepName = cmSystemTools::EscapeSpaces(libDepName.c_str());
  99. if(defType)
  100. {
  101. fout << "SET(" << libDepName << " \"" << defType << "\")\n";
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. fout.close();
  109. return;
  110. }