cmExportLibraryDependencies.cxx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 "cmGeneratedFileStream.h"
  17. #include "cmake.h"
  18. #include <memory> // auto_ptr
  19. // cmExecutableCommand
  20. bool cmExportLibraryDependenciesCommand::InitialPass(std::vector<std::string> const& args)
  21. {
  22. // First argument is the name of the test
  23. // Second argument is the name of the executable to run (a target or external
  24. // program)
  25. // Remaining arguments are the arguments to pass to the executable
  26. if(args.size() < 1 )
  27. {
  28. this->SetError("called with incorrect number of arguments");
  29. return false;
  30. }
  31. // store the arguments for the final pass
  32. // also expand any CMake variables
  33. m_Args = args;
  34. return true;
  35. }
  36. void cmExportLibraryDependenciesCommand::FinalPass()
  37. {
  38. // don't do anything if local mode
  39. if(m_Makefile->GetLocal())
  40. {
  41. return;
  42. }
  43. // Create a full path filename for output
  44. std::string fname = m_Args[0];
  45. bool append = false;
  46. if(m_Args.size() > 1)
  47. {
  48. if(m_Args[1] == "APPEND")
  49. {
  50. append = true;
  51. }
  52. }
  53. // Use copy-if-different if not appending.
  54. std::ostream* foutPtr;
  55. std::auto_ptr<cmGeneratedFileStream> foutNew;
  56. if(append)
  57. {
  58. foutPtr = new std::ofstream(fname.c_str(), std::ios::app);
  59. }
  60. else
  61. {
  62. std::auto_ptr<cmGeneratedFileStream> ap(
  63. new cmGeneratedFileStream(fname.c_str(), true));
  64. ap->SetCopyIfDifferent(true);
  65. foutNew = ap;
  66. foutPtr = foutNew.get();
  67. }
  68. std::ostream& fout = *foutPtr;
  69. if (!fout)
  70. {
  71. cmSystemTools::Error("Error Writing ", fname.c_str());
  72. cmSystemTools::ReportLastSystemError("");
  73. return;
  74. }
  75. cmake* cm = m_Makefile->GetCMakeInstance();
  76. cmGlobalGenerator* global = cm->GetGlobalGenerator();
  77. std::vector<cmLocalGenerator *> locals;
  78. global->GetLocalGenerators(locals);
  79. std::string libDepName;
  80. for(std::vector<cmLocalGenerator *>::iterator i = locals.begin();
  81. i != locals.end(); ++i)
  82. {
  83. cmLocalGenerator* gen = *i;
  84. cmTargets &tgts = gen->GetMakefile()->GetTargets();
  85. std::vector<std::string> depends;
  86. const char *defType;
  87. for(cmTargets::const_iterator l = tgts.begin();
  88. l != tgts.end(); ++l)
  89. {
  90. if ((l->second.GetType() != cmTarget::INSTALL_FILES)
  91. && (l->second.GetType() != cmTarget::INSTALL_PROGRAMS))
  92. {
  93. libDepName = l->first;
  94. libDepName += "_LIB_DEPENDS";
  95. const char* def = m_Makefile->GetDefinition(libDepName.c_str());
  96. if(def)
  97. {
  98. fout << "SET(" << libDepName << " \"" << def << "\")\n";
  99. // now for each dependency, check for link type
  100. cmSystemTools::ExpandListArgument(def, depends);
  101. for(std::vector<std::string>::const_iterator d = depends.begin();
  102. d != depends.end(); ++d)
  103. {
  104. libDepName = *d;
  105. libDepName += "_LINK_TYPE";
  106. defType = m_Makefile->GetDefinition(libDepName.c_str());
  107. libDepName = cmSystemTools::EscapeSpaces(libDepName.c_str());
  108. if(defType)
  109. {
  110. fout << "SET(" << libDepName << " \"" << defType << "\")\n";
  111. }
  112. }
  113. }
  114. }
  115. }
  116. }
  117. return;
  118. }